Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago