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

Decision structures, for $9.95 per month, 10 hours of access are provided.A...

for $9.95 per month, 10 hours of access are provided.Additional hours are $2.00 per hour

Java rmi client implement and web service client-side steps, What is the na...

What is the name of the services you have chosen? What do they do? What is the name of the publisher? Provide details if you are developing your own service(s). There are variou

Write a program of else statement in java, Write a program of else statemen...

Write a program of else statement in java? The else statement in Java // This is the Hello program in Java class Hello { public static void main (String args[]) { if (

How to draw polygons in java, How to draw Polygons in java? In Java rec...

How to draw Polygons in java? In Java rectangles are defined through the position of their upper left hand corner, their height, and their width. Therefore it is implicitly sup

Method over ridding method in java, Q. Write short on the method over riddi...

Q. Write short on the method over ridding method in java? Ans. Method over ridding and dynamic binding: We have seen that a method in a super class is inherited by its subclass

Array, public class Tester { static void test(int[] a) { int[] b = new in...

public class Tester { static void test(int[] a) { int[] b = new int[2]; a = b; System.out.print(b.length); System.out.print(a.length); } public static void main(String[] arg

Define the life cycle methods of a servlet? , The Web container is used for...

The Web container is used for managing the servlet's life cycle. The Web container produces an instance of the servlet and then the container invokes the init() function. At the co

Execution process of java bytecode, Execution Process of Java bytecode ...

Execution Process of Java bytecode JVM are available for almost every operating system. Java bytecode is executed by employing any operating system's JVM. Hence achieve port

Concurrent Programming, Problem 1 A savings account object holds a non-nega...

Problem 1 A savings account object holds a non-negative balance, and provides deposit(k ) and withdraw(k ) methods, where deposit(k ) adds k to the balance, and withdraw(k ) subtra

The tic-tac-toe program, Instructions Modify the program so that the co...

Instructions Modify the program so that the computer will generate moves for the ‘O' player (it must continue to accept user input for ‘X'). A simple way to do this is to use a

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