Question: Programming Assignment #7 SalesReadWrite The program this week will Open and Read a file that contains a list of sales data, basically a list of

Programming Assignment #7 SalesReadWrite

The program this week will Open and Read a file that contains a list of sales data, basically a list of numbers. There is one number on each line in the file. I attached the file containing the data to be read by your program in sales.txt. First you will prompt the user for the file name to open and read. Then your program will open the file and read the data from the file. As the data is being read from the file, you will keep track of how many sales numbers are in the file, determine the largest sales figure, and determine the smallest sales figure. After reading all the numbers you will write the results to a different file (SalesRpt.txt) and output to terminal stating program is done.

Steps:

Create a new BlueJ Project called: SalesReadProject

Copy the sales.txt file from Blackboard into the SalesReadProject Folder.

Create a new Class called SalesReadWrite. This is your main() driver program.

The SalesReadWrite main() will do the following:

NOTE: before writing main() method, make sure it looks like this. No need to understand the throws IOException for this class. We need this when working with Files.:

public static void main(String[] args) throws IOException

Prompt the user using Scanner to Enter name of sales file to read: .

Read the name of the file entered on keyboard by user.

Open the file (name provided from keyboard, you saved in filename variable) to READ from it using File and Scanner.

In a loop (what type of loop will you choose), read all the numbers from the file while calculating:

the smallest sale in the entire file. What data type will you use?

the largest sale in the entire file. What data type will you use?

the total number of sales in file. What data type will you use?

the sales average of all sales in file. What data type will you use?

NOTE: you will need a variable to keep track of each of these. Sales numbers are not negative.

The loop will terminate when the end of the is reached (remember how to detect end of file?):

CLOSE the file.

Print TO TERMINAL before opening the SalesRpt.doc file:

Opening SalesRpt.doc to write output...

Open the SalesRpt.doc file to WRITE to it using PrintWriter.

Print the following TO FILE (SalesRpt.doc). Format these numbers using printf. Decimal numbers make sure have 2 decimal places and decimals are aligned.:

Number of sales in file: XXXXXX

Smallest sale in file: XXX.XX

Largest sale in file: XXX.XX

Sale Average: XXX.XX

After printing To File, make sure to CLOSE the file.

Print TO TERMINAL after closing the SalesRpt.doc file:

Print Done writing to SalesRpt.doc to Terminal.

Print Open up SalesRpt.doc in NotePad to view output. to Terminal.

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!