Question

In: Computer Science

Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method...

Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it.

The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and  numberAxels.

Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong.

Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which will reuse their parents constructor and provide additional code for initializing their specific data.

Class Vehicle should have toString method that returns string representation of all vehicle data. Classes Car, Bus, and Truck will override inherited toString method from class vehicle in order to provide apropriate string representation of  all data for their classes which includes inherited data from Vehicle class and their own data.

Class Tester will instantiate 1-2 objects from those four classes (7 total) and it will display the information about those objects by invoking their toString methods.

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 {
   // data members declared as private
   private String make;
   private double weight;
   private double height;
   private double length;
   private int maxSpeed;
   private int noOfDoors;
   private int numberSeats;

   /**
   * @param make
   * @param weight
   * @param height
   * @param length
   * @param maxSpeed
   * @param noOfDoors
   * @param maxPassengers
   * @param numberSeats
   */
   public Vehicle(String make, double weight, double height, double length,
           int maxSpeed, int noOfDoors, int numberSeats) {

       this.make = make;
       this.weight = weight;
       this.height = height;
       this.length = length;
       this.maxSpeed = maxSpeed;
       this.noOfDoors = noOfDoors;
       this.numberSeats = numberSeats;

   }

   /**
   * @return the make
   */
   public String getMake() {
       return make;
   }

   /**
   * @param make
   * the make to set
   */
   public void setMake(String make) {
       this.make = make;
   }

   /**
   * @return the weight
   */
   public double getWeight() {
       return weight;
   }

   /**
   * @param weight
   * the weight to set
   */
   public void setWeight(double weight) {
       this.weight = weight;
   }

   /**
   * @return the height
   */
   public double getHeight() {
       return height;
   }

   /**
   * @param height
   * the height to set
   */
   public void setHeight(double height) {
       this.height = height;
   }

   /**
   * @return the length
   */
   public double getLength() {
       return length;
   }

   /**
   * @param length
   * the length to set
   */
   public void setLength(double length) {
       this.length = length;
   }

   /**
   * @return the maxSpeed
   */
   public int getMaxSpeed() {
       return maxSpeed;
   }

   /**
   * @param maxSpeed
   * the maxSpeed to set
   */
   public void setMaxSpeed(int maxSpeed) {
       this.maxSpeed = maxSpeed;
   }

   /**
   * @return the noOfDoors
   */
   public int getNoOfDoors() {
       return noOfDoors;
   }

   /**
   * @param noOfDoors
   * the noOfDoors to set
   */
   public void setNoOfDoors(int noOfDoors) {
       this.noOfDoors = noOfDoors;
   }

   /**
   * @return the numberSeats
   */
   public int getNumberSeats() {
       return numberSeats;
   }

   /**
   * @param numberSeats
   * the numberSeats to set
   */
   public void setNumberSeats(int numberSeats) {
       this.numberSeats = numberSeats;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Make=" + make + ", weight=" + weight + ", height=" + height
               + ", length=" + length + ", maxSpeed=" + maxSpeed
               + ", noOfDoors=" + noOfDoors + ", Number of Seats ="
               + numberSeats;
   }

}

==========================================

// Car.java

public class Car extends Vehicle {

   private int maxPassengers;

   private boolean isConvertable;

   public Car(String make, double weight, double height, double length,
           int maxSpeed, int noOfDoors, int maxPassengers, int numberSeats,
           boolean isConvertable) {
       super(make, weight, height, length, maxSpeed, noOfDoors, numberSeats);
       this.maxPassengers = maxPassengers;

   }

   /**
   * @return the maxPassengers
   */
   public int getMaxPassengers() {
       return maxPassengers;
   }

   /**
   * @param maxPassengers
   * the maxPassengers to set
   */
   public void setMaxPassengers(int maxPassengers) {
       this.maxPassengers = maxPassengers;
   }

   /**
   * @return the isConvertable
   */
   public boolean isConvertable() {
       return isConvertable;
   }

   /**
   * @param isConvertable
   * the isConvertable to set
   */
   public void setConvertable(boolean isConvertable) {
       this.isConvertable = isConvertable;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Car ::" + super.toString() + ", MaxPassengers=" + maxPassengers
               + ", isConvertable=" + isConvertable;
   }

}

