关于package包的问题,请高手指教
然后定义Item类和Storefront类放在包中代码如下:
Item类:
package comm.perfect.ecommerce;
import java.util.*;
public class Item implements Comparable{
private String id;
private String name;
private double retail;
private int quantity;
private double price;
Item(String idIn,String nameIn,String retailIn,String quanIn)
{
id=idIn;
name=nameIn;
retail=Double.parseDouble(retailIn);
quantity=Integer.parseInt(quanIn);
if(quantity>400)
{
price=retail*.5D;
}
else if(quantity>200)
{
price=retail*.6D;
}
else
{
price=retail*.7D;
}
price=Math.floor(price*100+.5)/100;
}
public int compareTo(Object obj)
{
Item temp=(Item)obj;
if(this.price<temp.price)
{
return 1;
}
else if(this.price>temp.price)
{
return -1;
}
return 0;
}
public String getId()
{
return id;
}
public String getName()
{
return name;
}
public double getRetail()
{
return retail;
}
public int getQuantity()
{
return quantity;
}
public double getPrice()
{
return price;
}
}
Storefront类 :
package comm.perfect.ecommerce;
import java.util.*;
public class Storefront{
private LinkedList catalog=new LinkedList();
public void addItem(String id,String name,String price,String quant)
{
Item it=new Item(id,name,price,quant);
catalog.add(it);
}
public Item getItem(int i)
{
return (Item)catalog.get(i);
}
public int getSize()
{
return catalog.size();
}
public void sort()
{
Collections.sort(catalog);
}
}
编译后生成的两个类文件Item.class和Storefront.class被存放在
G:\JAVA\Package\comm\perfect\ecommerce目录下。
我将classpath设为.;E:\j2sdk14\lib\tools.jar;G:\JAVA\Package,使其指向package包目录。然后创建一个类文件调用到包中的两个类文件,如下
import comm.perfect.ecommerce.*;
public class GiftShop{
public static void main(String[] arguments){
Storefront store=new Storefront();
store.addItem("c01","fmug","19.99","350");
store.addItem("c02","dmug","29.99","250");
store.addItem("c03","smug","39.99","15");
store.addItem("c04","msug","49.99","10");
store.addItem("c05","amug","59.99","50");
store.sort();
for(int i=0;i<store.getSize();i++)
{
Item show=(Item)store.getItem(i);
System.out.println("\nItem ID:"+show.getId()+
"\nName:"+show.getName()+
"\nRetail Price:$"+show.getRetail()+
"\nPrice:$"+show.getPrice()+
"\nQuantity:"+show.getQuantity());
}
}
}
但是编译时总是提示:
--------------------Configuration: j2sdk14 <Default>--------------------
G:\JAVA\GiftShop\GiftShop.java:1: package comm.perfect.ecommerce does not exist
import comm.perfect.ecommerce.*;
^
G:\JAVA\GiftShop\GiftShop.java:5: cannot resolve symbol
symbol : class Storefront
location: class GiftShop
Storefront store=new Storefront();
^
G:\JAVA\GiftShop\GiftShop.java:5: cannot resolve symbol
symbol : class Storefront
location: class GiftShop
Storefront store=new Storefront();
^
G:\JAVA\GiftShop\GiftShop.java:15: cannot resolve symbol
symbol : class Item
location: class GiftShop
Item show=(Item)store.getItem(i);
^
G:\JAVA\GiftShop\GiftShop.java:15: cannot resolve symbol
symbol : class Item
location: class GiftShop
Item show=(Item)store.getItem(i);
^
5 errors
Process completed.
相关推荐
CityTaxi:主要目标是设计一个 Android 应用程序,用于将乘客与最近的出租车司机进行匹配。 该应用程序的设计将考虑到三个演员
概述: 本用户手册解释了如何使用 CityTaxi 以及它是如何开发的。 抽象的: The main goal was to design an Android Mobile Application that will be used to match prospective passengers with nearest taxi driver. The app will be designed with THREE actors in mind: Prospective Passenger, Taxi driver, and Administrator. The GPS sensor in the phone will be used to determine Prospective Passenger's location, and an algorithm will b
正交拉丁超立方(OLHC)分组与实验设计(DOE)评估的优化Python实现.rar
正交拉丁超立方(OLHC)分组与实验设计(DOE)评估的优化Python实现.rar
Java微服务如何拆解审计日志查询服务
标题:Java微服务如何拆解审计日志查询服务 内容概要:围绕缓存策略、任务调度、回压控制和审计追踪,拆解Java微服务如何拆解审计日志查询服务的实现细节。 xdronline.com xdrea.com 9g.xinmei6.com xinghaohuanbao.com m.xiker66.com
港股十档行情tick数据涵盖逐笔成交与委托,记录每笔买卖价格、成交量及挂单明细 逐笔数据包含成交时间、价格、股数、成交方向,委托数据展示买一至买十、卖一至卖十的价格与数量
港股十档行情tick数据涵盖逐笔成交与委托,记录每笔买卖价格、成交量及挂单明细。逐笔数据包含成交时间、价格、股数、成交方向,委托数据展示买一至买十、卖一至卖十的价格与数量。分钟数据汇总每分钟开盘价、最高价、最低价、收盘价、成交量及成交额。历史行情覆盖近十五年,字段清晰完整,便于回溯分析。 数据源:CMES金融数据库
MO-372A_PQFP-F6_I1p27-R3p8x4p48Z1p1-N5p5C1p24.stp
MO-372A_PQFP-F6_I1p27-R3p8x4p48Z1p1-N5p5C1p24.stp


Java SE
