I need to program for school but I'm stuck right now.
Introduction
I have a file named "carlist.txt." This file has on each line information about a car in this order: vehicle_idnumber num_of_passengers fuel_capacity mpg make
So, a typical line might look like this: 487833 6 20 25 Ford
When you read in the file, you are guaranteed it is “clean”. The data are always:int int int int String over and over. This makes your work a lot simpler.
You also need to add a “method” to your vehicle object definition. This method should be a function that returns a double. The function computes the range of the vehicle. All it does is take the fuelcap and multiply it by the mpg. Your “turn-in” program needs to solve the following tasks.
Program 1:
Write a method which walks the array of cars and prints out the total number of each make of car. Your output should look something like: (these are made up numbers!)
MAKE NUMOFCARS
Ford 17 Subaru 23 GM 8 Porsche 5 Toyota 35 Suburban 12
Program 2: Write a method which analyzes all the cars and prints out the car id that has the highest range and the car id that has the lowest range. Note: range means fuel_cap * mpg. So, for example you might print out: (note, these are made-up numbers!)
Highest range: 987654 with a range of 430 miles Lowest range: 234567 with a range of 223 miles
In the example above the big number is the car vehicle number and the “miles” number is the range.
For program 1, I have to create an array (not array list!) but I don't how to deal with the fact that I don't know the size of the array upfront (since I don't know how many carmodels the list contains). How can I add car models or how do I handle the fact that one list might contain 5 car models and the next list contains 15 different models. How do I create this array out of my list?