you will be creating a driver class only for this assignment, however, you need
ID: 3700201 • Letter: Y
Question
you will be creating a driver class only for this assignment, however, you need to submit the driver class and both the input and output files.
Be sure to include a message to the user explaining the purpose of the program before any other printing to the screen.
Within the main method, please complete the following tasks:
Use a loop to create a file named “input.txt” that contains 10 randomly generated numbers between 0 and 99, one per line. Be sure to close the file when done and print a message to the screen indicating the input file has been created.
Create an output file named “output.txt”. Create a header row similar to the following in the file:
Number 1x 2x 3x 4x 5x 6x 7x 8x 9x 10x
Using a second loop, read in the numbers from the input file one at a time (use the hasNext() method). After reading in each number, calculate and write/print the first 10 multiples of the value read in separated by a tab to the output file.
Close file output file when all the values in the input file have been processed.
Print a message to the user indicating that the output files has been created.
Include clear comments throughout the program that explain the well named variables and what functionality the various lines/small sections of code are completing as related to the execution of the program.
Explanation / Answer
package engine;
import java.util.*;
import java.io.*;
public class DriverFile{
public static void main(String [] args)throws IOException
{
PrintWriter out = new PrintWriter(new File("testing.txt"));
Random rand = new Random();
int number, count=0, countTwo=0;
while(count!=100)
{
while(countTwo<=1)
{
number=rand.nextInt(100)+1;
out.print(number);
count++;
countTwo++;
}
out.println();
}
out.close();
}
}
package engine;
import java.util.*;
import java.io.*;
public class DriverFile{
public static void main(String [] args)throws IOException
{
PrintWriter out = new PrintWriter(new File("testing.txt"));
Random rand = new Random();
int number, count=0, countTwo=0;
while(count!=100)
{
while(countTwo<=1)
{
number=rand.nextInt(100)+1;
out.print(number);
count++;
countTwo++;
}
out.println();
}
out.close();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.