import java.util.Vector; class Supermarket{ Vector market = null; Supermarket(){ market = new Vector(); } public void append(Goods g){ market.addElement(g); } public void delete(Goods g){ market.removeElement(g); } public void query(Goods g){ for(int i = 0;imarket.size();i++){ if((market.elementAt(i)).equals(g) == true){ g.showMe(); } } } } class Goods{ private String name; private double price; private int num; public Goods(String name,double price,int num){ this.name=name; this.price = price; this.num = num; } public void sale(double buyprice){ if(num==0){ System.out.println("購買商品已售空"); return; } if(buypricethis.price){ System.out.println("余額不足"); }else{ num--; } } public void add(int quantity){ num+=quantity; } public void showMe(){ System.out.println("商品名稱:"+this.name+" 商品價格:"+this.price+"$ "+"商品個數(shù):"+this.num); } } //很多地方給的不是很詳細(xì),只能這么憑理解寫,測試main方法自己寫。
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、鐵嶺ssl等。為近1000家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的鐵嶺網(wǎng)站制作公司
/**
*?超市管理系統(tǒng)
*?@author?Administrator
*
*/
public?class?ChaoShiSystemManager?{
public?static?void?main(String[]?args)?{
new?HuoWuDomImpl().start();
}
}
class?HuoWu{
public?String?bianhao;?//商品編號
public?String?name;?//商品名稱
public?double?jiage;?//商品價格
}
class?HuoWuDomImpl{
private?static?java.util.ArrayListHuoWu?list?=?new?java.util.ArrayListHuoWu();
public?void?start(){
?int?num?=?0;
System.out.println("--歡迎登錄超市管理系統(tǒng)--");
System.out.println("1、添加商品");
System.out.println("2、查詢商品");
java.util.Scanner?sc?=?new?java.util.Scanner(System.in);
System.out.println("請輸入模塊名稱:");
try?{
num?=?sc.nextInt();
if(num?==?1){
setHuoWu();
new?HuoWuDomImpl().start();
}else?if(num?==?2){
getSeleteHuoWu();
new?HuoWuDomImpl().start();
}else{
throw?new?RuntimeException("提示:抱歉,模塊正在開發(fā)中");
}
}?catch?(Exception?e)?{
e.printStackTrace();
throw?new?RuntimeException("提示:對不起,您的輸入有誤!");
}finally{
sc.close();
}
}
public?void?setHuoWu(){
HuoWu?hw?=?new?HuoWu();
java.util.Scanner?sc?=?new?java.util.Scanner(System.in);
System.out.println("請輸入商品編號:");
hw.bianhao?=?sc.next();
System.out.println("請輸入商品名稱:");
hw.name?=?sc.next();
System.out.println("請輸入商品價格");
try?{
hw.jiage?=?sc.nextDouble();
}?catch?(Exception?e)?{
throw?new?RuntimeException("提示:商品價格輸入錯誤!");
}finally{
sc.close();
}
list.add(hw);
System.out.println("提示:恭喜,添加成功!");
}
public?void?getSeleteHuoWu(){
java.util.Scanner?sc?=?new?java.util.Scanner(System.in);
System.out.println("請輸入商品編號...");
String?bianhao?=?sc.next();
java.util.Iterator?it?=?list.iterator();
while(it.hasNext()){
if(bianhao.equals(((HuoWu)it.next()).bianhao)){
System.out.println("商品編號:"?+?((HuoWu)it.next()).bianhao);
System.out.println("商品名稱:"?+?((HuoWu)it.next()).name);
System.out.println("商品價格:"?+?((HuoWu)it.next()).jiage);
}
}
}
}
PS:程序可能還有點問題,自己調(diào)試一下吧。改天有空我再來更新。
package?c;
import?java.util.Scanner;
public?class?SuperMarket?{
static?Scanner?scan?=?new?Scanner(System.in);
public?static?String?str;
public?static?void?main(String[]?args)?{
showMsg();
while?(scan.hasNext())?{
switch?(scan.nextInt())?{
case?1:
commodityManage();
break;
case?2:
customerManage();
break;
case?3:
orderManage();
break;
case?4:
exitSystem();
break;
default:
System.out.println("輸入錯誤,請重新輸入!");
break;
}
}
scan.close();
}
/**
?*?顯示信息
?*/
public?static?void?showMsg()?{
System.out.println("===================================");
System.out.println("\t超??市??庫??存??管??理??系??統(tǒng)\t");
System.out.println("===================================");
System.out.println("1、商品管理");
System.out.println("2、客戶管理");
System.out.println("3、訂單管理");
System.out.println("4、退出系統(tǒng)");
System.out.println("===================================");
System.out.println("請輸入您的選擇(1-4):");
}
/**
?*?選項?1、商品管理
?*/
public?static?void?commodityManage()?{
str?=?"商品管理";
showWelcom(str);
System.out.println("以上為商品管理的信息!\n是否繼續(xù)?(按1繼續(xù)/其他結(jié)束):");
exitOrShow(1);
}
/**
?*?選項?2、客戶管理
?*/
public?static?void?customerManage()?{
str?=?"客戶管理";
System.out.println("以上為客戶管理的信息!\n是否繼續(xù)?(按2繼續(xù)/其他結(jié)束):");
exitOrShow(2);
}
/**
?*?選項?3、訂單管理
?*/
public?static?void?orderManage()?{
str?=?"訂單管理";
System.out.println("以上為訂單管理的信息!\n是否繼續(xù)?(按3繼續(xù)/其他結(jié)束):");
exitOrShow(3);
}
/**
?*?選項?4、退出系統(tǒng)
?*/
public?static?void?exitSystem()?{
System.exit(0);
}
public?static?void?showWelcom(String?str)?{
System.out.println("歡迎進(jìn)入"+?str?+"模塊");
System.out.println("===================================");
}
public?static?void?exitOrShow(int?nextInt)?{
if?(scan.nextInt()?!=?nextInt)?{
exitSystem();
}?else?{
showMsg();
}
}
}