Knowee
Questions
Features
Study Tools

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.

Question

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.

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

Solution 1

Sure, here is a simple implementation of the problem in Java:

// Vehicle class
public class Vehicle {
    String vehicleType;
    String vehicleNumber;

    public Vehicle(String vehicleType, String vehicleNumber) {
        this.vehicleType = vehicleType;
        this.vehicleNumber = vehicleNumber;
    }

    public void report() {
        System.out.println("Vehicle Type: " + vehicleType);
        System.out.println("Vehicle Number: " + vehicleNumber);
    }
}

// PassengerVehicle class
public class PassengerVehicle extends Vehicle {
    String engineNumber;
    String chassisNumber;
    int topSpeed;
    int numberOfPassengers;
    int numberOfGears;

    public PassengerVehicle(String vehicleType, String vehicleNumber, String engineNumber, String chassisNumber, int topSpeed, int numberOfPassengers, int numberOfGears) {
        super(vehicleType, vehicleNumber);
        this.engineNumber = engineNumber;
        this.chassisNumber = chassisNumber;
        this.topSpeed = topSpeed;
        this.numberOfPassengers = numberOfPassengers;
        this.numberOfGears = numberOfGears;
    }

    @Override
    public void report() {
        super.report();
        System.out.println("Engine Number: " + engineNumber);
        System.out.println("Chassis Number: " + chassisNumber);
        System.out.println("Top Speed: " + topSpeed);
        System.out.println("Number of Passengers: " + numberOfPassengers);
        System.out.println("Number of Gears: " + numberOfGears);
    }
}

// NonPassengerVehicle class
public class NonPassengerVehicle extends Vehicle {
    int totalLoad;

    public NonPassengerVehicle(String vehicleType, String vehicleNumber, int totalLoad) {
        super(vehicleType, vehicleNumber);
        this.totalLoad = totalLoad;
    }

    @Override
    public void report() {
        super.report();
        System.out.println("Total Load: " + totalLoad);
    }
}

In this code, Vehicle is the parent class with vehicleType and vehicleNumber as members. PassengerVehicle and NonPassengerVehicle are child classes that inherit from Vehicle. PassengerVehicle has additional members like engineNumber, chassisNumber, topSpeed, numberOfPassengers, and numberOfGears. NonPassengerVehicle has an additional member totalLoad. The report method is overridden in both child classes to print the details of the vehicle.

This problem has been solved

Solution 2

Sure, here is a simple implementation of the problem in Java:

// Vehicle class
public class Vehicle {
    String vehicleType;
    String vehicleNumber;

    public Vehicle(String vehicleType, String vehicleNumber) {
        this.vehicleType = vehicleType;
        this.vehicleNumber = vehicleNumber;
    }

    public void report() {
        System.out.println("Vehicle Type: " + vehicleType);
        System.out.println("Vehicle Number: " + vehicleNumber);
    }
}

// PassengerVehicle class
public class PassengerVehicle extends Vehicle {
    String engineNumber;
    String chassisNumber;
    int topSpeed;
    int numberOfPassengers;
    int numberOfGears;

    public PassengerVehicle(String vehicleType, String vehicleNumber, String engineNumber, String chassisNumber, int topSpeed, int numberOfPassengers, int numberOfGears) {
        super(vehicleType, vehicleNumber);
        this.engineNumber = engineNumber;
        this.chassisNumber = chassisNumber;
        this.topSpeed = topSpeed;
        this.numberOfPassengers = numberOfPassengers;
        this.numberOfGears = numberOfGears;
    }

    @Override
    public void report() {
        super.report();
        System.out.println("Engine Number: " + engineNumber);
        System.out.println("Chassis Number: " + chassisNumber);
        System.out.println("Top Speed: " + topSpeed);
        System.out.println("Number of Passengers: " + numberOfPassengers);
        System.out.println("Number of Gears: " + numberOfGears);
    }
}

