Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

In Java

Your uncle is trying to keep track of his new-car and used-car lots by writing a Java program. He
needs your help in setting up his classes.
Implement a superclass named Car that contains a price instance variable, a getPrice method, and
a 1-parameter constructor. The getPrice method is a simple accessor method that returns the price
instance variable’s value. The 1-parameter constructor receives a cost parameter and assigns a
value to the price instance variable based on this formula:
price = cost * 2;
Implement two classes named NewCar and UsedCar; they are both derived from the Car
superclass. NewCar should contain a color instance variable (the car’s color). UsedCar should
contain a mileage instance variable (the car’s odometer reading). The NewCar and UsedCar
classes should each contain a 2-parameter constructor, an equals method, and a toString() method.
In the interest of elegance and maintainability, don’t forget to have your subclass constructors call
your superclass constructors when appropriate. The toString() method should print the values of
all the instance variables within its class.
Provide a driver class that tests your three car classes. Your driver class should contain this main
method:
public static void main(String[] args)
{
NewCar new1 = new NewCar(8000.33, "silver");
NewCar new2 = new NewCar(8000.33, "silver");
if (new1.equals(new2))
{
System.out.println(new1);
}
UsedCar used1 = new UsedCar(2500, 100000);
UsedCar used2 = new UsedCar(2500, 100000);
if (used1.equals(used2))
{
System.out.println(used1);
}
} // end main
Output:
price = 16,000ドル.66, color = silver
price = 5,000ドル.00, mileage = 100,000

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
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
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education