• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading amounts from a text file  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to modify the source code to read the sales amounts from a text file instead of the keyboard The code itself works and does that but it reads the text file and then asks me to input data. I am kind of a novice/intermediate so any advice would be greatly appreciated.
The purpose of this program:


Write a program that stores the weekly (Monday thru Friday) sales totals for three salespersons. Your program should read the sales amounts from a text file and print a sales report with headings, the daily totals for each salesperson (your two-dimensional array), the calculated weekly totals for each sales person and the calculated totals for the day of each salesperson. In addition, create a single-dimensional array of Strings representing the days of the week (Monday-Friday) using an initializer list.

Output Screen

Weekly Sales Report

Mon Tue Wed Thurs Fri Total

1 10.00 20.00 30.00 40.00 50.00 150.00
2 60.00 70.00 80.00 90.00 10.00 310.00
3 20.00 30.00 40.00 50.00 60.00 200.00
--------------------------------------------------------------
90.00 120.00 150.00 180.00 120.00 660.00

 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raina Yukoma wrote:..and then asks me to input data.

That's what the code starting at line 56 does. If you don't want that to happen, just take those lines out.
 
Raina Yukoma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but I also want the input data in the textfile be incorporated within similar output format in the sample I provided
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the String.split method to break up each line from the file into its constituent parts and then use Integer.parseInt to convert the substrings into integer values that you can store in your a array.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!