明明在包里面有类,怎么显示这个问题.

hb2005 2005-03-08 09:34:32
错误提示:
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");
}

}
...全文
83 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hb2005 2005-03-09
  • 打赏
  • 举报
回复
是的.前面已经初始化类了.可是到了后面就不行了.不知道为什么?
funcreal 2005-03-09
  • 打赏
  • 举报
回复
dsuj.ch01.candyMachine.Dispenser
please remove or make sure it appears in the correct subdirectory of the classpath
这个类是按照它的包所指明的路径存放的吗?
jackkui 2005-03-08
  • 打赏
  • 举报
回复

是不是你的classpath设置的有问题,里面设置上“.;”,这个表示在当前目录下面寻找
hedonister 2005-03-08
  • 打赏
  • 举报
回复
ding

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