Knowee
Questions
Features
Study Tools

Create an abstract class Motor Vehicle with the following details:Data Members: (a) model Name (b)model Number (c) model PriceMethods: display() to show all the details.Create a subclass of this class Car that inherits the class Motor Vehicle and add the following details:Data Members:  discount RateMethods:(a) display() method to display the Car name, model number, price and the discount rate.(b) discount() method to compute the discount.Input FormatName:Model No:Price:Discount rate:Discount value:Price after discount:Output FormatVehicleTN SA5221100000.00202000.008000.00

Question

Create an abstract class Motor Vehicle with the following details:Data Members: (a) model Name (b)model Number (c) model PriceMethods: display() to show all the details.Create a subclass of this class Car that inherits the class Motor Vehicle and add the following details:Data Members:  discount RateMethods:(a) display() method to display the Car name, model number, price and the discount rate.(b) discount() method to compute the discount.Input FormatName:Model No:Price:Discount rate:Discount value:Price after discount:Output FormatVehicleTN SA5221100000.00202000.008000.00

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution 1

Here is a step-by-step guide on how to create the abstract class Motor Vehicle and its subclass Car in Java:

Step 1: Declare the abstract class Motor Vehicle

public abstract class MotorVehicle {
    protected String modelName;
    protected String modelNumber;
    protected double modelPrice;

    public MotorVehicle(String modelName, String modelNumber, double modelPrice) {
        this.modelName = modelName;
        this.modelNumber = modelNumber;
        this.modelPrice = modelPrice;
    }

    public abstract void display();
}

Step 2: Declare the subclass Car that extends Motor Vehicle

public class Car extends MotorVehicle {
    private double discountRate;

    public Car(String modelName, String modelNumber, double modelPrice, double discountRate) {
        super(modelName, modelNumber, modelPrice);
        this.discountRate = discountRate;
    }

    public double discount() {
        return this.modelPrice * this.discountRate / 100;
    }

    @Override
    public void display() {
        System.out.println("Name: " + this.modelName);
        System.out.println("Model No: " + this.modelNumber);
        System.out.println("Price: " + this.modelPrice);
        System.out.println("Discount rate: " + this.discountRate);
        System.out.println("Discount value: " + discount());
        System.out.println("Price after discount: " + (this.modelPrice - discount()));
    }
}

Step 3: Test the Car class

public class Main {
    public static void main(String[] args) {
        Car car = new Car("Vehicle", "TN SA522", 10000, 20);
        car.display();
    }
}

When you run the Main class, it will create a new Car object and display its details, including the discount value and the price after discount.

This problem has been solved

Solution 2

Here is a step-by-step guide on how to create the abstract class Motor Vehicle and its subclass Car in Java:

Step 1: Declare the abstract class Motor Vehicle

public abstract class MotorVehicle {
    protected String modelName;
    protected String modelNumber;
    protected double modelPrice;

    public MotorVehicle(String modelName, String modelNumber, double modelPrice) {
        this.modelName = modelName;
        this.modelNumber = modelNumber;
        this.modelPrice = modelPrice;
    }

    public abstract void display();
}

Step 2: Declare the subclass Car that extends Motor Vehicle

public class Car extends MotorVehicle {
    private double discountRate;

    public Car(String modelName, String modelNumber, double modelPrice, double discountRate) {
        super(modelName, modelNumber, modelPrice);
        this.discountRate = discountRate;
    }

    public double discount() {
        return this.modelPrice * this.discountRate / 100;
    }

    @Override
    public void display() {
        System.out.println("Name: " + this.modelName);
        System.out.println("Model No: " + this.modelNumber);
        System.out.println("Price: " + this.modelPrice);
        System.out.println("Discount rate: " + this.discountRate);
        System.out.println("Discount value: " + discount());
        System.out.println("Price after discount: " + (this.modelPrice - discount()));
    }
}

Step 3: Test the classes

public class Main {
    public static void main(String[] args) {
        Car car = new Car("Vehicle", "TN SA522", 10000, 20);
        car.display();
    }
}

When you run the Main class, it will create a new Car object and display its details, including the discount value and the price after discount.

This problem has been solved

Solution 3

This seems like a task in Java. Here's how you can create the classes:

// Abstract class MotorVehicle
abstract class MotorVehicle {
    String modelName;
    String modelNumber;
    double modelPrice;

