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<String>)
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 readingI will be writing this code in Python. However, I do not have the CSV file. So, I will be providing a partial solution. Thumbs up if you like the solution.
# Displaying error if the file can not be opened.
import sys
try:
f = open('WaterData.csv', 'rb')
except IOError:
print ("Could not read file: WaterData.csv")
sys.exit()
#Defining the variables.
currentDate = ''
gallonsUsed = 0
#Reading the CSV file.
import csv
with open("WaterData.csv", "r") as f:
reader = csv.reader(f, delimiter="\t") #Change the delimeter
according to your file.
for i, line in enumerate(reader):
if not line.startswith('#') or not line.startswith(''):
if len(list)==2:
else:
print('Error in the line.')
continue:
The purpose of this program is to read a file, called WaterData.csv. It will output date...
Write in Java please. 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...
write a c++ code to read multiple integers from input.dat until the end of file. Edit input.dat and put several integers in it. Compile and execute the code then check output.dat to verify all the integers are in there. Update the code to check to see if input.dat exists before reading from it. If it doesn’t exist print an error message (and don’t read!). Compile and execute your code. Delete input.dat and output.dat and execute – did you see your...
Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...
The following code uses a Scanner object to read a text file called dogYears.txt. Notice that each line of this file contains a dog's name followed by an age. The program then outputs this data to the console. The output looks like this: Tippy 2 Rex 7 Desdemona 5 1. Your task is to use the Scanner methods that will initialize the variables name1, name2, name3, age1, age2, age3 so that the execution of the three println statements below will...
Description:
This Java program will
read in data from a file students.txt that keeps records
of some students. Each line in students.txt contains
information about one student, including his/her firstname,
lastname, gender, major, enrollmentyear and whether he/she is a
full-time or part-time student in the following format.
FIRSTNAME
LASTNAME
GENDER
MAJORENROLLMENTYEAR FULL/PART
The above six fields are separated by a
tab key.
A user can input a
keyword indicating what group of students he is searching for. For
example, if...
The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...
C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything. Your function should be named...
Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500 inclusive. 1.Use a file called randoms.txt as a input file and output file a. If you go to open the file and its not there then ask the user to create the file and then quit 2. Ask the user to specify how many random numbers the file will hold. a.Make sure that the...
Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...
(Java) Rewrite the following exercise below to read inputs from a file and write the output of your program in a text file. Ask the user to enter the input filename. Use try-catch when reading the file. Ask the user to enter a text file name to write the output in it. You may use the try-with-resources syntax. An example to get an idea but you need to have your own design: try ( // Create input files Scanner input...