CSC1020 Homework 1

Overview

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 (see below). 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

3-bit ANSI

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, tab, quotation marks, and so on. Placed in a String argument for a print(), printf(), or 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.

Color 3-bit ANSI Escape Codes
Reset \u001B[0m
Black \u001B[30m
Red \u001B[31m
Green \u001B[32m
Yellow \u001B[33m
Blue \u001B[34m
Magenta \u001B[35m
Cyan \u001B[36m
White \u001B[37m

Color Enumeration

The 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.

Color Driver

Your driver will contain three methods:

Sample Output

Below is output from a sample run of the program. Your output should match this as closely as possible.

Sample Output

UML

UML