java题:编写类似淘宝一个简单的处理订单发货和进货的程序,要求实现简单的进货和发货以及统计货物量的功能

java题:编写类似淘宝一个简单的处理订单发货和进货的程序,要求实现简单的进货和发货以及统计货物量的功能,第1张

import java.util.ArrayList

public class Du {

public static void main(String[] args) throws Exception {

Seller seller = new Seller("My Store")

seller.addGoods("T-shirt"迟野, 200)

seller.addGoods("Pill", 100)

seller.addGoods("T-shirt", 100)

seller.addGoods("橡旦碰T-shirt", 50)

seller.addGoods("Pill", 50)

seller.addGoods("Hat", 100)

seller.printGoods()

Seller sell2 = new Seller("The Other Store")

sell2.addGoods("T-shirt", 200)

sell2.addGoods("Hat", 100)

sell2.sellGoods("T-shirt", 50)

sell2.addGoods("Hat"梁谈, 100)

sell2.printGoods()

}

}

class Seller {

private String sellerName

private int TotalTypeOfGoods

private ArrayList<String>goodsNameList = new ArrayList<String>()

private ArrayList<Integer>goodsQuantityList = new ArrayList<Integer>()

public Seller(String sellerName) {

this.sellerName = sellerName

}

public void addGoods(String goodName, int goodNum) {

int index = goodsNameList.indexOf(goodName)

if (index == -1) {

goodsNameList.add(goodName)

goodsQuantityList.add(new Integer(goodNum))

} else {

goodsQuantityList.set(index, goodsQuantityList.get(index)

.intValue()

+ goodNum)

}

TotalTypeOfGoods = goodsNameList.size()

}

public void sellGoods(String goodName, int goodNum) throws Exception {

if (TotalTypeOfGoods == 0) {

throw new Exception("No goods provided by the shop. Closed!")

}

int index = goodsNameList.indexOf(goodName)

if (index != -1) {

int qty = goodsQuantityList.get(index)

if (goodNum >qty) {

throw new Exception("Insufficient goods in the shop. Sorry!")

}

goodsQuantityList.set(index, qty - goodNum)

}else{

throw new Exception("Our shop doesn't sell " + goodName)

}

}

public void printGoods() {

System.out.print("Seller :" + this.sellerName + "\t")

System.out.println("Totoal Types of Goods is :" + this.TotalTypeOfGoods)

for(int i = 0i <goodsNameList.size()i++){

System.out.print("Goods Name: " + goodsNameList.get(i))

System.out.println("Remains: " + goodsQuantityList.get(i))

}

System.out.println()

}

}

-----------------testing

Seller :My Store Totoal Types of Goods is :3

Goods Name: T-shirtRemains: 350

Goods Name: PillRemains: 150

Goods Name: HatRemains: 100

Seller :The Other Store Totoal Types of Goods is :2

Goods Name: T-shirtRemains: 150

Goods Name: HatRemains: 200

你这样说,应该庆坦是想做C/咐差凳S架构的软件.

那么,把做好的工程做成一个jar包就行,因为jar包可以双击直接运行.

MyEclipse就可以把工程导成衡旅jar包:

右键工程, Export..

选择java里的jar,下面随便找个盘,取名xxx.jar. 下一步

再下一步,选择带程序入口的类.

确定,完成.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12370217.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存