Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help!!! Computer Lab: Number Systems Construct an object-oriented Java program that performs each of the foll conversions. Note that we're only dealing with non-negative number

help!!! image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Computer Lab: Number Systems Construct an object-oriented Java program that performs each of the foll conversions. Note that we're only dealing with non-negative number of the following Converts a decimal integer into a 32-bit binary number Converts a decimal integer into an 8-digit hexadecimal number . Converts a 32-bit binary number into a decimal integer . Converts a 32-bit binary number into an 8-digit hexadecimal number . Converts an 8-digit hexadecimal number into a decimal integer Converts an 8-digit hexadecimal number into a 32-bit binary number Your program should be interactive, requiring the user to select the appropriate option from a menu of options (no GUI required). Note that Java's Scanner class will be very helpful reading data from the keyboard. The conversions you code must be direct. In other words, if you had to convert a base 2 number into base 16, the conversion should be made directly from base 2 to base 16 and not from base 2 to base 10 to base 16. You may not use any methods or utilities from the Java library that do the conversions for you, such as: Integer.toBinaryString() Integer.toHexString() Your program should send all output to a file called csis.txt. This output file will be submitted along with your source code for the lab. All information displayed in the terminal window, including input from the user, should also be sent to the output file. Focus on Data Structures rovided for each of the test data nd spaces while inputting the une to tum in output in the order to Note that you can omit commas and Spa shown below. Note that v data into the program. 1. Decimal to Binary: a) 65, 535 b) 1,000,000 c) 1,234,567, 890 2. Decimal to Hexadecimal: a) 65,535 b) 1,000,000 c) 1,234,567,890 3. Binary to Decimal: a) 0110 0101 11 b) 0111 1111 111 0101 1100 1101 1010 1110 0000 0101 1111 1111 1111 0010 0001 1101 0011 900 0000 0000 0000 0000 0000 0000 0010 4. Binary to Hexadecimal: 0110 0101 1100 1101 1010 1110 0000 0101 0111 1111 1111 1111 0010 0001 1101 0011 J 0010 1011 1010 1101 0111 0110 0011 1010 5. Hexadecimal to Decimal: a) 12345678 b) 2A3DF8A7 c) O0FF00FF 6. Hexadecimal to Binary: a) 12345678 b) 2A3DF8A7 c) 00FF00FF For extra credit, perform error checking on the user input displaying app error messages if the user enters invalid data such as a valu conversion or inappropriate digits for the selected base. Adda to show that your extra credit works prop deal with this invalid data in a robust manner witho valid data such as a value out of range for a s for the selected base. Add additional test data ur extra credit works properly. Your program should be able to a robust manner without crashing! Page 44 1: A Few Comments: in its own source file. * Number Systems Lab Note 1: A Few Com Each class should be contained within its own file, csis.txt, directly from tout to the file. ctly from your Program output should be captured to a file, csi am rather than cutting and pasting the output to the u should be sent to the s, as well as any input All program output gram output displayed in the terminal window she file. This includes the displayed menu, user prompts, as the user. your methods small, usually performing a single task. luding a main() methon Your program should be a complete application including a the classes that maken Keep main() small placing details in the methods of the class your object-oriented program. There should be no user-defined static methods in your program main(). your program other than Do not use floats, doubles or scientific notation in your code. Binary numbers should be output as 32 bits (i.e., display leading zeros) with a space separating nibbles as shown in the input data above. You may build a GUI for the application although it is not required. 1: A Few Comments: in its own source file. * Number Systems Lab Note 1: A Few Com Each class should be contained within its own file, csis.txt, directly from tout to the file. ctly from your Program output should be captured to a file, csi am rather than cutting and pasting the output to the u should be sent to the s, as well as any input All program output gram output displayed in the terminal window she file. This includes the displayed menu, user prompts, as the user. your methods small, usually performing a single task. luding a main() methon Your program should be a complete application including a the classes that maken Keep main() small placing details in the methods of the class your object-oriented program. There should be no user-defined static methods in your program main(). your program other than Do not use floats, doubles or scientific notation in your code. Binary numbers should be output as 32 bits (i.e., display leading zeros) with a space separating nibbles as shown in the input data above. You may build a GUI for the application although it is not required. stems Lab Note 2: Classes and Methode uld include at least the following classes * Number Systems Lab Ne Your program should include river, Menu, Decimal, Binary, Hexadecimal et to perform the conversions, parate methods to get input, to perform the con outout. Shown below are methods for each of natures shown indented represent hat I recommend. The method signatures shown inden within the unindented methods. You can certainly add Each class must use separate metho and to generate the appropriate outouts the classes that I recomme methods being called from within the more methods than what is shown. Decimal Class public void deeToBin() private void input Dec() private void toBin() private void outBin() Binary class public void binToDec() private void input Bin() private void toDec() private void out Dec() public void decToHex() private void input Deco private void toHex() private void out Hex () public void binTo Hex () private void inputBin() private void toHex() private void out Hex() Menu Class public void display) public int get Selection () Hexadecimal Class public void hexToDec () private void input Hex() private void toDec () private void out Dec () public void hexToBin() private void input Hex () private void toBin() private void outBin() Note that the Menu class will contain a method to display a me to prompt the user for a menu selection and receive the input Think Scanner class to capture the input from the key method to display a menu and a method on and receive the input from the user. Page 48 tems lab. require that e code below are all Number Systems Lab Note 3: Driver Class Here's a look at my Driver class for the number syste use this driver class for your lab. No changes to the IOException id main(String[] args) throws IOEX import java.io. public class Driver public static void main(String) are int choices lewriter ( sis.tx Printwriter pw = new Printwriter (new File Decimal dec = new Decimal (pw); Binary bin - new Binary (pw); Hexadecimal hex - new Hexadecimal (pw); Menu menu - new Menu (pw); do menu.display(); choice - menu.getSelection (): switch (choice) case 1 : dec.decToBin(); break; case 2 : dec. decToHex(); break; case 3: bin.binToDec(); break; case 4 bin.bin Tolex(); break; case 5 : hex.hexToDec(); break; case 6 : hex.hexTobin(); break; } while (choice !- 7); pw.close(); That's it! Note that there are no conversions being performed in the Driver class (or in the Menu class). The conversions are performed within the Decinal Binary and Hexadecimal classes. Note that I'm using one-arg constructors to instantiate obiects for each of the Decimal, Binary, Hexadecimal and Menu classes. The argument that yo passed to each of these constructors is a Printwriter object. of the classes to have access to the Print Writer object create allows you generate output to the csis.txt output file from eac The problem that arises is this. An object that is passed as a p constructor is only visible within the scope of the constructor. the other methods in each class access the Printwriter o riter object. This allows each object created in the driver. put file from each of the classes Focus on Data Structures sed as a parameter to a structor. Therefore, how can Writer object as well? neach class and, within the din as a parameter to the solution is to declare a class variable in each an the Print Writer object passed in as a class variable is assigned the value of th the class will have access to the constructor, assign the Print class variable. Once the class vs Print Writer obiect Printwriter object. Writer object, each of the methods in the eclare a class variable in each of the classes: So we declare a class variable private PrintWriter pw; need to assign its argument to the class Each of the constructors will then need to assign its argument variable. For example: public Decimal(PrintWriter pw) this.pw = pw; We use this here to distinguish the argument name with the class variable name. If you didn't want to use this, you would have to use an argument with a different name than the class variable: public Decimal(PrintWriter p) { pw = p; + Number Systems Lab Note 4: Print Writer Class Shown below is the use of Java's Print Writer and File open an output file and send output to the output file. TeWriter classes to Required declarations: import java.io.*; public static void main(String[] args) throws IOException To open a file for output: Print Writer pW - new Print Writer (new Filewriter("csis.txt"), To send output to the file: pw.print("Sends to output file."); pw.println("Sends to output file with linefeed."); To close the output file: pw.close(); ary to Hexadecimal Conversion thm that maps one value to sion algorithm used by the other base nversion is more of an algorithm that Number Systems Lab Notes 5: Binary The binary to hex conversion is other rather than a mathematical conversion number (don't input spaces) into a str conversions obiect, hex, perhaps ou must create a stringBuilder object all hold the resulting hex conversion value First, you must read the 32-bit binary nun object, bin. Then you must cres Initialized to "00000000", which will be The reason you need to use value rather than a s biect to hold the resulting hex value of a String object is need to use a stringBuilder object to ho her than a string object is because the value ce created. The value of a eation. Otherwise String and immutable and cannot be changed once create obiect can be modified after creation. Otherwise ilder objects are pretty much the same. StringBuilder object ca StringBuilder objects the String object, looking at 4-bits at a time. look at 4-bits and will return the Next you must iterate through bin, the strin The substring function will allow you to look at 4-bits a resulting 4-bits as a String: bin.substring(1, 1+4) The String that the substring function returns can then be compared against a string constant holding a 4-bit value: if (bin.substring(i, i + 4).equals("0000")) If the comparison returns true, then you can set the appropriate position in the String object, hex, to the appropriate hex digit: if (bin.substring(i, i + 4).equals("0000")) hex.setCharAt(), '0'); else if (bin.substring(i, i + 4).equals("0001")) hex.setCharAt(), '1'); All of this will take place within a for loop that init increments i by 4 and j by 1. or loop that initializes i and to 0 and Page 50 und in this link on Number Systems Lab Note 6: Program Documentatie da document on the use of Javadoc that can be found Canvas: I've provided a document on th les Java Review | Javadoc Program Documentatie In particular, note the following guidelines: . Every class must have a Javadoc class comment. Every method must have a Javadoc method comment Every method parameter must have an @param tag. Every method with a return statement must have an @return tan . Generate the HTML Javadoc documentation for your project and he submit the folder that contains the Javadoc documentation in the when submitting the lab. piect and be sure to tation in the zip archive * Number Systems Lab Note 7: Class Diagram Shown below is the class diagram for my solution to the number systems lab. Driver Menu Decimal Binary Hexadecimal Focus on Data Structures

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions