The data file vehicle_data_2.txt contains morerealistic vehicle data for cars, vans and trucks. If youexamine the data, you will see that in addition to data for fieldsgroup, vehID,regNo and make, all vehicles havedata for the following additional fields
model -- aString e.g. "Mondeo TDCiZetec";
airCon -- aboolean field set true only if the vehicle has airconditioning or climate control;
engineSize -- adouble (litres);
fuelType -- aString set to "Unleaded" or"Diesel";
gearbox -- aString e.g. "five-speedmanual";
transmission -- aString e.g. "RWD" for rear wheeldrive vehicles
mileage -- anint (miles);
dateFirstRegistered-- a String in the format, for example,"12-07-2018".
and cars, vans and trucks have different additional data.
Amend the Vehicle class so that it has thesenew fields shown above. But do not modify the "four parameter" formof the constructor -- in fact, it is no longer needed and it can bedeleted leaving only the "no parameter" form. In addition,you will need extra code in the readData() methodto read data for the new fields
Also, as the file vehicle_data_2.txt containslines such as
[Car data]
that will not be relevant until later, modify thereadVehicleData() method so that as well asignoring comment lines and blank lines, it also (temporarily)ignores lines that start with [.
With these changes you should now be able to read in data fromthe file vehicle_data_2.txt . Modify theprintDetails() method so that the details of eachvehicle are displayed in the terminal window in a format similarto:
Fiat Panda ActiveEco Group: AA Vehicle Id:TF-63403
Airconditioning/Climate Control: No
Engine Size:1.1 Fuel: Unleaded
Gearbox:five-speed manual Transmission: FWD
Mileage:13584 Date first registered: 29-07-2014
Of course, not all the data in thefile will have been read and we will return to this issueshortly.
The data file vehicle_data_2.txt contains more realistic vehicle data for cars, vans and trucks. If you examine the dat
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am