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

Program execution of boggle game application, In this assignment, you will ...

In this assignment, you will implement the game of Boggle, a word game in which players connect adjacent letters on a 4x4 board to create as many words as possible. This is based o

Servlet pages from being cached by the browser, How do I prevent the output...

How do I prevent the output of my JSP or Servlet pages from being cached by the browser? Ans) You will require to set the appropriate HTTP header attributes to stop the dynamic

Roster entries in chat application, The roster lets you keep track of the a...

The roster lets you keep track of the availability ("presence") of other users. A roster also allows you to organize users into groups such as "Friends" and "Co-workers". Other IM

Card, Create a class called DeckOfCards that stores 52 objects of the Card ...

Create a class called DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a deck, and report the number of cards left in the deck. The s

Jdbc, creating connection which will authenciate for a password

creating connection which will authenciate for a password

How dbms is better to use than flat-file database, How can you justify that...

How can you justify that a DBMS is better to use than Flat-file database? A DBMS takes care of the storage, retrieval, and management of large data sets on a Database. It give

Why http is a stateless protocol ?, The "http protocol" is a stateless resp...

The "http protocol" is a stateless response or request based protocol. You may contain the state information between different page requests as given below: HTTP Sessions are

Intro to Programming, Overall Requirements Every phone number is broken up ...

Overall Requirements Every phone number is broken up into sections as shown below: Country Code Area Code Prefix Line Number 1 919 882 5000 Write a program to separate out a ph

Interface, Interface to calculate carbon foot print

Interface to calculate carbon foot print

Convert string to super ascii, A string S is said to be "Super ASCII", if i...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''''a''''-''''z'''') and

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