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

Create a general design for a class-implement and test, Objectives 1.  ...

Objectives 1.      To design and implement a simple class. 2.      To write a test program to create instances of your class and demonstrate its behaviour. 3.      To col

Java and Arrays, AskWrite an application that uses an Array to store 10mess...

AskWrite an application that uses an Array to store 10messages of type String. You will store this Array with 10 messages of your choosing. For example, a message could be “I love

Need java assignment for course, Need Java Assignment for course Project...

Need Java Assignment for course Project Description: I want to get an assignment done. Involves building on a minesweeper game written in Java. You subsequent code is to be u

Describe member variables vs. local variables, Describe Member Variables vs...

Describe Member Variables vs. Local Variables ? class Car { String licensePlate = ""; // member variable double speed; = 0.0; // member variable double maxSp

Development of an android app urgent, Development of an Android app urgent ...

Development of an Android app urgent Project Description: I am searching for some good android developer who has depth in knowledge of making an app. I am focusing on a certa

Simple sudoku implementation, SudCell and Simple Sudoku Implementation ...

SudCell and Simple Sudoku Implementation We describe, fully, the SudCell class that will represent each of the 81 cells or boxes in a Sudoku puzzle.  Then we will

Explain about the dynamic behavior of core java, This language was designed...

This language was designed to adapt the changing environment and behavior. New methods and instance variables can be added to the client side without any major changes happening at

Cryptoarithmatic, Create problem that solves cryptoarithmatic problem that ...

Create problem that solves cryptoarithmatic problem that uses from user using java

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