Two files are required, a data class named Car and an executable class named TestCar.
Class Car (data class, no main method)
five instance data members, all private: String make, String model, int year, double price, String color.
one static, or class, member named unitsSold assigned a value of zero. Make it public.
a no-arg constructor, and another parameterized constructor that sets values in all data members when called. Both constructors should increment the unitsSold static data member.
has setters and getters for each data member.
a toString() method that returns the state of all data members of a Car instance
In Class TestCar
must hold a main method and a method named evaluateCars
In main:
create two Car instances using the parameterized constructor.
create a third Car instance with the no-arg constructor
use all of the Car class setter methods to assign values to the third Car's data members.
use the "array initializer" syntax to make an array to hold these three Car objects.
call the method named evaluateCars with the array as its sole argument.
Make sure you catch the value returned by evaluateCars.
print the value in the unitsSold data member and the value returned by evaluateCars
In evaluateCars
use a foreach loop to process the array passed in to the method
print the state of each Car object using the toString method.
calculate the total value of the Car objects in the array.
return the total value to main.
Example Output
make=Lamborghini, model=Aventador, year=2016, price=405000.0, color=yellow
make=Honda, model=Odyssey, year=2015, price=33560.0, color=cherry
make=Dodge, model=Hellcat, year=2016, price=76500.0, color=orange
Your 3 cars are worth $515,060.00