How we can changing the implementation, JAVA Programming

Assignment Help:

How we can changing the Implementation ?

Suppose the Car class requires to be used in a simulation of New York City traffic in that each actual car on the street is represented through one Car object. That's a lot of cars. As currently written every car object occupies around 60 bytes of memory (depending mostly on the size of the license plate string. We can knock off eight bytes per car through using floats instead of doubles, but the interface can stay the similar:

public class Car {

private String licensePlate; // e.g. "New York A456 324"
private float speed; // kilometers per hour
private float maxSpeed; // kilometers per hour

public Car(String licensePlate, double maxSpeed) {

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

}

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

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

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

// 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 + (float) deltaV;
if (this.speed > this.maxSpeed) {
this.speed = this.maxSpeed;
}
if (this.speed < 0.0) {
this.speed = 0.0F;
}
}
}
Since the interface is the similar, no other classes in which depend on this class requires to change or even be recompiled. We might save even more through using a custom LicensePlate class in which only permits one-byte ASCII characters instead of two byte Unicode characters.


Related Discussions:- How we can changing the implementation

Explain about the dynamic java, Dynamic JAVA Class and type informatio...

Dynamic JAVA Class and type information is kept around at runtime. This allows runtime loading and inspection of code in a very flexible way.

Give an example for using getter methods, Give an example for Using Getter ...

Give an example for Using Getter Methods ? class CarTest6 { public static void main(String args[]) { Car c = new Car(); c.setLicensePlate("New York A45 636"); c.setMa

Password Generator Software, In this exercise, I want you to generate passw...

In this exercise, I want you to generate password based on random number generator. Develop an application that keeps track of the URL, username and password. I have listed few st

Data structures and algorithm, Create a class to implement the ArrayList co...

Create a class to implement the ArrayList collection. The name should be YourFirstNameArrayList; for example if I were creating the class then I would call it WaynesArrayList. Do

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

What are the non-final functions in java object class?, The non-final funct...

The non-final functions are clone (), finalize (), toString (), equals () , hashCode () and. The other methods like wait (), getClass (), notifyAll (), notify () etc are final

Determine the phase loading- java program development, Determine the phase ...

Determine the phase Loading- Java Program Development In phase 3, the program must first be placed in memory before it can be executed. This is done by the class loader, whic

Explain about the interpreter in java, Machines should have Java interprete...

Machines should have Java interpreter for the Java byte code to get implemented. Linking is a very simple process and this feature helps while developing applications. Java compile

Define cross-cutting functionality , An aspect is the cross-cutting functio...

An aspect is the cross-cutting functionality that you are executing. It is the aspect of your application you are modularizing. An example of an aspect is logging. Logging is somet

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