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 representtion of all vehicle data. Classes Car, Bus, and Truck will override inherited toString method from class vehicle in order to provide appropriate 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 (at least five total) and it will display the information about those objects by invoking their toString methods.

Solutions

Expert Solution

package com.motor;

public class Vehicle
{
String make = null;
double weight = 0.0d;
double height = 0.0d;
double length = 0.0d;
double maxSpeed = 0.0d;
int numberDoors = 0;
boolean isConvertable = false;
int numberSeats = 0;
int numberAxels = 0;

public Vehicle()
{
System.out.println("Enter Default Constructor for Vehicle Class");
   }

//Vehical Class Parameterized Constructor
public Vehicle(String make, double weight, double height, double length, double maxSpeed, int numberDoors, boolean isConvertable, int numberSeats, int numberAxels)
{
this.make = make;
this.weight = weight;
this.height = height;
this.length = length;
this.maxSpeed = maxSpeed;
this.numberDoors = numberDoors;
this.isConvertable = isConvertable;
this.numberSeats = numberSeats;
this.numberAxels = numberAxels;
}

//Overriding toString() method
public String toString()
{
return "Make-"+make+" Corp. : Weight-"+weight+" Kgs : Height-"+height+" meters : Length-"+length+" meters : MaxSpeed-"+maxSpeed+" KMPH : NumberOfDoors-"+numberDoors+" : IsConvertable-"+isConvertable+" : NumberOfSeats-"+numberSeats+" : NumberOfAxels-"+numberAxels;
}

}

package com.motor;

public class Truck extends Vehicle
{

double maxWeightLoad = 0.0d;
public Truck()
{
System.out.println("Enter Default Constructor for Truck Class");
}

//Truck Class Parameterized Constructor
public Truck(String make, double weight, double height, double length, double maxSpeed, int numberDoors, boolean isConvertable, int numberSeats, int numberAxels, double maxWeightLoad)
{
super(make,weight,height,length,maxSpeed,numberDoors,isConvertable,numberSeats,numberAxels);
this.maxWeightLoad = maxWeightLoad;
System.out.println("This is a Truck");
}

//Overriding toString()
public String toString()
{
String retString = super.toString();
return retString+" : MaxWeightLoad-"+maxWeightLoad+" Tonns";
}
}

package com.motor;

public class Car extends Vehicle
{

int maxPassengers = 0;
public Car()
{
System.out.println("Enter Default Constructor for Car Class");
}

//Car Class Parameterized Constructor
public Car(String make, double weight, double height, double length, double maxSpeed, int numberDoors, boolean isConvertable, int numberSeats, int numberAxels, int maxPassengers)
{
super(make,weight,height,length,maxSpeed,numberDoors,isConvertable,numberSeats,numberAxels);
this.maxPassengers = maxPassengers;
System.out.println("This is a Car");
}

//Overriding toString()
public String toString()
{
String retString = super.toString();
return retString+" : MaxPassengers-"+maxPassengers;
}
}

package com.motor;

public class Bus extends Vehicle
{

int maxPassengers = 0;
public Bus()
{
System.out.println("Enter Default Constructor for Bus Class");
}

//Bus Class Parameterized Constructor
public Bus(String make, double weight, double height, double length, double maxSpeed, int numberDoors, boolean isConvertable, int numberSeats, int numberAxels, int maxPassengers)
{
super(make,weight,height,length,maxSpeed,numberDoors,isConvertable,numberSeats,numberAxels);
this.maxPassengers = maxPassengers;
System.out.println("This is a Bus");
}

//Overriding toString()
public String toString()
{
String retString = super.toString();
return retString+" : MaxPassengers-"+maxPassengers;
}

}

package com.motor;

public class Testor
{
public Testor()
{
System.out.println("Enter Default Constructor for Testor Class");
}
public static void main(String[] args)
{
Vehicle vehicle1 = new Car("Mercedez AMG Benz",950,2.5,4,220.3,4,false,4,2,4);
System.out.println(vehicle1.toString());
Vehicle vehicle2 = new Bus("Tata Marcopolo",2050,2.1,7,100.4,3,true,72,3,72);
System.out.println(vehicle2.toString());
Vehicle vehicle3 = new Truck("Ashok Layland",1980,2.2,9.8,80.7,3,false,4,3,72);
System.out.println(vehicle3.toString());
}
}


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 will...
(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