Question

In: Computer Science

package dealership; public abstract class Vehicle { private float dealerPrice; private int year; public Vehicle(float d,...

package dealership;

public abstract class Vehicle {
    private float dealerPrice;
    private int year;

    public Vehicle(float d, int y) { dealerPrice = d; year = y; }
    public float getDealerPrice()                 { return dealerPrice; }
    public int getYear()                          { return year;  }
    public abstract float getStickerPrice();
}

In the space below write a concrete class Car in the dealership package that is a subclass of Vehicle class given above.

You will make two constructors, both of which must call the superclass constructor. Make a two argument constructor (float, int) that initializes both instance variables using the arguments (think carefully about how this should be done). Make a single argument constructor (float) that initializes the dealerPrice with the float argument and initializes year to the current year (2020). Override the getStickerPrice()method so that it returns 1.5 times the dealerPrice if the year is at least 2010, and returns 1.2 times the dealerPrice if the year is older than 2010 (that is, year < 2010).

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================


package dealership;

public class Car extends Vehicle {


    //that initializes the dealerPrice with the float argument and initializes year to the current year (2020
    public Car(float price) {

        super(price, 2020);
    }

    //Make a two argument constructor (float, int) that initializes both instance variables
    public Car(float price, int year) {
        super(price, year);
    }


    public float getStickerPrice() {

        if (getYear() >= 2010)
            return (float) (1.5 * super.getDealerPrice());
        else
            return (float) (1.2 * super.getDealerPrice());
    }


}

====================================================================


Related Solutions

package compstore; public class Desktop{ private String brand; private float price; public Desktop(String brand, float price)...
package compstore; public class Desktop{ private String brand; private float price; public Desktop(String brand, float price) { this.brand = brand; this.price = price; } public String getBrand() { return brand; } public float getPrice() { return price; } } package compstore; public class DeskTopDeals{ // assume proper variables and other methods are here public void dealOfTheDay(Desktop[] items, int numItems){ /**************************** * your code would go here * ****************************/ } } Given the above Desktop class, write code that should go...
package construction; public class Bid{ private String contractor; private float price; public Bid(String contractor, float price)...
package construction; public class Bid{ private String contractor; private float price; public Bid(String contractor, float price) { this.contractor = contractor; this.price = price; } public String getContractor() { return contractor; } public float getPrice() { return price; } } package construction; public class ContractorBids{ // assume proper variables and other methods are here public void winningBid(Bid[] bids, int numBids){ /**************************** * your code would go here * ****************************/ } } You are doing renovations on your building, and multiple contractors...
public class Square {    public static final int NUM_OF_SIDES = 4;    private float length;...
public class Square {    public static final int NUM_OF_SIDES = 4;    private float length;       public Square(float l) {        setLength(l);    }       public void setLength(float l) {        if(l >= 0) {            length = l;        }    }       public float getLength() {        return length;    }           //TODO - Add method to calculate add return area          //TODO -...
package applications; public class Matrix { private int[][] m; public Matrix(int x, int y) { m...
package applications; public class Matrix { private int[][] m; public Matrix(int x, int y) { m = new int[x][y]; } public Matrix(int x, int y, int z) { m = new int[x][y]; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { m[i][j] = z; } } } public int rowsum(int i) throws IndexOutOfBoundsException { if (i < 0 || i > m.length-1) { throw new IndexOutOfBoundsException("Invalid Row"); } int sum =...
public class Clock { private int hr; private int min; private int sec; public Clock() {...
public class Clock { private int hr; private int min; private int sec; public Clock() { setTime(0, 0, 0); } public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); } public void setTime(int hours, int minutes, int seconds) { if (0 <= hours && hours < 24) hr = hours; else hr = 0; if (0 <= minutes && minutes < 60) min = minutes; else min = 0; if(0 <= seconds && seconds < 60) sec =...
public class SinglyLikedList {    private class Node{        public int item;        public...
public class SinglyLikedList {    private class Node{        public int item;        public Node next;        public Node(int item, Node next) {            this.item = item;            this.next = next;        }    }       private Node first;    public void addFirst(int a) {        first = new Node(a, first);    } } 1. Write the method add(int item, int position), which takes an item and a position, and...
The class Distance is defined below: class Distance //English Distance class { private: int feet; float...
The class Distance is defined below: class Distance //English Distance class { private: int feet; float inches; public: //constructor (no args) Distance() : feet(0), inches(0.0) { } //constructor (two args) Distance(int ft, float in) : feet(ft), inches(in) { } }; Overloading the following operators: a. + to add two Distance objects using member function. b. - to subtract two Distance objects using friend function c. << and >> Use the following main function to test your class Distance. int main()...
public class IntNode               {            private int data;            pri
public class IntNode               {            private int data;            private IntNode link;            public IntNode(int data, IntNode link){.. }            public int     getData( )          {.. }            public IntNode getLink( )           {.. }            public void    setData(int data)     {.. }            public void    setLink(IntNode link) {.. }         } All questions are based on the above class, and the following declaration.   // Declare an empty, singly linked list with a head and a tail reference. // you need to make sure that head always points to...
In the following class public class Single { private float unique; ... } Create constructor, setter...
In the following class public class Single { private float unique; ... } Create constructor, setter and getter methods, and toString method. Write a program that request a time interval in seconds and display it in hours, minutes, second format. NEED THESE ASAP
Consider the following java class: class Student {    private int student_Number;    private String student_Name;    public Student(int...
Consider the following java class: class Student {    private int student_Number;    private String student_Name;    public Student(int stNo,String name) {         student_Number=stNo;         student_Name=name;      }     public String getName() {       return student_Name;     }      public int getNumber() {       return student_Number;      }     public void setName(String st_name) {       student_Name = st_name;     } } Write a Tester class named StudentTester which contains the following instruction: Use the contractor to create a student object where student_Number =12567, student_Name = “Ali”. Use the setName method to change the name of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT