Question

Problem You work for a dealership that deals in all kinds of vehicles. Cars, Trucks, Boats,...

Problem

You work for a dealership that deals in all kinds of vehicles. Cars, Trucks, Boats, and so forth need to be inventoried in the system. The inventory must be detailed so that it could be searched based on number of doors, engine type, color, and so on.

This program will demonstrate the following:

  • How to create a base class
  • How to extend a based class to create new classes
  • How to use derived classes

Solving the Problem

Step 1

The first thing you have to do is decide what attributes and aspects of all vehicle types will be shared. Once this decision is made, a base class can be created to be shared by the child classes later in the program. In this case, the color, horsepower, engine type, and price will be attributes shared by all vehicles. Included is a method that will be shared by all children to set the attributes that are common to them all.

Step 2

Given the base class, there are some aspects that need to be included for each vehicle type. Some have doors, and some do not. Some have length that matters, while most do not care. Some might have more or fewer wheels than others. These more specific classes take advantage of the common attributes while adding their own.

Step 3

After defining the classes, it is necessary to create objects of each type to add data to them. Although an object of type vehicle can be created, it is so generic that you really could not say what type of vehicle it was. The more specific objects will have the attributes that make them different from the other child classes.

Documentation Guidelines:

Use good programming style (e.g., indentation for readability) and document each of your program parts with the following items (the items shown between the '<' and '>' angle brackets are only placeholders. You should replace the placeholders and the comments between them with your specific information). Your cover sheet should have some of the same information, but what follows should be at the top of each program's sheet of source code. Some lines of code should have an explanation of what is to be accomplished, this will allow someone supporting your code years later to comprehend your purpose. Be brief and to the point. Start your design by writing comment lines of pseudocode. Once that is complete, begin adding executable lines. Finally run and test your program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

//super class which has comman properties of all vehicles.
class Vehicle{
   String numberPlate;
   String color;
   String model;
  
   //Constructors
   public Vehicle() {
   }
   public Vehicle(String numberPlate, String color, String model) {
       super();
       this.numberPlate = numberPlate;
       this.color = color;
       this.model = model;
   }
  
   //getters and setters
   public String getNumberPlate() {
       return numberPlate;
   }
   public void setNumberPlate(String numberPlate) {
       this.numberPlate = numberPlate;
   }
   public String getColor() {
       return color;
   }
   public void setColor(String color) {
       this.color = color;
   }
   public String getModel() {
       return model;
   }
   public void setModel(String model) {
       this.model = model;
   }
   @Override
   public String toString() {
       return "Vehicle: \nnumberPlate: " + numberPlate + "\ncolor: " + color + "\nmodel: " + model;
   }
  
  
  
}
//subclass which posses the super class fields
//subclass of Car is class which has specific properties of Car and Vehicle
class Car extends Vehicle{
   boolean carryPeople;
   boolean isCar;
   int numberOfWheels;
     
   //constructors
   public Car() {
       super();
   }
   public Car(String numberPlate, String color, String model,boolean carryPeople,boolean isCar, int numberOfWheels) {
       super(numberPlate, color, model);
       this.carryPeople=carryPeople;
       this.isCar=isCar;
       this.numberOfWheels=numberOfWheels;
   }
  
   //getters and setters
   public boolean isCarryPeople() {
       return carryPeople;
   }
   public void setCarryPeople(boolean carryPeople) {
       this.carryPeople = carryPeople;
   }
   public boolean isCar() {
       return isCar;
   }
   public void setCar(boolean isCar) {
       this.isCar = isCar;
   }
   public int getNumberOfWheels() {
       return numberOfWheels;
   }
   public void setNumberOfWheels(int numberOfWheels) {
       this.numberOfWheels = numberOfWheels;
   }
   @Override
   public String toString() {
       return "Car: \ncarryPeople: " + carryPeople + "\nisCar: " + isCar + "\nnumberOfWheels: " + numberOfWheels
               + "\nnumberPlate: " + numberPlate + "\ncolor: " + color + "\nmodel: " + model;
   }
  
     
}
//subclass which posses the super class fields
//subclass of Truck is class which has specific properties of Truck and Vehicle
class Truck extends Vehicle{
   boolean carryThings;
   boolean isTruck;
   int numberOfWheels;
  
