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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

Java

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.
  • 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.
  • 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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,