Give an example of class or static members, JAVA Programming

Assignment Help:

Give an example of Class or static Members?

Below is a Car class along with such a speedLimit field and getSpeedLimit() method.
public class Car {

private String licensePlate; // e.g. "New York A456 324"
private double speed; // kilometers per hour
private double maxSpeed; // kilometers per hour
private static double speedLimit = 112.0; // kilometers per hour

public Car(String licensePlate, double maxSpeed) {

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

}

// getter (accessor) methods
public static double getSpeedLimit() {
return speedLimit;
}

public boolean isSpeeding() {
return this.speed > speedLimit;
}

public String getLicensePlate() {
return this.licensePlate;
}

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

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

// setter method for the license plate property
public 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;
}

}

}


Related Discussions:- Give an example of class or static members

What are the different types of bean injections, Two types of bean injectio...

Two types of bean injections are there:- 1. By setter 2. By constructor

Student, short Java application that stores words in an Array or ArrayList....

short Java application that stores words in an Array or ArrayList.

What are the sub categories of ai explain, What are the Sub categories of A...

What are the Sub categories of Artificial Intelligence? Briefly explain any two. 1. Robotics :  These are the machines that are computer programmed and perform work that was pr

What are adding methods, What are adding methods? A subclass isn't rest...

What are adding methods? A subclass isn't restricted to changing the behavior of its superclass. It can also add fully latest techniques and fields that are not shared along wi

I want school management project, I want School Management project Proje...

I want School Management project Project Description: An easy school management project which able to store all data about students like fees structure, admission details and

Illustrate jdbc, JDBC stands for Java Database Connectivity: It is an ...

JDBC stands for Java Database Connectivity: It is an API which gives easy connection to a wide range of databases. To connect to a database we have to load the appropriate dri

Search on column demonstration in semantic vector, Search on column demonst...

Search on column demonstration in Semantic Vector Project Description: I am preparing a research on Semantic Vectors. But I am not able to check out in a vector representa

Create java threads, Create a thread in either a C or a Java program and ru...

Create a thread in either a C or a Java program and run it. The thread should read a keyboard value "x" and exit from the code, or it can also use an "ESC" to exit. That is, the t

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