Java Question
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;
}
}
Hundley posted this at 20:45 — 8th January 2002.
They have: 40 posts
Joined: Jul 2001
nevermind guys - I got it... thanks!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.