IN JAVA. Any help is appreciated! Thank you! PART 1 : Automobiles Create a data class named Automobile that implements the Comparable interface. Give the class data fields for make, model, year, and price. Then add a constructor, all getters, a toString method that shows all attribute values, and implement Comparable by using the year as the criterion for comparing instances. Write a program named TestAutos that creates an ArrayList of five or six Automobiles. Use a for loop to display the elements in the ArrayList. Sort the Arraylist of autos by year with Collections.sort(). Finally, use a foreach loop to display the ArrayList sorted by year
IN JAVA.
Any help is appreciated! Thank you!
PART 1 : Automobiles
Create a data class named Automobile that implements the Comparable interface. Give the class data fields for make, model, year, and price. Then add a constructor, all getters, a toString method that shows all attribute values, and implement Comparable by using the year as the criterion for comparing instances.
Write a program named TestAutos that creates an ArrayList of five or six Automobiles. Use a for loop to display the elements in the ArrayList. Sort the Arraylist of autos by year with Collections.sort(). Finally, use a foreach loop to display the ArrayList sorted by year.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
PART 2: Pets
Examine carefully the UML class diagram below:
NOTE: Class Reptile was missing a toString() method. It has now been added.
- class Pet has an attribute of type java.util.Date.
- no specific dates are required for this attribute.
- compareTo(Dog) compares Dogs by weight.
Create executable class TestPet as follows:
- create at least one Reptile pet and display it
- create an array of at least four Dog pets
- sort the array of Dogs by weight
- use a foreach loop to fully display all data for all dogs sorted by weight (see sample output)