01-03-2013, 07:19 PM
Copy these to codes into different eclipse classes
[code2=java]public class carPetrol
{
int tPetrol = 0;
public carPetrol(){
}
public carPetrol(int petrolAmount){
tPetrol = petrolAmount;
}
public void fillTank(int amount){
tPetrol = tPetrol + amount;
}
public void drive(int amount){
tPetrol = tPetrol - amount;
}
public int meterReading(){
return tPetrol;
}
}[/code2]
You will need to run the second program for this to work.
[code2=java]public class carPetrolTest {
public static void main(String[] args){
carPetrol petrolTank = new carPetrol(0);
petrolTank.fillTank(100);
petrolTank.drive(20);
System.out.println(petrolTank.meterReading() + " litres of gas remaining");
}
}[/code2]
[code2=java]public class carPetrol
{
int tPetrol = 0;
public carPetrol(){
}
public carPetrol(int petrolAmount){
tPetrol = petrolAmount;
}
public void fillTank(int amount){
tPetrol = tPetrol + amount;
}
public void drive(int amount){
tPetrol = tPetrol - amount;
}
public int meterReading(){
return tPetrol;
}
}[/code2]
You will need to run the second program for this to work.
[code2=java]public class carPetrolTest {
public static void main(String[] args){
carPetrol petrolTank = new carPetrol(0);
petrolTank.fillTank(100);
petrolTank.drive(20);
System.out.println(petrolTank.meterReading() + " litres of gas remaining");
}
}[/code2]