IOPractical
IOPractical
Image that you own a prestigious car insurance firm. Your little brother has accidentally messed up
the file, but fortunately the file headers (first record) are not affected. Some records have lost the
integrity of the contraints on their values, some records are empty and some are incomplete or
meaningless. Each record is expected to have a string, double, int, int. Assume that if a record has
all the attributes in order and they meet the constraints discussed below, then the record is valid or
unaffected. Each records represents a Car object and its values are comma delimited.
You are expected to write a program that will read the records and instantite Car objects, add them
to an ArrayList of Car objects. Your program should then write the Car objects (using their
toString() method) into a text file named okay.txt if there is no existing duplicate in the okay.txt file
and the product of the topSpeed and numPassengers is greater than the milage for the Car. For
every corrupt record, write it into a text file named corrupt.txt (if its empty, write a “#” in the
corrupt.txt file). A record is corrupt if its value(s) prevent the instantiation of a Car object.
You are expected to code a standalone Car class and a program named IntegrityCheck. The car class
must have the following:
• private attributes with setters and getters: String carModelName, double topSpeed,int
numPassengers, int milage
• The String have at least 3 characters, otherwise the setter must prevent the instantiation of
the relevant object. The numerical values should be at least 1, any deviations must prevent
the instantiation of the object. The topSpeed must be at least 180 and at most 480. The
milage must be at least 0 and at most 250000.
• A public String toString() method that returns the values of the object as they appear in the
records of the carsdata.txt file.
• A public boolean sameAs(Car carobj) method that compares the values of the car invoking
it and the one passed as a formal parameter and returns true if all their attributes have the
same values.
• A public double getAveSpeed(String carName, ArrayList<Car>) that recieves an ArrayList
of Car objects and carModelName and returns the average top speed for all Car objects in
the arraylist that have the specified carName.
• A public Car getFastest(ArrayList<Car>) that returns the fastest Car object from the given
array list of Cars.
Your program must test all methods. Submit *.java and *.txt files (all of them) in *.zip file named
with your student number. Feel free to use additional methods to help with achieving the desired
functionality. Instead of using the throws IOException on method headers, use try-catch blocks
where necessary.