我擁有一切工作,但System.exit(0)
。如果按下按鈕,它應該退出任何剩餘時間。我不知道該怎麼做。幫助將不勝感激。無法獲取System.exit()在dragon12項目中工作
/*
Creates the perfect hard-boiled(simulates 12 minutes in boiling water) or soft-boiled
egg(simulates 6 minutes in boiling water). Both options require 10 seconds of rinsing
under cold water after necessary time for boiling. Allow user to exit any remaining
time.
*/
import java.io.*;
import java.util.*;
public class AdvancedEggMaker {
public static void main(String[] args) {
MCU mcu = null;
try {
mcu = new MCU(new Communicator(args[0]));
}
catch (IOException e) {
System.out.println(e);
}
mcu.println("SW2 - HB Egg", 0);
mcu.println("SW3 - SB Egg", 1);
while (true) {
int sw = mcu.getSwitch();
if (sw == 2) {
mcu.println("Hard Boiled Egg", 0);
mcu.println("Place Egg in", 0);
mcu.println("boiling water", 1);
mcu.println("then press SW4", 0);
mcu.println("SW5 - Quit", 1);
int sw2 = mcu.getSwitch();
switch (sw2) {
case 4:
int t = 720;
while (t > 0 && sw2 == 4) {
t = (t - 1);
mcu.println("Boiling...", 0);
mcu.println((t/60) + "mins left...", 1);
}
break;
case 5:
System.exit(0);
break;
}
}
if (sw == 3) {
mcu.println("Soft Boiled Egg", 0);
mcu.println("Place Egg in", 0);
mcu.println("boiling water", 1);
mcu.println("then press SW4", 0);
mcu.println("SW5 - Quit", 1);
int sw2 = mcu.getSwitch();
switch (sw2) {
case 4:
int t = 360;
while (t > 0 && sw2 == 4) {
t = (t - 1);
mcu.println("Boiling...", 0);
mcu.println((t/60) + "mins left...", 1);
}
break;
case 5:
System.exit(0);
break;
}
}
mcu.println("Rinse Egg", 0);
mcu.println("then press SW4", 0);
mcu.println("SW5 - Quit", 1);
int sw3 = mcu.getSwitch();
if (sw3 == 4) {
double t = 10;
while (t > 0.0) {
t = (t - 1);
mcu.println("Rinsing...", 0);
mcu.println(t + "Secs left...", 1);
}
if (sw == 5) {
System.exit(0);
}
}
}
}
}
什麼是MCU類的代碼? – 2013-05-04 14:22:31
你誤解了'switch'的用法。 – Maroun 2013-05-04 14:24:09
檢查您是否有輸入號碼5,並繼續執行第5種情況。 – 2013-05-04 14:38:24