Question
Suppose we have a class called Car that models cars. This class has instance variables year, make, model, and price. It also provides appropriate observer
Suppose we have a class called Car that models cars. This class has instance variables year, make, model, and price. It also provides appropriate observer methods, including one called getPrice that returns a value of type int indicating the price of "this" car. Implement a client method totalPrice, which accepts a list (ArrayUnsortedList carList) of cars and returns an integer equal to the total cost of the cars on the list.
I have made the car clas but do not know how to implement the client method that returns the total cost of cars on the list (NOTE: MUST BE an ARRAYUNSORTEDLIST). Thank you.
public class Car { private int year; private String make; private String model; private double price; public Car(int year, String make, String model, double price) { this.year = year; this.make = make; this.model = model; this.price = price; } public int getYear() { return year; } public String getMake() { return make; } public String getModel() { return model; } public double getPrice() { return price; } @Override public String toString() { return String.format( "%4d %s %s - $%,.2f", getYear(), getMake(), getModel(), getPrice() ); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started