Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

CISS-110 Project 6b

Posted on October 16, 2019January 20, 2025 By William Jojo
CISS-110-Project
CISS-110 Project 6

For this project, you will continue working with files. The file format will be a series of numbers, which could be binary, octal, decimal, or hexadecimal. Some numbers will fall into multiple categories. For example, 306 can fall into three possible classifications.


Learning outcomes

  • Implementing user-defined methods.
  • Working with regular expressions.
  • Working with files.
  • Using Scanner with files.
  • More work with Integer.parseInt().
  • Confirmation program produces desired results.

Create methods to identify numbers. Perhaps each method could be an “is” method like isBinary, isOctal, isDecimal, isHexadecimal. Each of these will take a value of type String and return a boolean. Remember that each number can qualify for multiple classifications.

In addition to the four methods noted above, create one more method called baseConvert, which is responsible for taking the number as a String along with the radix of the number and printing its base and value.

Using a new matches() method from the String class, you will be able to identify specific patterns in strings. This will be discussed during the lecture.

The following patterns are provided for identification:

Binary      ->   [01]+
Octal       ->   [0-7]+
Decimal     ->   [0-9]+
Hexadecimal ->   [0-9a-fA-F]+

Use the following data for your input file:

210 134
998 a34
A0 87
2398 10010 101
10
DeAd beEF

The example output provided shows the first sentence provided by main() and the second sentence by baseConvert(). Your program will produce the following output to the screen:

210 is a valid octal number. 210 base 8 is 136 base 10.
210 is a valid decimal number. 210 base 10 is 210 base 10.
210 is a valid hexadecimal number. 210 base 16 is 528 base 10.

134 is a valid octal number. 134 base 8 is 92 base 10.
134 is a valid decimal number. 134 base 10 is 134 base 10.
134 is a valid hexadecimal number. 134 base 16 is 308 base 10.

998 is a valid decimal number. 998 base 10 is 998 base 10.
998 is a valid hexadecimal number. 998 base 16 is 2456 base 10.

a34 is a valid hexadecimal number. a34 base 16 is 2612 base 10.

A0 is a valid hexadecimal number. A0 base 16 is 160 base 10.

87 is a valid decimal number. 87 base 10 is 87 base 10.
87 is a valid hexadecimal number. 87 base 16 is 135 base 10.

2398 is a valid decimal number. 2398 base 10 is 2398 base 10.
2398 is a valid hexadecimal number. 2398 base 16 is 9112 base 10.

10010 is a valid binary number. 10010 base 2 is 18 base 10.
10010 is a valid octal number. 10010 base 8 is 4104 base 10.
10010 is a valid decimal number. 10010 base 10 is 10010 base 10.
10010 is a valid hexadecimal number. 10010 base 16 is 65552 base 10.

101 is a valid binary number. 101 base 2 is 5 base 10.
101 is a valid octal number. 101 base 8 is 65 base 10.
101 is a valid decimal number. 101 base 10 is 101 base 10.
101 is a valid hexadecimal number. 101 base 16 is 257 base 10.

10 is a valid binary number. 10 base 2 is 2 base 10.
10 is a valid octal number. 10 base 8 is 8 base 10.
10 is a valid decimal number. 10 base 10 is 10 base 10.
10 is a valid hexadecimal number. 10 base 16 is 16 base 10.

DeAd is a valid hexadecimal number. DeAd base 16 is 57005 base 10.

beEF is a valid hexadecimal number. beEF base 16 is 48879 base 10.

Submit the project to the Learning Management System as Project6_lastname.java.

Post navigation

❮ Previous Post: CISS-110 Project 6a
Next Post: CISS-110 Project 8b – JavaFX ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.