Knowee
Questions
Features
Study Tools

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.Input:CarHRDQ245652WVC12342H2X1234535kph45

Question

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.Input:CarHRDQ245652WVC12342H2X1234535kph45

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

Solution

Sure, here is a simple implementation of a Vehicle class in Java. This class includes fields for vehicle type, vehicle number, engine number, chassis number, top speed, number of passengers, and number of gears.

public class Vehicle {
    private String vehicleType;
    private String vehicleNumber;
    private String engineNumber;
    private String chassisNumber;
    private int topSpeed;
    private int numberOfPassengers;
    private int numberOfGears;

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

    public String getVehicleType() {
        return vehicleType;
    }

    public String getVehicleNumber() {
        return vehicleNumber;
    }

    public String getEngineNumber() {
        return engineNumber;
    }

    public String getChassisNumber() {
        return chassisNumber;
    }

    public int getTopSpeed() {
        return topSpeed;
    }

    public int getNumberOfPassengers() {
        return numberOfPassengers;
    }

    public int getNumberOfGears() {
        return numberOfGears;
    }

    @Override
    public String toString() {
        return "Vehicle Type: " + vehicleType + "\nVehicle Number: " + vehicleNumber + "\nEngine Number: " + engineNumber + "\nChassis Number: " + chassisNumber + "\nTop Speed: " + topSpeed + " kph" + "\nNumber of Passengers: " + numberOfPassengers + "\nNumber of Gears: " + numberOfGears;
    }
}

You can create a new Vehicle object and print its details like this:

public class Main {
    public static void main(String[] args) {
        Vehicle car = new Vehicle("Car", "HRDQ2456", "52WVC1234", "2H2X12345", 35, 4, 5);
        System.out.println(car);
    }
}

This will print:

Vehicle Type: Car
Vehicle Number: HRDQ2456
Engine Number: 52WVC1234
Chassis Number: 2H2X12345
Top Speed: 35 kph
Number of Passengers: 4
Number of Gears: 5

This is a basic implementation and does not include any error checking or validation. You might want to add that depending on your specific requirements.

This problem has been solved

Similar Questions

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

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.

In a car-rental showroom, every car is identified by a car-ID. There are two categories of cars in the showroom and they are labelled XX and YY. The mileage of car XX is 15 kmpl and YY is 20 kmpl. Write a Java program that obtains the monthly fuel consumption for a specified number of cars  (user-defined) and determines which car has travelled the longest distance. Create a class Car and perform the above task using array of objects.Input form :Enter number of cars: 3Enter car-ID: 121Enter car label: XXEnter car’s monthly fuel consumption in litres: 10Enter car-ID: 122Enter car label: YYEnter car’s monthly fuel consumption in litres: 10Enter car-ID: 123Enter car label: YYEnter car’s monthly fuel consumption in litres: 5Output form :The car-ID of the car that has travelled longest distance is: 122The car label of the car that has travelled longest distance is YYDistance travelled: 200

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/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.