• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

reading amounts from a text file

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
machines help you to do more, but experience less. Experience this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic