急急急,求救,赠送高分
这样的程序如何写?
Question 1.
写一个关于名为 StoreItem的worker(support) class,它应该具有:
· 储存物品的项目
· 物品的价格条款
· 对购买大批量的货物的打折的程度
· 对购买小批量的货物的打折的程度
· 库存的数量
你的CLASS应该有 default constructor 和一个 overloaded constructor. 你的overloaded constructor 应该初始化 the instance variables, 每个instance variable都有着相应的参数. 提供一个可以提示顾客购买数量的方法 (purchase method), 如果购买的数量达到打折的标准就计算折扣, 输出产品名称(description),购买的数量(quantity purchased), 和 购买要花的钱, 产品在库存的数量.例如. 20个原价为$5.00的产品, 但是购买10个以上会给打多的折扣为20%。
20*(1 - 20.0/100)*5.00 = $80.00
而只买5个同样的产品需要 $25.00,(也是是没有折扣)
写一个可以结合你写的StoreItem class 的Java client (application) class 来实现以下列表:
· 以下面3个产品为例子
Description产品名称 Price价格 Discount折扣 Discount Minimum Quantity获得折扣的最小数量 Number in Stock库存
Pen $4.55 5% 10 1000
marker $2.50 7% 8 18
note pad $4.55 15% 15 1500
·
· 下列的代码代表客户要输入的数字
Code purchase
1 pens
2 markers
3 note pads
any other integer exit purchase mode
·
要求用户购买的数量不可以是负数. 计算价钱并输出具体信息。注意你的purchase method应该输出一个正确的信息。如果定单没有被填满就不能执行.
注意:
运行你的程序要求出现以下结果
15 markers, 5 pens, 20 note pads, 5 markers
你的输出应该为:
购物单:
item(商品): marker
quantity(数量): 15
cost(价钱): $34.87
item: pen
quantity: 5
cost: $22.75
item: note pad
quantity: 20
cost: $77.35
item: marker
quantity: 5
order cannot be filled (定单没有被填满)
终止运行
Question 2.
为你的StoreItem class做一个复印件. 取名为StoreItem2. 在StoreItem2里做些改动:
· 介绍2个静态变量(static variables) 来实现
o 总共购买的数量(the total number of items purchased on the trip )
o 总共花的钱数(the total cost of the trip)
· 介绍2个static methods
o 第一个用来初始化购买总数量(the first to initialize the total number of items purchased), 和总花销( the total cost of the trip )
o 第二个用来输出
§ 购买的总数量(the total number of items purchased on the trip )
§ 总花销(the total cost of the trip)
§ 平均每件物品的价格( the average price per item for the trip )
· 介绍 mutators 用来
o 改变某一商品提供打折的最小数量[change the minimum quantity for bulk discount of an item] (最小的数量应该传递一个准确的数字[the new minimum quantity should be passed down as an explicit parameter]).
o 改变某一商品的折扣 (最小的折扣应该传递一个准确的数字[the new discount should be passed down as an explicit parameter]).
为你的第二个问题的client class 做一个COPY.修改他为下列要求:
· 在运行结果前,
o 提示用户输入一个最新的 marker 折扣率 并且 更新相应的object 变量(update the corresponding object state accordingly). 注意:折扣率不能为负数或者大于100的数(Note that a discount percentage cannot be negative or be greater than 100. )
o 提示用户输入一个最新的NOTE PAD的获得折扣的最小数量值(Prompt the user to enter an updated note pad bulk minimum)同样 更新相应的object 变量(update the corresponding object state accordingly). 注意输入的获得折扣的最小值不能是变量。
· 结束运行后,要求输出:
o 购买商品的总数量,
o 购买商品所花的总钱数
o 商品的平均价格
注意你可以做些改变在你的( purchase method)和 support (worker) class里. 运行程序的到和QUESTION1一样的结果,但是在运行结果之前用户必须更新the marker折扣到 10% 和购买 note pad 获得折扣的最小数量为 25.
你的输出应该像这样:
Shopping Trip Transactions
item: marker
quantity: 15
cost: $33.75
item: pen
quantity: 5
cost: $22.75
item: note pad
quantity: 20
cost: $91.00
item: marker
quantity: 5
order cannot be filled
Shopping Trip Summary
Total number of items purchased: 40
Total cost: $147.50
Average price per item: $3.69
Normal Termination
问题点数:100、回复次数:3Top
1 楼adot111(安定)回复于 2003-04-01 00:11:29 得分 0
写完的程序为:(但是这个程序没有输入功能,如何改变才能让他实现输入功能。
import javax.swing.*;
class StoreItem
{
private String descriptionItem;
private float priceItem;
private float percentDisItem;//the percentage discount
private int miniNumItem;//the minimum number of Item
private int quantityInStock;//the number of Items in stock
public StoreItem(String item,float price,float percent,int miniNum,int numStock)
{
this.descriptionItem=item;
this.priceItem = price;
this.percentDisItem = percent;
this.miniNumItem = miniNum;
this.quantityInStock = numStock;
}
public float getPriceItem()
{
return priceItem;
}
public float getPercentDisItem()
{
return percentDisItem;
}
public int getMiniNumItem()
{
return miniNumItem;
}
public int getQuantityInStock()
{
return quantityInStock;
}
public void setPriceItem(float price)
{
priceItem = price;
}
public void setPercentDisItem(float percent)
{
percentDisItem = percent;
}
public void setMiniNumItem(int miniNum)
{
miniNumItem = miniNum;
}
public void setQuantityInStock(int numStock)
{
quantityInStock = numStock;
}
public void getPurchaseResult(int quantity)
{
float tempPrice;
System.out.println("quantity:" + quantity);
if(quantity>=miniNumItem) //if the quantity which you purchase is larger than discount minimum quantity.
if (quantityInStock>=quantity)//if the quantity in stock is larger than quantity you purchase.
{
tempPrice= quantity*(1-percentDisItem)*priceItem;//calculate the price.
System.out.println("cost: $"+ tempPrice);
quantityInStock=quantityInStock-quantity;
}
else
{
System.out.println("order cannot be filled");
}
else
{
if (quantityInStock>=quantity)//if the quantity in stock is larger than quantity you purchase.
{
tempPrice= quantity*priceItem;//calculate the price.
System.out.println("cost: $"+ tempPrice);
quantityInStock=quantityInStock-quantity;
}
else
{
System.out.println("order cannot be filled");
}
}
}
}
public class Client
{
public static void main(String[] args)
{
int purchasenum;
StoreItem markerItem=new StoreItem("marker",2.50f,0.07f,10,1000);//create a marker object.
StoreItem penItem=new StoreItem("pen",4.55f,0.05f,8,18);
StoreItem notepadItem=new StoreItem("note",4.55f,0.15f,15,1500);
try{
purchasenum=Integer.parseInt(args[0]);
String aa="marker";
String bb="pen";
String cc="notepad";
int r1=aa.compareTo(args[1]);
int r2=bb.compareTo(args[1]);
int r3=cc.compareTo(args[1]);
if (r1==0)
{
System.out.println("item: " +args[1]);
markerItem.getPurchaseResult(purchasenum);
}
else if(r2==0)
{
System.out.println("item: " +args[1]);
penItem.getPurchaseResult(purchasenum);
}
else if (r3==0)
{
System.out.println("item: " + args[1]);
notepadItem.getPurchaseResult(purchasenum);
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("please input the correct's argument!");
System.out.println("for example:");
System.out.println("java Client 10 pen ");
System.out.println("java Client 10 marker");
System.out.println("java Client 10 notepad");
}
}
}
Top
2 楼adot111(安定)回复于 2003-04-01 00:17:57 得分 0
如何使用JOptionPane实现输入呢?以完成下面的要求Top
3 楼lighteen(清凉)回复于 2003-04-01 00:38:01 得分 100
留下email地址,我发给你Top
相关问题
- 100分赠送(急急急急急)
- 100分赠送(急急急急急)
- 求助 散分100 急 急急急急急急急急急
- 高分求ASP用户密码如何加密?急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!急!
- 急急急急急急!!!!!!!!!高分求助!!!!!!!!!
- 急急急急急急急急急...在线等...解决放分
- ■■■■■■■■重分寻找Formula_one控件,急急急急急急急急急急急急急急急■■■■
- excel问题,100分请教大家,急急急急急急急急急急急!!!!!!!!!!
- 百分求购sqlserver2000可以在xp2下的版本急!急!急!急!急!急!急!急!急!急!急!急!急!急!
- 急急急急急急急急!!!!!! 150分!!快啊!!!