==========================================

// Bus.java

public class Bus extends Vehicle {
   private int numberAxles;

   public Bus(String make, double weight, double height, double length,
           int maxSpeed, int noOfDoors, int numberSeats, int numberAxles) {
       super(make, weight, height, length, maxSpeed, noOfDoors, numberSeats);
       this.numberAxles = numberAxles;
   }

   /**
   * @return the numberAxles
   */
   public int getNumberAxles() {
       return numberAxles;
   }

   /**
   * @param numberAxles
   * the numberAxles to set
   */
   public void setNumberAxles(int numberAxles) {
       this.numberAxles = numberAxles;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Bus ::" + super.toString() + ", Number Axles=" + numberAxles;
   }

}

============================================

// Truck.java

public class Truck extends Vehicle {
   private double maxWeightLoad;

   /**
   * @param make
   * @param weight
   * @param height
   * @param length
   * @param maxSpeed
   * @param noOfDoors
   * @param numberSeats
   * @param maxWeightLoad
   */
   public Truck(String make, double weight, double height, double length,
           int maxSpeed, int noOfDoors, int numberSeats, double maxWeightLoad) {
       super(make, weight, height, length, maxSpeed, noOfDoors, numberSeats);
       this.maxWeightLoad = maxWeightLoad;
   }

   /**
   * @return the maxWeightLoad
   */
   public double getMaxWeightLoad() {
       return maxWeightLoad;
   }

   /**
   * @param maxWeightLoad
   * the maxWeightLoad to set
   */
   public void setMaxWeightLoad(double maxWeightLoad) {
       this.maxWeightLoad = maxWeightLoad;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Truck ::" + super.toString() + ", Max Weight Load="
               + maxWeightLoad;
   }

}

=========================================

// Test.java

import java.util.ArrayList;

public class Test {

   public static void main(String[] args) {
  
       ArrayList<Vehicle> vehicles=new ArrayList<Vehicle>();
       vehicles.add(new Car("Benz", 350, 2, 7, 230, 4, 4, 4, true));
       vehicles.add(new Car("Toyota", 320, 3, 7, 220, 4, 6, 7, false));
       vehicles.add(new Bus("Volvo", 2000, 7, 15, 180,3, 56, 2));
       vehicles.add(new Bus("Benz", 2300, 7, 15, 190, 3, 32, 2));
       vehicles.add(new Truck("Mahindra", 1200, 5, 10, 160, 2, 2, 1000));
       vehicles.add(new Truck("Tata", 1100,5, 10, 170, 2, 2,1200));
       vehicles.add(new Truck("Ashok Leyland", 1100, 5, 10, 160, 2, 2, 1400));
      
       for(int i=0;i<vehicles.size();i++)
       {
           System.out.println(vehicles.get(i));
           System.out.println("-----------------------------------------------------------------------------");
       }
      
      
      
      

   }

}

=======================================

Output:

Car ::Make=Benz, weight=350.0, height=2.0, length=7.0, maxSpeed=230, noOfDoors=4, Number of Seats =4, MaxPassengers=4, isConvertable=false
-----------------------------------------------------------------------------
Car ::Make=Toyota, weight=320.0, height=3.0, length=7.0, maxSpeed=220, noOfDoors=4, Number of Seats =7, MaxPassengers=6, isConvertable=false
-----------------------------------------------------------------------------
Bus ::Make=Volvo, weight=2000.0, height=7.0, length=15.0, maxSpeed=180, noOfDoors=3, Number of Seats =56, Number Axles=2
-----------------------------------------------------------------------------
Bus ::Make=Benz, weight=2300.0, height=7.0, length=15.0, maxSpeed=190, noOfDoors=3, Number of Seats =32, Number Axles=2
-----------------------------------------------------------------------------
Truck ::Make=Mahindra, weight=1200.0, height=5.0, length=10.0, maxSpeed=160, noOfDoors=2, Number of Seats =2, Max Weight Load=1000.0
-----------------------------------------------------------------------------
Truck ::Make=Tata, weight=1100.0, height=5.0, length=10.0, maxSpeed=170, noOfDoors=2, Number of Seats =2, Max Weight Load=1200.0
-----------------------------------------------------------------------------
Truck ::Make=Ashok Leyland, weight=1100.0, height=5.0, length=10.0, maxSpeed=160, noOfDoors=2, Number of Seats =2, Max Weight Load=1400.0
-----------------------------------------------------------------------------


