Question

In: Computer Science

Create a super class named Vehicle, which has the following attributes: VIN, engine size, Year, Speed....

Create a super class named Vehicle, which has the following attributes: VIN, engine size, Year, Speed. Check

Add a subclass named Car, which has the following additional attributes: Wheel size, Model, Miles (OOD). Check

Add another subclass to the vehicle superclass named Boat which has the following additional attributes: Hours, Gas type, Type (Fishing Boat, Deck boat, bowrider boat), and Check

Write a method named DisplayInfo() in your main to display the information of the Vehicle. In this method print all the features of the vehicle.

Add a method in each class to estimate the price of the vehicle subclasses base on some factors of each type. And call this method from the method DisplayInfo().

In the main method create three objects one of type Vehicle, the second of type Cars, and the third of type Boat.

I have the classes and variables made. How would i create the object (i know how to create) and pass this information to the display info.

Java language

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Vehicle.java

public class Vehicle {
   private String vin;
   private double engineSize;
   private int year;
   private int speed;

   public Vehicle(String vin, double engineSize, int year, int speed) {
       this.vin = vin;
       this.engineSize = engineSize;
       this.year = year;
       this.speed = speed;
   }

   public String getVin() {
       return vin;
   }

   public void setVin(String vin) {
       this.vin = vin;
   }

   public double getEngineSize() {
       return engineSize;
   }

   public void setEngineSize(double engineSize) {
       this.engineSize = engineSize;
   }

   public int getYear() {
       return year;
   }

   public void setYear(int year) {
       this.year = year;
   }

   public int getSpeed() {
       return speed;
   }

   public void setSpeed(int speed) {
       this.speed = speed;
   }

   @Override
   public String toString() {
       return " VIN :" + vin + ", Engine Size :" + engineSize + ", Year :"
               + year + ", Speed :" + speed;
   }

}
_________________________

// Boat.java

public class Boat extends Vehicle {
   private double hours;
   private String gasType;
   private String type;

   public Boat(String vin, double engineSize, int year, int speed,
           double hours, String gasType, String type) {
       super(vin, engineSize, year, speed);
       this.hours = hours;
       this.gasType = gasType;
       this.type = type;
   }

   public double getHours() {
       return hours;
   }

   public void setHours(double hours) {
       this.hours = hours;
   }

   public String getGasType() {
       return gasType;
   }

   public void setGasType(String gasType) {
       this.gasType = gasType;
   }

   public String getType() {
       return type;
   }

   public void setType(String type) {
       this.type = type;
   }

   @Override
   public String toString() {
       return "Boat Hours :" + hours + ", Gas Type :" + gasType + ", Type="
               + type + super.toString();
   }

   public void estimateCost() {
       if(getEngineSize()<=100)
       {
           System.out.println("Boat Cost : $23000");
           System.out.println(toString());
       }
       else if(getEngineSize()>100)
       {
           System.out.println("Boat Cost : $43000");
           System.out.println(toString());
       }
      
   }

}
_____________________________

// Car.java

public class Car extends Vehicle {
private double wheelSize;
private String model;
private double miles;
public Car(String vin, double engineSize, int year, int speed,
       double wheelSize, String model, double miles) {
   super(vin, engineSize, year, speed);
   this.wheelSize = wheelSize;
   this.model = model;
   this.miles = miles;
}
public double getWheelSize() {
   return wheelSize;
}
public void setWheelSize(double wheelSize) {
   this.wheelSize = wheelSize;
}
public String getModel() {
   return model;
}
public void setModel(String model) {
   this.model = model;
}
public double getMiles() {
   return miles;
}
public void setMiles(double miles) {
   this.miles = miles;
}
@Override
public String toString() {
   return "Car : WheelSize :" + wheelSize + ", Model=" + model + ", Miles :"
           + miles + super.toString();
}
public void estimateCost() {
   if(model.equals("Mahindra XUV500"))
   {
       System.out.println("Car Price :$20000");
       System.out.println(toString());
   }
   else if(model.equals("Swift"))
   {
       System.out.println("Car Price :$10000");
       System.out.println(toString());
   }
  
}

}
____________________________

// Test.java

public class Test {

   public static void main(String[] args) {
  
       Vehicle v=new Vehicle("SERQW1234567",5883,2019,120);
       Car c=new Car("MKAWES234156",2384,2017,160,16,"Mahindra XUV500",23000);
       Boat b=new Boat("BHAERS5467783",1500,2018,100,12,"E10","Fishing Boat");
      
       DisplayInfo(c);
       DisplayInfo(b);
       DisplayInfo(v);
      
   }

   private static void DisplayInfo(Object o) {
       if(o instanceof Car)
       {
           ((Car)o).estimateCost();
       }
       else if(o instanceof Boat)
       {
           ((Boat)o).estimateCost();
       }
  
      
   }

  

}
____________________________

Output:

Car Price :$20000
Car : WheelSize :16.0, Model=Mahindra XUV500, Miles :23000.0 VIN :MKAWES234156, Engine Size :2384.0, Year :2017, Speed :160
Boat Cost : $43000
Boat Hours :12.0, Gas Type :E10, Type=Fishing Boat VIN :BHAERS5467783, Engine Size :1500.0, Year :2018, Speed :100

_______________Thank You


Related Solutions

Create a car class with three attributes: year, mpg, speed and list of owners. The class...
Create a car class with three attributes: year, mpg, speed and list of owners. The class also should have 2 methods called accelerate and brake. Whenever the car accelerates, its speed is increased by 30 and whenever the car brakes, its speed is reduced by 60. add a constructor to the class, which takes year, mpg, and speed as input implement a magic method that prints the car information including year, speed and mpg. That is, for a car object,...
Here is the assignment description. * Create a class named 'Account' having the following private attributes...
Here is the assignment description. * Create a class named 'Account' having the following private attributes int accountNumber; double balance; * Write a constructor with parameters for each of the attributes. * Write another constructorwith one parameter for the accountNumber. * Write getter and setter methods for each of the private attributes. * Write a method void credit(double amount) which adds the given amount to the balance. * Write a method void debit(double amount) which subtracts the given amount from...
The Account class Create a class named Account, which has the following private properties:
in java The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber (), getBalance (), setBalan newBalance). There is no setNumber () once an account is created, its account number cannot change. Now implement these methods: void deposit (double amount) and void withdraw (double amount). For both these methods, if the amount is less than...
The Account class Create a class named Account , which has the following private properties:
 The Account class Create a class named Account , which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNunber(), getBalance(), setBalance (double newBalance) . There is no setNunber() - once an account is created, its account number cannot change. Now implement these methods: void deposit (double anount) and void withdraw(double anount). For both these methods, if the amount is less than zero,...
Challenge: Documents Description: Create a class in Python 3 named Document that has specified attributes and...
Challenge: Documents Description: Create a class in Python 3 named Document that has specified attributes and methods for holding the information for a document and write a program to test the class. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Document that has the following attributes and methods and is saved in the file Document.py. Attributes __title is a...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement deposit(double amount) and withdraw(double amount) methods. If the amount is less than zero,...
The Account class Create a class named Account, which has the following private properties: number: long...
The Account class Create a class named Account, which has the following private properties: number: long balance: double Create a no-argument constructor that sets the number and balance to zero. Create a two-parameter constructor that takes an account number and balance. First, implement getters and setters: getNumber(), getBalance(), setBalance(double newBalance). There is no setNumber() -- once an account is created, its account number cannot change. Now implement these methods: void deposit(double amount) and void withdraw(double amount). For both these methods,...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. this is c sharp program please type the whole program.
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT