Knowee
Questions
Features
Study Tools

Create an abstract class Motor Vehicle with the following details:Data Members: (a) model Name (b)model Number (c) PriceMethods: display() to show all the details.Create a subclass of this class Car that inherits the class MotorVehicle 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 FormatRow1: Model NameRow2: Model NoRow3: PriceRow4: Discount rateOutput FormatRow1: Discount valueRow2: Price after discount

Question

Create an abstract class Motor Vehicle with the following details:Data Members: (a) model Name (b)model Number (c) PriceMethods: display() to show all the details.Create a subclass of this class Car that inherits the class MotorVehicle 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 FormatRow1: Model NameRow2: Model NoRow3: PriceRow4: Discount rateOutput FormatRow1: Discount valueRow2: Price after discount

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

Solution

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 MotorVehicle with its data members and method.

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

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

    public abstract void display();
}

Step 2: Declare the subclass Car that extends the MotorVehicle class. Add the new data member and methods.

public class Car extends MotorVehicle {
    private double discountRate;

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

    @Override
    public void display() {
        System.out.println("Model Name: " + modelName);
        System.out.println("Model Number: " + modelNumber);
        System.out.println("Price: " + price);
        System.out.println("Discount Rate: " + discountRate);
    }

    public void discount() {
        double discount = price * discountRate;
        double priceAfterDiscount = price - discount;
        System.out.println("Discount: " + discount);
        System.out.println("Price after discount: " + priceAfterDiscount);
    }
}

Step 3: Now you can create an object of the Car class and call its methods.

public class Main {
    public static void main(String[] args) {
        Car car = new Car("Model1", "1234", 20000, 0.1);
        car.display();
        car.discount();
    }
}

This program will first display the car details and then calculate and display the discount and the price after discount.

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.

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

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

creata a classs vehicle withe datamenbers vehicle number name cost brand and yeat. declare year as static. create objects and display the details. create array of objects

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.