我在这里遗漏了一些东西。我的程序在要求此人输入他们的服务包后结束。请原谅多余的代码,我是这方面的初学者,还没有学到比这更有效的方法。
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);
}
}