// NonPassengerVehicle class
public class NonPassengerVehicle extends Vehicle {
    int totalLoad;

    public NonPassengerVehicle(String vehicleType, String vehicleNumber, int totalLoad) {
        super(vehicleType, vehicleNumber);
        this.totalLoad = totalLoad;
    }

    @Override
    public void report() {
        super.report();
        System.out.println("Total Load: " + totalLoad);
    }
}

In this code, Vehicle is the parent class with vehicleType and vehicleNumber as members. PassengerVehicle and NonPassengerVehicle are child classes that inherit from Vehicle. PassengerVehicle has additional members like engineNumber, chassisNumber, topSpeed, numberOfPassengers, and numberOfGears. NonPassengerVehicle has an additional member totalLoad. The report method is overridden in both child classes to print the details of the vehicle.

You can create instances of PassengerVehicle and NonPassengerVehicle for car, bike, bicycle, and lorry as per your requirements.

This problem has been solved

Solution 3

Sure, here is a simple implementation of the problem in Java:

// Vehicle class
public class Vehicle {
    String vehicleType;
    String vehicleNumber;

    public Vehicle(String vehicleType, String vehicleNumber) {
        this.vehicleType = vehicleType;
        this.vehicleNumber = vehicleNumber;
    }
}

// PassengerVehicle class
public class PassengerVehicle extends Vehicle {
    String engineNumber;
    String chassisNumber;
    int topSpeed;
    int numberOfPassengers;
    int numberOfGears;

    public PassengerVehicle(String vehicleType, String vehicleNumber, String engineNumber, String chassisNumber, int topSpeed, int numberOfPassengers, int numberOfGears) {
        super(vehicleType, vehicleNumber);
        this.engineNumber = engineNumber;
        this.chassisNumber = chassisNumber;
        this.topSpeed = topSpeed;
        this.numberOfPassengers = numberOfPassengers;
        this.numberOfGears = numberOfGears;
    }
}

// NonPassengerVehicle class
public class NonPassengerVehicle extends Vehicle {
    int totalLoad;

    public NonPassengerVehicle(String vehicleType, String vehicleNumber, int totalLoad) {
        super(vehicleType, vehicleNumber);
        this.totalLoad = totalLoad;
    }
}

// Car class
public class Car extends PassengerVehicle {
    public Car(String vehicleNumber, String engineNumber, String chassisNumber, int topSpeed, int numberOfPassengers, int numberOfGears) {
        super("Car", vehicleNumber, engineNumber, chassisNumber, topSpeed, numberOfPassengers, numberOfGears);
    }
}

// Bike class
public class Bike extends PassengerVehicle {
    public Bike(String vehicleNumber, String engineNumber, String chassisNumber, int topSpeed, int numberOfPassengers, int numberOfGears) {
        super("Bike", vehicleNumber, engineNumber, chassisNumber, topSpeed, numberOfPassengers, numberOfGears);
    }
}

// Lorry class
public class Lorry extends NonPassengerVehicle {
    public Lorry(String vehicleNumber, int totalLoad) {
        super("Lorry", vehicleNumber, totalLoad);
    }
}

// Bicycle class
public class Bicycle extends NonPassengerVehicle {
    public Bicycle(String vehicleNumber, int totalLoad) {
        super("Bicycle", vehicleNumber, totalLoad);
    }
}

In this code, we have a base class Vehicle with vehicleType and vehicleNumber as members. We then have two classes PassengerVehicle and NonPassengerVehicle that extend Vehicle and add their own members. Finally, we have Car, Bike, Lorry, and Bicycle classes that extend PassengerVehicle or NonPassengerVehicle and set the vehicleType in their constructors.

You can create instances of these classes and use their members to generate a report for the vehicles.

This problem has been solved

Similar Questions