   //constructors
   public Truck() {
       super();
   }
   public Truck(String numberPlate, String color, String model,boolean carryThings,boolean isTruck,int numberOfWheels) {
       super(numberPlate, color, model);
       this.carryThings=carryThings;
       this.isTruck=isTruck;
       this.numberOfWheels=numberOfWheels;
      
   }
  
   //setters and getters
   public boolean isCarryThings() {
       return carryThings;
   }
   public void setCarryThings(boolean carryThings) {
       this.carryThings = carryThings;
   }
   public boolean isTruck() {
       return isTruck;
   }
   public void setTruck(boolean isTruck) {
       this.isTruck = isTruck;
   }
   public int getNumberOfWheels() {
       return numberOfWheels;
   }
   public void setNumberOfWheels(int numberOfWheels) {
       this.numberOfWheels = numberOfWheels;
   }
   @Override
   public String toString() {
       return "Truck: \ncarryThings: " + carryThings + "\nisTruck: " + isTruck + "\nnumberOfWheels: " + numberOfWheels
               + "\nnumberPlate: " + numberPlate + "\ncolor: " + color + "\nmodel: " + model;
   }
  
  
}
public class DemoClass {

   public static void main(String[] args) {
       //creating an object of super class;
       Vehicle myVehicle = new Vehicle("100","black","ABC");
       //creating an objects of subclasses Car and Truck
       Vehicle myCar= new Car("200","blue","BCA",true,true,4);
       Vehicle myTruck= new Truck("300","red","ACB",true,true,8);
      
       System.out.println(myVehicle.toString()+"\n");
       System.out.println(myCar.toString()+"\n");
       System.out.println(myTruck.toString()+"\n");
   }

}

Output:

Vehicle:
numberPlate: 100
color: black
model: ABC

Car:
carryPeople: true
isCar: true
numberOfWheels: 4
numberPlate: 200
color: blue
model: BCA

Truck:
carryThings: true
isTruck: true
numberOfWheels: 8
numberPlate: 300
color: red
model: ACB

Add a comment
Know the answer?
Add Answer to:
Problem You work for a dealership that deals in all kinds of vehicles. Cars, Trucks, Boats,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Questions Submission Question 2: Stacks Problem Write a program that keeps track of where cars are...

    Questions Submission Question 2: Stacks Problem Write a program that keeps track of where cars are located in a parking garage to estimate the time to retrieve a car when the garage is full. This program will demonstrate the following: How to create a list for use as a stack, How to enter and change data in a stack. Solving the Problem Step 1 In Python, the stack data structure is actually implemented using the list data structure with a...

  • Python 3 IDE/AWS Problem You are tasked with writing a new program for your company that...

    Python 3 IDE/AWS Problem You are tasked with writing a new program for your company that keeps track of the customer’s information and his or her current bill. The company wants the name, address, phone number, and balance to be stored for each customer. This program will demonstrate the following: How to use a class to organize data How to use methods to access the data of a class How to create objects from a class Solving the Problem Step...

  • Picture a car dealership. There are many different types of vehicles for sale. The salespeople know...

    Picture a car dealership. There are many different types of vehicles for sale. The salespeople know every detail about every one. But the accountants inside only care that a vehicle is getting sold. Model this system: The dealer sells Hatchbacks and Sedans Every vehicle has a price Hatchbacks have 5 doors and sedans have 4 Every vehicle has a trunk. A hatchback holds 30 cu ft, a sedan 20 Lastly, every vehicle can be started Make two functions that take...

  • Python 3 Problem: I hope you can help with this please answer the problem using python...

    Python 3 Problem: I hope you can help with this please answer the problem using python 3. Thanks! Code the program below . The program must contain and use a main function that is called inside of: If __name__ == “__main__”: Create the abstract base class Vehicle with the following attributes: Variables Methods Manufacturer Model Wheels TypeOfVehicle Seats printDetails() - ABC checkInfo(**kwargs) The methods with ABC next to them should be abstracted and overloaded in the child class Create three...

  • Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in...

    Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in interesting ways. Now you’ll get a chance to use more of what objects offer, implementing inheritance and polymorphism and seeing them in action. You’ll also get a chance to create and use abstract classes (and, perhaps, methods). After this project, you will have gotten a good survey of object-oriented programming and its potential. This project won’t have a complete UI but will have a...

  • Use Java and please try and show how to do each section. You are creating a 'virtual pet' program...

    Use Java and please try and show how to do each section. You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of...

  • Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and...

    Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...

  • Please help me with the following question. This is for Java programming. In this assignment you...

    Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT