我在這裏錯過了一些東西。我的程序在要求輸入他們的服務包後結束。請原諒冗餘代碼,我是一個初學者,並且還沒有學到比這更有效的方法。程序結束時沒有考慮到語句(編碼初學者)
import javax.swing.JOptionPane;
public class InternetSP
{
public static void main(String[] args)
{
final double PACKA = 9.95, PACKB = 13.95, PACKC = 19.95;
final int PACKAC = 2, PACKBC = 1;
double chargecalc, entrycalc = 0;
String entry, pack;
pack = JOptionPane.showInputDialog(null, "Please enter your service" + " package (A,B or C)");
if (pack == "A" || pack == "B")
{
entry = JOptionPane.showInputDialog(null, "Please enter your usage " + "hours.");
entrycalc = Double.parseDouble(entry);
}
if (pack == "A")
{
if (entrycalc > 10)
{
chargecalc = (PACKA + (entrycalc * PACKAC));
JOptionPane.showMessageDialog(null, "Your total charges are: $" + chargecalc);
}
else
{
JOptionPane.showMessageDialog(null, "Your total charge is: $" + PACKA);
}
}
else if (pack == "B")
{
if (entrycalc > 20)
{
chargecalc = (PACKB + (entrycalc * PACKBC));
JOptionPane.showMessageDialog(null, "Your total charges are:" + "$ " + chargecalc);
}
else
{
JOptionPane.showMessageDialog(null, "Your total charge is: $" + PACKB);
}
}
else if (pack == "C")
{
JOptionPane.showMessageDialog(null, "Your total charge is:" + "$ " + PACKC);
}
System.exit(0);
}
}
是什麼讓你覺得他們是「不考慮」?你試圖調試什麼? – geoffspear 2013-02-20 13:28:10
+1爲新,但仍然問一個問題! – Rich 2013-02-20 13:40:47