Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicycle, ant the other encapsulating a motorized vehicle. A motorized vehicle has the following additional attributes: its engine volume displacement, in liters; and a method computing and returning a measure of horsepower which is the number of liters times the number of wheels. You also need to include a client class to test these two classes.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// Vehicle.java
public abstract class Vehicle {
private String ownerName;
private int noOfWheels;
public Vehicle(String ownerName, int noOfWheels)
{
this.ownerName = ownerName;
this.noOfWheels = noOfWheels;
}
public String getOwnerName() {
return ownerName;
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
public int getNoOfWheels() {
return noOfWheels;
}
public void setNoOfWheels(int noOfWheels) {
this.noOfWheels = noOfWheels;
}
}
______________________
// Bicycle.java
public class Bicycle extends Vehicle {
public Bicycle(String ownerName, int noOfWheels)
{
super(ownerName, noOfWheels);
}
}
_______________________
// MotorVehicle.java
public class MotorVehicle extends Vehicle {
private int engineVolume;
public MotorVehicle(String ownerName, int
noOfWheels, int engineVol) {
super(ownerName, noOfWheels);
this.engineVolume = engineVol;
}
public int getEngineVolume() {
return engineVolume;
}
public void setEngineVolume(int engineVolume)
{
this.engineVolume =
engineVolume;
}
public double horsePower()
{
return
getNoOfWheels()*engineVolume;
}
}
___________________________
// Test.java
public class Test {
public static void main(String[] args) {
Bicycle b=new Bicycle("Kane Williams",2);
MotorVehicle m=new MotorVehicle("James",4,25);
System.out.println("Bicycle Info :");
System.out.println("Owners name:"+b.getOwnerName());
System.out.println("No of Wheels:"+b.getNoOfWheels());
System.out.println("\nMotorVehicle Info :");
System.out.print("Owners name:"+m.getOwnerName());
System.out.println("No of Wheels:"+m.getNoOfWheels());
System.out.println("Engine Volume
Displacement:"+m.getEngineVolume());
System.out.println("Horse Power:"+m.horsePower());
}
}
_______________________________
Output:
Bicycle Info :
Owners name:Kane Williams
No of Wheels:2
MotorVehicle Info :
Owners name:JamesNo of Wheels:4
Engine Volume Displacement:25
Horse Power:100.0
_______________Could you plz rate me well.Thank
You
Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicyc...
Write an abstract superclass encapsulating a vehicle: A vehicle has two attributes: its owner's name and its number of wheels. This class has two non-abstract subclasses: one encapsulating a bicycle, and the other encapsulating a motorized vehicle. A motorized vehicle has the following additional attributes: its engine volume displacement, in liters; and a method computing and returning a measure of horsepower which is the number of liters times the number of wheels. Write an application class utilizing these two classes.
(JAVA) Write an abstract superclass encapsulating a college applicant: A college applicant has two attributes: the applicant’s name and the college the applicant is applying to. This class has two non-abstract subclasses: one encapsulating an applicant for undergraduate school, and the other encapsulating an applicant for graduate school. An applicant for undergraduate school has two attributes: a SAT score and a GPA. An applicant for graduate school has one additional attribute:...
Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...
1. Design and implement classes. Design a class named Account and its two subclasses named Checking and Saving. Make Flexible and NotFlexbile subclasses of Saving. An account has a name, address, phone number, and balance. A checking account has a overdraft limit. A saving account has an interest rate. A flexible saving account has the accumulated interest rate. A none flexible account has the expected accumulated interest rate at the maturity of the account. Override the toString method in each...
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...