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
Question
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
Solution
Here is a simple implementation in Python:
class Vehicle:
year = 2022 # static member
def __init__(self, vehicle_number, name, cost, brand):
self.vehicle_number = vehicle_number
self.name = name
self.cost = cost
self.brand = brand
def display(self):
print(f"Vehicle Number: {self.vehicle_number}, Name: {self.name}, Cost: {self.cost}, Brand: {self.brand}, Year: {Vehicle.year}")
# creating objects
vehicle1 = Vehicle("1234", "Car", 20000, "Toyota")
vehicle2 = Vehicle("5678", "Bike", 1500, "Honda")
# displaying details
vehicle1.display()
vehicle2.display()
# creating array of objects
vehicles = [vehicle1, vehicle2]
# displaying details of all vehicles in the array
for vehicle in vehicles:
vehicle.display()
In this code, we first define a class Vehicle with data members vehicle_number, name, cost, brand and a static member year. The display method is used to print the details of a vehicle.
We then create two objects vehicle1 and vehicle2 of the Vehicle class and display their details.
Finally, we create an array vehicles of these objects and display the details of all vehicles in the array.
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.Input:CarHRDQ245652WVC12342H2X1234535kph45OutputCarHRDQ245652WVC12342H2X1234535kph45
Create a class Building with data members building number, name, area (in square feet), cost/square feet, location, total cost, and year of construction. Declare the cost/square feet as the static data member. Define a parametric constructor to initialize the data members. Make use of this pointer. Create an array of objects and display details of N buildings along with the total cost
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
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
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.
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.