Develop a Java Application with ‘Vehicle’ Class with vehicle type, vehicle number, engine number, chassis number, top speed, number of passengers, number of gears. Generate a report for the vehicles. Implement the concept using Interfaces.

evelop a Java Application with ‘Vehicle’ Class with vehicle type, vehicle number, engine number, chassis number, top speed, number of passengers, number of gears. Generate a report for the vehicles. Implement the concept using Interfaces.

This assignment will assess your skills and knowledge on implementing interfaces to define contracts and enforce common behavior across multiple classes.Context: You are tasked with developing a software application for a car rental agency. The application needs to handle different types of vehicles, including cars, motorcycles, and trucks. To enforce a common behavior and ensure consistency among these vehicle types, you decide to utilize interfaces. Additionally, you want to incorporate various small modules into the question to make it engaging and interactive for the developers.For this assignment, Compose a Java programming question that incorporates the following modules:Design and implement an interface named "Vehicle" that includes methods for retrieving the vehicle's make, model, and year of manufacture.Develop a class named "Car" that implements the Vehicle and "CarVehicle" interfaces. This interface includes additional methods for setting and retrieving the number of doors and the fuel type (petrol, diesel, or electric).Construct a class named "Motorcycle" that also implements Vehicle and the "MotorVehicle" interfaces. This interface should have methods for setting and retrieving the number of wheels and the type of motorcycle (sport, cruiser, or off-road).Generate a class named "Truck" that implements the Vehicle and "TruckVehicle" interfaces. This interface should include methods for setting and retrieving the cargo capacity (in tons) and the transmission type (manual or automatic).Integrate all the classes into a main program that allows the user to create objects of different vehicle types, provide relevant information, and display the details of each vehicle.You will be accessed based on the following criteria:The interface design in the Vehicle Information System provides a contract specifying the methods for retrieving and setting vehicle details, ensuring a consistent structure for different vehicle types.The class implementation in the Vehicle Information System translates the interface specifications into concrete implementations for different vehicle types, enabling the storage and retrieval of specific attributes and behaviors.The main program in the Vehicle Information System allows users to interactively create, input, and display details of various vehicle objects, providing a comprehensive interface for managing and accessing vehicle information.The code quality in the Vehicle Information System emphasizes readability, maintainability, and adherence to best practices, ensuring a clean and well-structured codebase that promotes efficient development and future scalability.The error handling mechanism in the Vehicle Information System effectively manages and gracefully handles potential exceptions or invalid user inputs, ensuring a robust and stable application experience.The documentation in the Vehicle Information System provides clear and comprehensive explanations of classes, methods, and their functionalities, aiding developers in understanding and maintaining the codebase effectively.Remember to use appropriate variable names and follow coding best practices.

The type Vehicle has drive functionality. The classes Car and Bike implements the drive functionality and can be further subclassed.  Fill in the given code with appropriate access specifier so that the subclasses of Car and Bike do not modify the Drive functionality.interface Vehicle{   void drive();}class Car implements Vehicle{    final void drive()    {        //drive    } }

Design a C++ program to manage vehicles for a transport company. The program should handle three types of vehicles: cars, trucks, and buses. Implement a class with a base class and derived classes for each vehicle type. The base class, Vehicle, should have the following attributes: colour, mileage, top speed, and the number of gears. Each derived class should inherit from the Vehicle class and include additional attributes specific to the vehicle type.Car Class (Derived from Vehicle):Additional Attributes: number of doors and fuel type.Functionality: Implement a function to display car details, including all attributes inherited from the base class and the additional attributes specific to cars.Truck Class (Derived from Vehicle):Additional Attributes: cargo capacity and max load capacity.Functionality: Implement a function to display truck details, including all attributes inherited from the base class and the additional attributes specific to trucks.Bus Class (Derived from Vehicle):Additional Attributes: seating capacity and route number.Functionality: Implement a function to display bus details, including all attributes inherited from the base class and the additional attributes specific to buses.

1/3

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.