CISS-110 Project 6
For this project you will continue to work with files. The file format will be a series of numbers that could be binary, octal, decimal or hexadecimal.
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 perform the identification of 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 returns 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 certain patterns in strings. This will be discussed during lecture.
The following patterns are provided for identification:
Binary -> [01]+ Octal -> [0-7]+ Decimal -> [0-9]+ Hexadecimal -> [0-9a-fA-F]+
Using the following data for your input file:
210 134 998 a34 A0 87 2398 10010 101 10 DeAd beEF
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.