Objekt: Ovn. hjælp
Hej alle.Jeg har en ovn der har simple formål.
Strømmen skal kunne tændes og slukkes, det samme med varmen og temperaturen skal være mellem 0 og 475 Fahrenheit.
Til sidst i min kode har jeg så lavet et scenarie.
Jeg har dog problemer med alle mine methods, da den melder fejl på samtlige.
Nogle der kan hjælpe mig med at gennemskue problemet og hjælpe mig til at få koden til at virke korrekt?
Med venlig hilsen Michael
public class Oven {
public static void main(String[] args) {
private boolean power;
private boolean heat;
private int temperature;
/**
The getPower method will return the value of the power variable.
With the return command, the current power setting will appear.
*/
public boolean getPower() {
return power;
}
/**
The getHeat method will return the value of the power variable.
With the return command, the current heat setting will appear.
*/
public boolean getHeat() {
return heat;
}
/**
The getTemperature method will return the value of the channel variable.
With the return command, the current temperature setting will appear.
*/
public int getTemperature() {
return temperature;
}
/**
The powerOn() method will turn on the power of the oven.
*/
public void powerOn() {
power=true;
}
/**
The powerOff() method will turn off the oven's power.
*/
public void powerOff() {
power=false;
}
/**
The setPower method will set the power field to the
value stored in the newPower argument.
newPower: The new value for the power.
*/
public void setPower(boolean newPower) {
power = newPower;
}
/**
The heatOn() method will turn on the heat of the oven.
*/
public void heatOn() {
heat=true;
}
/**
The heatOff() method will turn off the heat of the oven.
*/
public void heatOff() {
heat=false;
}
/**
The setHeat method will set the power field to the
value stored in the newHeat argument.
newHeat: The new value for the power.
*/
public void setHeat(boolean newHeat) {
Heat = newHeat;
}
/**
The setTemperature method will set the temperature field to the
value stored in the newTemperature argument.
newTemperature: The new value for the temperature.
*/
public void setTemperature(int newTemperature) {
temperature = newTemperature;
}
/**
The temperatureUp() method will increase the temperature of the oven.
*/
public void temperatureUp() {
temperature++;
}
/**
The temperatureDown() method will decrease the temperature of the oven.
*/
public void temperatureDown() {
temperature--;
}
/**
The printStates() method will display the current state of
the television object on the standard output device.
*/
public void printStates() {
System.out.println("Power: " + power);
System.out.println("Heat: " + heat);
System.out.println("Temperature: " + temperature);
System.out.println();
}
Oven maxentOven = new Oven();
maxentOven.printStates();
//turn on the oven
maxentOven.setPower(true);
//turn on the heat
maxentOven.setHeat(true);
//I will now turn up the heat to 200 Fahrenheit
maxentOven.setTemperature(200);
//now I will print the state
maxentOven.printStates();
//next I turn up the heat to 400 Fahrenheit
maxentOven.setTemperature(400);
// finally I decrease the temperature, turn off the heat and turn off the power
// and print state again
maxentOven.temperatureDown();
maxentOven.heatOff();
maxentOven.powerOff();
maxentOven.printStates();
}
}
