March 10th, 2013, 04:51 AM
Join Date: Mar 2013
Time spent in forums: 10 m 52 sec
Reputation Power: 0
Homework - Cars Project (Help)
[IMG]Please can someone answer this question so i can compare mine.
Create a java class called Car.
The class needs to contain 4 variables
- ManType (The manufactures Name)
- Colour (A number to represent the colours)
- Length (The length of the car)
- Height (The height of the car)
Create getter and setter methods for all veriables. the setter method for ManType should ensure that the string passed as a parameter is converted to uppercase before being saved as the ManType.
Create a parameterised constructor. It should use the setter methods to set variables and not set the variables directly.
Create a toString() method. the method should return a String that follows the example below. "This is a White Audi of length 3.5m and height 1.5m" White,Audi,3.5 and 1.5 all taken from the variables.[/IMG]
Create a Scanner connecting to the text file Cars.txt
Read each line of the text file, and break into 4 variables. after checking vadility of variables, use the, to create a new car object, and store that into the Cars array CarA.
Create a parameterised method Count(String manType) which returns the number of cars in the array which match the manufacturers name.
Create a parameterised method Count(int colour) which returns the number of cars in the array which match the supplied colour.
Create a method called RandomPrint(). this method should check the number of cars in the array, and then select 10 random cars and print out their stats, by use of the toString() method of the car itself.
Create a method LongestCar(), which searches the array for the longest vehicle and prints out its details.
Create a method LowestCar(), which searches the array for the lowest vehicle and prints out its details.[/IMG]