=====================Could you plz rate me well.Thank You


Related Solutions

Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method...
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it. The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels. Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong. Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which...
(JAVA) Create three classes, Vehicle, Truck, and Person. The Vehicle class has a make and model,...
(JAVA) Create three classes, Vehicle, Truck, and Person. The Vehicle class has a make and model, test emissions per mile, and a driver/owner (= Person object). (Each vehicle can only have one driver/owner.) The class Truck is a derived class from the Vehicle class and has additional properties load capacity in tons (type double since it can contain a fractional part) and a towing capacity in pounds (type int). Be sure that your classes have appropriate constructors, accessors, mutators, equals(),...
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class....
In Java, create an abstract vehicle class. Create a Truck Class that Inherits from Vehicle Class. The vehicle class should contain at least 2 variables that could pertain to ANY vehicle and two methods. The truck class should contain 2 variables that only apply to trucks and one method. Create a console program that will instantiate a truck with provided member information then call one method from the truck and one method contained from the inherited vehicle class. Have these...
Design an application with a single class and two static methods: method main and method isLeap....
Design an application with a single class and two static methods: method main and method isLeap. Static method isLeap accepts year as integer and returns boolean value true or false depending whether year is leap or not. public static boolean isLeap ( int year ) The year is leap year if it is divisible by 4, but not divisible by 100 except if it is divisible by 400. Examples 2007 is not a leap year 2008 is leap year 1700...
Write a c++ code: 2.2.1 Vehicle Class The vehicle class is the parent class of a...
Write a c++ code: 2.2.1 Vehicle Class The vehicle class is the parent class of a derived class: locomotive. Their inheritance will be public inheritance so react that appropriately in their .h les. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +setName(s:string):void +getName():string +getMap():char** +getSize():int +setMap(s: string):void +getMapAt(x:int, y:int):char +vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of chars, it will...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the...
Specifications: This project will have two data classes and a tester class. Design: Create a solution...
Specifications: This project will have two data classes and a tester class. Design: Create a solution for this programming task. You will need to have the following parts: Text file to store data between runs. Two classes that implement the given interfaces. You may add methods beyond those in the interfaces A tester class that tests all of the methods of the data classes. Here are the interfaces for your data classes: package project1; import java.util.ArrayList; public interface Person {...
Specifications: This project will have two data classes and a tester class. Design: Create a solution...
Specifications: This project will have two data classes and a tester class. Design: Create a solution for this programming task. You will need to have the following parts: Text file to store data between runs. Two classes that implement the given interfaces. You may add methods beyond those in the interfaces A tester class that tests all of the methods of the data classes. Here are the interfaces for your data classes: package project1; import java.util.ArrayList; public interface Person {...
How can the classes be modified to satisfy the comments & example tester: public class InvalidIntegerException...
How can the classes be modified to satisfy the comments & example tester: public class InvalidIntegerException extends Exception{ // Write a class for an InvalidIntegerException here //Constructor that takes no arguments public InvalidIntegerException (){ super(); } //Constructor that takes a string message public InvalidIntegerException (String message){ super(message); } } import java.io.InputStream; import java.io.IOException; public class Parser { private InputStream in; public static final int CHAR_ZERO = (int) '0'; public Parser (InputStream in) { this.in = in; } // Complete the...
Write a class called Name. A tester program is provided in Codecheck, but there is no...
Write a class called Name. A tester program is provided in Codecheck, but there is no starting code for the Name class. The constructor takes a String parameter representing a person's full name. A name can have multiple words, separated by single spaces. The only non-letter characters in a name will be spaces or -, but not ending with either of them. The class has the following method: • public String getName() Gets the name string. • public int consonants()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT