Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The purpose of this program is to read a file, called WaterData.csv. It will output date and gallons. So it would look something like 2/04/15
The purpose of this program is to read a file, called WaterData.csv. It will output date and gallons. So it would look something like "2/04/15 40 Gallons". The pseudo code is as follows.
prompt the user for a file name open the file if that file cannot be opened display an error message and quit endif create a String variable 'currentDate' and initialize it to the empty string. create a variable gallonsUsed and initialize it to 0 while the file has contents read a line if the line begins with an octothorpe (#) or is length 0 throw the line away end if split the line into fields called String[] dataFields if there are < or > 2 fields add an error message to an error list (ArrayList) throw the line away end if split dataFields[0] (the date field) into dateFields (what is the delimiter?) ignore the time field. if currentDate is empty assign dataField[0] to currentDate add the hours' reading to gallonsUsed else if currentDate <> dataField[0] we've found a new day output the date and the gallonsUsed for that date do not display any more than 1 digit to the right of the decimal point assign dataField[0] to currentDate reset gallonsUsed end if end while output the last reading
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started