justuptime.com - monitor your servers & websites

Java Question

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 40 posts

Joined: Jul 2001

Here is a program that I have written. I am trying to rewrite it using encapsulation but am having some problems... any thoughts???

Thanks...

class VolcanoRobot {
String status;
int speed;
float temperature;

void checkTemperature() {
if (temperature > 660) {
status = "returning home";
speed = 5;
}
}

void showAttributes() {
system.out.println("Status: " + status);
system.out.println("Speed: " + speed);
system.out.println("Temperature: " + temperature);
}

public static void main(String[] arguments) {
VolcanoRobot dante = new VolcanoRobot();

dante.status = "exploring";
dante.speed = 2;
dante.temperature = 510;
dante.showAttributes();

System.out.println("Increasing speed to 3.");
dante.speed = 3;
dante.showAttributes();

System.out.println("Changing temperature to 670.");
dante.temperature = 670;
dante.showAttributes();

System.out.println("Checking the temperature.");
dante.checkTemperature();
dante.showAttributes;
}
}

They have: 40 posts

Joined: Jul 2001

nevermind guys - I got it... thanks!