    MotorVehicle(String modelName, String modelNumber, double modelPrice) {
        this.modelName =

Solution 4

Here is a step-by-step guide on how to create the abstract class Motor Vehicle and its subclass Car in Java:

Step 1: Create the abstract class Motor Vehicle

public abstract class MotorVehicle {
    protected String modelName;
    protected String modelNumber;
    protected double modelPrice;

    public MotorVehicle(String modelName, String modelNumber, double modelPrice) {
        this.modelName = modelName;
        this.modelNumber = modelNumber;
        this.modelPrice = modelPrice;
    }

    public abstract void display();
}

Step 2: Create the subclass Car that inherits from Motor Vehicle

public class Car extends MotorVehicle {
    private double discountRate;

    public Car(String modelName, String modelNumber, double modelPrice, double discountRate) {
        super(modelName, modelNumber, modelPrice);
        this.discountRate = discountRate;
    }

    @Override
    public void display() {
        System.out.println("Name: " + modelName);
        System.out.println("Model No: " + modelNumber);
        System.out.println("Price: " + modelPrice);
        System.out.println("Discount rate: " + discountRate);
        System.out.println("Discount value: " + discount());
        System.out.println("Price after discount: " + (modelPrice - discount()));
    }

    public double discount() {
        return modelPrice * discountRate / 100;
    }
}

Step 3: Test the Car class

public class Main {
    public static void main(String[] args) {
        Car car = new Car("Vehicle", "TN SA522", 10000, 20);
        car.display();
    }
}

This will output:

Name: Vehicle
Model No: TN SA522
Price: 10000.0
Discount rate: 20.0
Discount value: 2000.0
Price after discount: 8000.0

This problem has been solved

Similar Questions

Defi ne a class MotorVehicle as describedbelow: Data members: (a) modelName (b) modelNumber (c) modelPrice Methods: (a) display() method to display the name,price, and model number. Defi ne another class named Car that inherits theclass MotorVehicle and has the following: Data members: (a) discountRateMethods: (a) display() method to display the Carname, Car model number, Car price, andthe discount rate. (b) discount() method to compute thediscount Create the classes MotorVehicleand Car with suitable constructors andtest it.

Develop a Java Application with ‘Vehicle’ Class with vehicle type, vehicle number, as member. Inherit the classes bicycle, car, bike, and lorry from vehicle class. Consider car and bike only as passenger vehicle. Get inputs engine number, chassis number, top speed, number of passengers, number of gears for Passenger vehicle, and if is not a passenger vehicle, get inputs total amount of load to carry for the respective inherited classes. Generate a report for the vehicles. Implement the concept using inheritance and method overriding. Input form:Car (VEHICLE TYPE)HRDQ2456 (VEHICLE NUMBER)52WVC1234 (ENGINE NUMBER)2H2X1234 (CHASSIS NUMBER)535kph (SPEED)4 (No. of PASSENGER)5 (GEARS)Output form:CarHRDQ245652WVC12342H2X1234535kph45

Problem 2: Classes and Objects Scenario: Write a Python program to implement the concept of classes, methods, and objects. Instructions:  Create a Python Class named “Vehicle.”  This Class will have a total of five (5) attributes and one (1) method, as follows: o Attributes: type, total_seats, color, price, mileage o Method: print_detail()  If the total number of seats in a vehicle is more than seven (7) and the price is more than $50,000, print “It is an unaffordable vehicle.” Otherwise, print “You may afford and easily park it.”  Create the following four (4) vehicle objects: bus, bike, car, and pickup_truck.  For each object, take the attribute value from the user. This means the user will enter all five (5) attribute values for each object.  Assign these values to the related object and print all the details one by one.  In your program logic, you must use the concept of classes, methods, and objects, as well as accessing methods through objects.  Save your Python file as: Problem2_StudentNameInitials

Complete the Car class byDeclaring the String factory instance variableDeclaring the String model instance variableDeclaring int year instance variableDeclaring string colour instance variableWriting the constructor method with input parameters for factory, model, year and colourWriting the method carAge to display the age of the car (2024 - year)Complete the main method byUsing new to create an instance of Car with the constructor: Car("BMW" , "X5" , 2021 , "Black") Printing the car detailsPrinting the return value for the carAge() method on the Car instance

Predict the outputabstract class Vehicle{    abstract void calcPremium(Number N);}interface Insurance{    abstract void calcPremium (Object O);}class Car extends Vehicle implements Insurance{                 public void calcPremium (Object O)                    {                        System.out.println("Object");                    }    void calcPremium (Number N)     {        System.out.println("Number");    } }public class Test{    public static void main(String[] args)    {        Vehicle a = new Car();         a. calcPremium (new Integer(121));          Insurance b = new Car();           b. calcPremium (new Integer(121));           Car c = new Car();            c. calcPremium (new Integer(121));    }}Select one:a.NumberObjectNumberb.NumberNumberObjectc.Run time errord.Compile time error

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.