明明在包里面有类,怎么显示这个问题.
错误提示:
CandyMachine.java :52 cannot access Dispenser bad class file:.\Dispenser.class
class file contains wrong class : dsuj.ch01.candyMachine.Dispenser
please remove or make sure it appears in the correct subdirectory of the classpath
public static void sellProduct(Dispenser product,CashRegister cRegister) throws IOException
我在前面已经引用了类了,代码如下:
import java.io.*;
import dsuj.ch01.candyMachine.*;
public class CandyMachine
{
static BufferedReader keyboard = new BufferedReader(new InputStreamreader(System.in));
public static void main(String[] args)throws IOException
{
CashRegister cashRegister = new CashRegister();
Dispenser candy = new Dispenser(100,50);
Dispenser chips = new Dispenser(100,65);
Dispenser gum = new Dispenser(75,45);
Dispenser cookies = new Dispenser(100,85);
int choice;
showSelection();
choice = Integer.parseInt(Keyboard.readLine());
while(choice != 9)
{
switch(choice)
{
case 1:sellProduct(candy,cashRegister);
break;
case 2:sellProduct(chips,cashRegister);
break;
case 3:sellProduct(gum,cashRegister);
break;
case 4:sellProduct(cookies,cashRegister);
break;
default : System.out.println("Invalid Selection");
}
showSelection();
choice = Integer.parseInt(Keyboard.readLine());
}
}
public static void showSelection()
{
System.out.println("*** Welcome to Shelly's Candy Shop ***");
System.out.println("To select an item,enter");
System.out.println("1 for Candy");
System.out.println("2 for chips");
System.out.println("3 for Gum");
System.out.println("4 for Cookies");
System.out.println("9 to exit");
}
public static void sellProduct(Dispenser product,CashRegister cRegister)throws IOException
{
int amount;
int amount2;
if(product.getCount()>0)
{
System.out.println("please deposit"+product.getProductCost()+"cents");
amount = Integer.parseInt(keyboard.readLine());
if(amount<product.getProductCost())
{
System.out.println("please deposit another"+(product.getProductCost()-amount)+"cents");
amount2 = Integer.parseInt(keyboard.readLine());
amount = amount + amount2;
}
if(amount >= product.getProductCost())
{
cRegister.acceptAmount(amount);
product.makeSale();
System.out.println("Collect your item at the bottom and enjoy");
}
else
System.out.println("The amount is not enough.Collect what you deposited");
System.out.println("*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_");
}
else
System.out.println("sorry this item is sold out");
}
}