Class 1, Part 2 | Intro to Java 30-IT-396 |
Cars Example
/*
* Car.java
*
* Created on January 30, 2002, 12:44 PM
*/
/**
*
* @author default
*/
public class Car {
private int gallonsOfGas;
private int location;
private int maxGallonsOfGas;
/** Creates a new instance of Car */
public Car() {
gallonsOfGas = 0;
location = 0;
maxGallonsOfGas = 10;
}
public void setGallonsOfGas(int gallons) {
if (gallonsOfGas + gallons
> maxGallonsOfGas) {
gallonsOfGas = maxGallonsOfGas;
} else if (gallonsOfGas
+ gallons < 0) {
gallonsOfGas = 0;
} else {
gallonsOfGas += gallonsOfGas;
}
}
public void setLocation (int location) {
location += location;
gallonsOfGas -= (location
/ 10);
}
public int getGallonsOfGas() {
return gallonsOfGas;
}
public int getLocation() {
return location;
}
}
Created by: Brandan
Jones January 4, 2002