我正在尝试为我的计算机科学课程的家庭作业制作菜单。我以为我把一切都搞砸了,但我不断收到我似乎无法修复的错误。另外我最多只能使用 Java 1.4.2,所以我不能使用 Scanner。这是代码:
更新代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class JavaBurger
{
static ArrayList MenuItems = new ArrayList();
public static void main(String[] args)
{
InputStreamReader inp = null;
BufferedReader input = null;
int nOption = 0;
double price = 0;
double amount;
double amount1 = 0;
double amount2 = 0;
double amount3 = 0;
double amount4 = 0;
double amount5 = 0;
double amount6 = 0;
double amount7 = 0;
double amount8 = 0;
double amount9 = 0;
double amount10 = 0;
amount = (amount1 + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10);
try
{
inp = new InputStreamReader(System.in);
input = new BufferedReader(inp);
while(true)
{
System.out.println("Choose a Menu Option");
System.out.println("1. Burger - 13.49");
System.out.println("2. Pasta - 16.79");
System.out.println("3. Salad - 13.49");
System.out.println("4. Salmon - 18.99");
System.out.println("5. Chicken - 16.99");
System.out.println("6. Nachos - 13.99");
System.out.println("7. Soup - 6.99");
System.out.println("8. Fajitas - 18.49");
System.out.println("9. Ribs - 23.99");
System.out.println("10. Calamari-9.99");
System.out.println("\nChoose an option(1-10) >> ");
System.out.println("Subtotal: $" + amount);
System.out.println("Total: $" + (amount * 1.13));
nOption = Integer.parseInt(input.readLine());
switch(nOption)
{
case 1:
Burger(input);
break;
case 2:
Pasta(input);
break;
case 3:
Salad(input);
break;
case 4:
Salmon(input);
break;
case 5:
Chicken(input);
break;
case 6:
Nachos(input);
break;
case 7:
Soup(input);
break;
case 8:
Fajitas(input);
break;
case 9:
Ribs(input);
break;
case 10:
Calamari(input);
break;
}
}
}
catch(Exception exp)
{
}
}
public static void Burger(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many Burgers would you like? ");
int a = Integer.parseInt(input.readLine());
int aa = a.nextInt();
double aaa = Math.pow(1 + a, aa);
amount1 = (aaa * 13.49);
break;
}
}
public static void Pasta(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of Pasta would you like? ");
int b = Integer.parseInt(input.readLine());
int bb = b.nextInt();
double bbb = Math.pow(1 + b, bb);
amount2 = (bbb * 16.79);
break;
}
} public static void Salad(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many Salads would you like? ");
int c = Integer.parseInt(input.readLine());
int cc = c.nextInt();
double ccc = Math.pow(1 + c, cc);
amount3 = (ccc * 13.49);
break;
}
} public static void Salmon(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of Salmon would you like? ");
int d = Integer.parseInt(input.readLine());
int dd = d.nextInt();
double ddd = Math.pow(1 + d, dd);
amount4 = (ddd * 18.99);
break;
}
} public static void Chicken(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of Chicken would you like? ");
int e = Integer.parseInt(input.readLine());
int ee = e.nextInt();
double eee = Math.pow(1 + e, ee);
amount5 = (eee * 16.99);
break;
}
} public static void Nachos(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of Nachos would you like? ");
int f = Integer.parseInt(input.readLine());
int ff = f.nextInt();
double fff = Math.pow(1 + f, ff);
amount6 = (fff * 13.99);
break;
}
} public static void Soup(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of Soup would you like? ");
int g = Integer.parseInt(input.readLine());
int gg = g.nextInt();
double ggg = Math.pow(1 + g, gg);
amount7 = (ggg * 6.99);
break;
}
} public static void Fajitas(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of 2 Fajitas would you like? ");
int h = Integer.parseInt(input.readLine());
int hh = h.nextInt();
double hhh = Math.pow(1 + h, hh);
amount8 = (hhh * 18.49);
break;
}
} public static void Ribs(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many racks of Ribs would you like? ");
int i = Integer.parseInt(input.readLine());
int ii = i.nextInt();
double iii = Math.pow(1 + i, ii);
amount9 = (iii * 23.99);
break;
}
} public static void Calamari(BufferedReader input) throws IOException
{
while(true)
{
System.out.println("How many orders of Calamari would you like? ");
int j = Integer.parseInt(input.readLine());
int jj = j.nextInt();
double jjj = Math.pow(1 + j, jj);
amount10 = (jjj * 9.99);
break;
}
}
}
更新错误:
C:\Java\bin>javac JavaBurger.java
JavaBurger.java:98: error: int cannot be dereferenced
int aa = a.nextInt();
^
JavaBurger.java:100: error: cannot find symbol
amount1 = (aaa * 13.49);
^
symbol: variable amount1
location: class JavaBurger
JavaBurger.java:114: error: int cannot be dereferenced
int bb = b.nextInt();
^
JavaBurger.java:116: error: cannot find symbol
amount2 = (bbb * 16.79);
^
symbol: variable amount2
location: class JavaBurger
JavaBurger.java:128: error: int cannot be dereferenced
int cc = c.nextInt();
^
JavaBurger.java:130: error: cannot find symbol
amount3 = (ccc * 13.49);
^
symbol: variable amount3
location: class JavaBurger
JavaBurger.java:143: error: int cannot be dereferenced
int dd = d.nextInt();
^
JavaBurger.java:145: error: cannot find symbol
amount4 = (ddd * 18.99);
^
symbol: variable amount4
location: class JavaBurger
JavaBurger.java:158: error: int cannot be dereferenced
int ee = e.nextInt();
^
JavaBurger.java:160: error: cannot find symbol
amount5 = (eee * 16.99);
^
symbol: variable amount5
location: class JavaBurger
JavaBurger.java:173: error: int cannot be dereferenced
int ff = f.nextInt();
^
JavaBurger.java:175: error: cannot find symbol
amount6 = (fff * 13.99);
^
symbol: variable amount6
location: class JavaBurger
JavaBurger.java:187: error: int cannot be dereferenced
int gg = g.nextInt();
^
JavaBurger.java:189: error: cannot find symbol
amount7 = (ggg * 6.99);
^
symbol: variable amount7
location: class JavaBurger
JavaBurger.java:202: error: int cannot be dereferenced
int hh = h.nextInt();
^
JavaBurger.java:204: error: cannot find symbol
amount8 = (hhh * 18.49);
^
symbol: variable amount8
location: class JavaBurger
JavaBurger.java:217: error: int cannot be dereferenced
int ii = i.nextInt();
^
JavaBurger.java:219: error: cannot find symbol
amount9 = (iii * 23.99);
^
symbol: variable amount9
location: class JavaBurger
JavaBurger.java:232: error: int cannot be dereferenced
int jj = j.nextInt();
^
JavaBurger.java:234: error: cannot find symbol
amount10 = (jjj * 9.99);
^
symbol: variable amount10
location: class JavaBurger
20 errors