Question: I have started writing the program (I pasted it below the instructions) but I have no idea where to go from there. Within DrJava, you

I have started writing the program (I pasted it below the instructions) but I have no idea where to go from there.

Within DrJava, you are to create one class which is described below:

You are to download the file entitled decimal.txt that is associated with this assignment. This file contains eight decimal numbers (one per line) that you will need for this assignment.

DecimalToBinary class will have one class variable that is of type String. Call it output.

You are to have and use the following variables in your program:

Integers: decimalNumber, base, count, and i.

Array of String: convertArray that will be set to be of size 10.

Using a try and catch clause, you are to read one number at a time from the decimal.txt file and convert it to its binary equivalent. The base will always be the value 2. You are to invoke the method decToBin(described below) to do the conversion. The final result of the conversion of each number (i.e. the binary equivalent) will be inserted to an element of the array convertArray. You are to show each converted decimal number to its equivalent via the JOptionPane. Upon converting all the decimal numbers to their binary equivalent, you are to close the file (i.e. decimal.txt). Dr. Castaeda 2

Then, using another try and catch clause, you are to write to a file called conversion.txt all the elements of the array convertArray. Do this writing with one element per line to the file.

Display the message This program was written by ______ and End of program. via a JOptionPane.

Note: In the above statement make sure that you replace my name with your name.

The method decToBin will be declared with the method header as follows:

public static void decToBin(int num, int base)

The base case in this method will be when the value of num becomes zero. Once this occurs, you are to print (to the console) the message Reached base case. Then you are to execute a return, but do not return any value since this method has void in its header.

Otherwise, you are to recursively invoke decToBin with the two appropriate arguments. (These two arguments are what you must determine). You will then concatenate the remainder of the current value ofnum and base via the Modula operator. Then print out (to the console) the message Current answer: concatenated with the current value of output. Thus, you will be able to see your answer grow towards the correct answer.

Dont forget to import any classes that you may need for this program.

decimal.txt file:

25 16 2 37 101 4 7 175

Unfinished program:

import java.util.Scanner; import javax.swing.JOptionPane; // Create class DecimalToBinary public class DecimalToBinary { private String output; public static void main(String[] args) { // Define variables to be used in program private int decimalNumber, base, count, i; // Initialize an array of string to be of size 10 private String[] convertArray = new String[10]; // Create a try/catch block try(Scanner input = new Scanner(Paths.get("decimal.txt"))) { } catch { } if(output != null) { output.close(); } JOptionPane.showMessageDialog(null, "This program was written by Dakota Davila"); JOptionPane.showMessageDialog(null, "End of program."); public static void decToBin(int num, int base) { } } // End main method } // End class DecimalToBinary

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!