CSC1110 Homework 10
Complete the following program
We are going to write a program that will display decimal integer values as both hexadecimal and binary representations and will highlight the different representations with different colors. To do so, we will first create a
Color Enumeration that will store all 9 “colors” and values of 3-bit ANSI. We will then write a small driver class that will explain the purpose of the class to the user, then ask them for a decimal value. It will validate the user input and, if valid, will display the value in all three representations (hexadecimal, binary, and decimal) in the appropriate colors. The program will continue to ask the user for input until they enter
“q”, which will quit the program, with an appropriate message.
Early computers (until the mid 1980s) only had text output, which as we all know is quite boring. In an attempt to spice things up, the ANSI escape codes were created to allow terminals to display text in various colors in the foreground and background. ANSI escape codes work just like regular escape codes that we are familiar with, such as newline(\n), tab(\t), quotation mark(\"), and so on. Placed in a String argument for a
println() method, it will change the color of the terminal output. This color change will persist until another color change is made. To return to the default color of your terminal, there is an ANSI RESET escape code that reset the color.
3-bit ANSI Escape Codes
Color enumeration will contain
String representations of the various ANSI colors (RESET, BLACK, RED, etc). Each color will have a single
String instance variable,
ansi, that will contain the ANSI escape code for that color. You will have to write a constructor to accomplish this. Additionally, a
toString() method that returns the value stored in ansi will prove helpful.
Your driver will contain three methods:
validate()method, which accepts as a parameter a
Stringcontaining the input from the user, and will validate the
String,ensuring the input is an integer
display()method that will have as a parameter the decimal int value to be displayed, and will display the hexadecimal, binary, and decimal representations of the value in the appropriate colors.
Commit and Push your files to GitHub Classroom.