Question: Exercise 1: Arrays of Primitives Declare a reference variable for an array of doubles. Name the array prices. Instantiate the prices array to hold 50
Exercise 1: Arrays of Primitives
- Declare a reference variable for an array of doubles. Name the array prices.
- Instantiate the prices array to hold 50 doubles.
- Set the third array element of prices to 13.99. REMEMBER: Array indexing starts at 0.
- Write a for loop to count the number of values in the prices array that are greater than 10.
Exercise 2: Comparing Objects
Write an equals method for the Car class given here. Two Cars are equal if their Vehicle Identification Numbers (VIN) are the same. HINT: The String class has an equals method that can be called from the Car class equalsmethod.
Exercise 3: UML diagrams
Draw the UML diagram for the Car class from Exercise 2 after including the equals method.
Exercise 4: Arrays of Objects
- Declare and instantiate an array of 40 cars using the Car class. Name the array dealerCars.
- Write Java statements to add three cars to the dealerCars array.
- Make a hole at the beginning of the dealerCars array by moving the cars in the array up by one position.
- Add another car to the beginning of the array.
- Write a for loop to display all the cars in the dealerCars array. Add any necessary methods to the Car class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
