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

High quality leads and directory scraping, Project Description: (1) I wa...

Project Description: (1) I want a comprehensive list of Australian chiropractors. The data requires coming from various sources including Google but the following are obligatory

Application to control robot arm , I send you these files in order to make ...

I send you these files in order to make clear image about my task that I want you to design for me an application for PC that used to control robot arm via micro controller PIC18.

Explain java.lang.string library in java, Explain java.lang.string library ...

Explain java.lang.string library in java? Strings are objects. Specifically they're instances of the class java.lang.String . This class has several methods which are useful f

Discuss features of java, Question 1 Discuss features of JAVA Question...

Question 1 Discuss features of JAVA Question 2 What are primitive data types? Discuss Question 3 Explain data conversion function ValueOf ()? Question 4 What are th

How can we include images in a web page using html and java, How can we inc...

How can we include images in a web page using HTML and Java script? Image in HTML Image in Javascript Images in JavaScript could be manipulated in several ways using the buil

I need integrate template to java system, I need integrate template to Java...

I need integrate template to Java system Project Description: We have around 60 files for a java backend and want to implement a template, the system is complete it requires

Differentiate local and global variables, Differentiate Local and Global Va...

Differentiate Local and Global Variables? Local variables are the variables have limited scope although global have bigger scope Local variables are not accessed through others

Eclipse javaj, how to write coding for money and currency

how to write coding for money and currency

I need java expert with tomcat tuning experience, I need Java expert with t...

I need Java expert with tomcat tuning experience Project Description: Require a Java expert to fix memory issues with tomcat. Skills required: Java, Apache

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