Describe the superclass in inheritance, JAVA Programming

Assignment Help:

Describe the Superclass in Inheritance ?

In this example you start through defining a more common MotorVehicle class.
public class MotorVehicle {

private String licensePlate; // e.g. "New York A456 324"
private double speed; // kilometers per hour
private double maxSpeed; // kilometers per hour
private String make; // e.g. "Harley-Davidson", "Ford"
private String model; // e.g. "Fatboy", "Taurus"
private int year; // e.g. 1998, 1999, 2000, 2001, etc.
private int numberPassengers; // e.g. 4

// constructors
public MotorVehicle(String licensePlate, double maxSpeed,
String make, String model, int year, int numberOfPassengers) {
this(licensePlate, 0.0, maxSpeed, make, model, year, numberOfPassengers);
}

public MotorVehicle(String licensePlate, double speed, double maxSpeed,
String make, String model, int year, int numberOfPassengers) {

// I could add some more constraints like the
// number of doors being positive but I won't
// so that this example doesn't get too big.
this.licensePlate = licensePlate;
this.make = make;
this.model = model;
this.year = year;
this.numberPassengers = numberOfPassengers;

if (maxSpeed >= 0.0) {
this.maxSpeed = maxSpeed;
}
else {
maxSpeed = 0.0;
}

if (speed < 0.0) {
speed = 0.0;
}

if (speed <= maxSpeed) {
this.speed = speed;
}
else {
this.speed = maxSpeed;
}

}


// getter (accessor) methods
public String getLicensePlate() {
return this.licensePlate;
}

public String getMake() {
return this.make;
}

public String getModel() {
return this.model;
}

public int getYear() {
return this.year;
}

public int getNumberOfPassengers() {
return this.numberPassengers;
}

public int getNumberOfPassengers() {
return this.numberWheels;
}

public double getMaxSpeed() {
return this.maxSpeed;
}

public double getSpeed() {
return this.speed;
}

// setter method for the license plate property
protected void setLicensePlate(String licensePlate) {
this.licensePlate = licensePlate;
}

// accelerate to maximum speed
// put the pedal to the metal
public void floorIt() {
this.speed = this.maxSpeed;
}

public void accelerate(double deltaV) {

this.speed = this.speed + deltaV;
if (this.speed > this.maxSpeed) {
this.speed = this.maxSpeed;
}
if (this.speed < 0.0) {
this.speed = 0.0;
}
}
}
The MotorVehicle class has all the features shared through motorcycles and cars, but it leaves the number of wheels unspecified, and it doesn't have a numberDoors field since not all motor vehicles have doors. It also forms the fields and the setLicensePlate() method protected on the other hands of private and public. 


Related Discussions:- Describe the superclass in inheritance

Code, pebble merchant

pebble merchant

Saaa, Write a program to find the area under the curve y = f(x) between x =...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

I want fitlife app for android - ios, I want FitLIFE app for Android, IOS, ...

I want FitLIFE app for Android, IOS, Windows Project Description: Hello, I want to develop an app for Android, IOS and Windows Phone. This app will be work with open source B

Classifieds android app from my word press classifieds, Classifieds Android...

Classifieds Android app from my Word press Classifieds website with Google gps/ map augmented reality for ads Project Description: 1. Prepare an Android Classifieds app for m

Explain the uses of JVM verifier, Explain the uses of JVM verifier The ...

Explain the uses of JVM verifier The JVM "verifier" checks the code when it's loaded to verify that it has the correct structure --that it does not use an uninitialized pointer

Video course on computer security needed, Video course on computer security...

Video course on computer security needed Project Description: We want a video course on computer security. Just like the way lynda provides. Skills required are Computer S

Image caching with html, In the airplane program, you may have noticed that...

In the airplane program, you may have noticed that the loading of each image appears to be jerky, erratic, or slow, and that the URL for each image flickers in the status bar each

Answer, a program to find the area under curve y=f(x) between x=a and x=b,i...

a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits of a and b

Difference between while statement and a do while statement, What is the di...

What is the difference between a while statement and a do while statement? A while statement checks at the starting of a loop to see whether the next loop iteration should occu

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd