我只提供思路,代碼就不用了吧:先通過(guò)設(shè)備id找到模組,遍歷模組,通過(guò)模組id刪除中間表關(guān)系,再刪除模組,最后刪除設(shè)備(你應(yīng)該用的是JDBC吧,用hibernate就簡(jiǎn)單多啦)
創(chuàng)新互聯(lián)主要從事成都網(wǎng)站制作、成都做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)西城,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):18980820575
public?class?Cart?{
public?StringBuilder?data;
public?float?total;
public?Cart(){
data=new?StringBuilder();
}
public?void?buy(Goods?g){
g.gtotal=g.gnum*g.gprice;
total=total+g.gtotal;
data.append("[");
data.append(g.gname+"|");
data.append(g.gprice+"|");
data.append(g.gnum+"|");??//還是豎線看著方便
data.append(g.gtotal);
data.append("]");
}
public?void?delete(Goods?g){
int?s=data.indexOf(g.gname);
int?e=data.indexOf("]",?s);
data.delete(s-1,?e+1);
total=total-g.gtotal;??//刪除商品?,需要修改總額
}
public?void?update(Goods?g){
data.replace(3,?10,?"["+g.gname+"|"+g.gprice+"|"+g.gnum+"|"+g.gtotal);
}
public?void?show(){
System.out.print("總計(jì)金額:"?+?total?+?"????")?;
System.out.println(data);
}
}
//Excute類里有點(diǎn)小錯(cuò)誤,
//總覺(jué)得update方法?不對(duì)頭,你想怎么做?
建一個(gè)靜態(tài)的Map集合 做購(gòu)物車的集合
key值 放商品的ID value 放 商品對(duì)象.
對(duì)map 增刪改查就好了.. 結(jié)算完了 清空map
項(xiàng)目:完成一個(gè)電商系統(tǒng)的商品模塊功能,商品類包含以下屬性:商品ID, 商品名,類別名,單價(jià),庫(kù)存量,產(chǎn)地,計(jì)量單位等信息,要求實(shí)現(xiàn)商品管理功能以及管理員功能,具體如下:
1.管路員登錄(賬號(hào)密碼固定admin/admin)
2.修改管理員密碼
3.商品添加
4.商品列表
5.查詢指定id商品
6.根據(jù)商品id刪除商品
7.根據(jù)id修改商品價(jià)格
8.根據(jù)id修改指定商品庫(kù)存
9.根據(jù)商品類別查詢所有商品
10.查詢指定價(jià)格區(qū)間的商品信息
根據(jù)項(xiàng)目要求,我們首先分析題目,知道此項(xiàng)目至少四個(gè)類:管理員類、商品類、系統(tǒng)類、測(cè)試類。
由于我們決定對(duì)此系統(tǒng)進(jìn)行優(yōu)化,要求能夠?qū)?shù)據(jù)進(jìn)行保存,所以我們用流的相關(guān)知識(shí),將數(shù)據(jù)寫(xiě)入已經(jīng)創(chuàng)建好的文檔中,使其自動(dòng)讀寫(xiě),以便管理,三個(gè)文檔分別用于保存商品信息、id、user。
import?java.util.Scanner;
import?java.util.Vector;
/*
*只寫(xiě)了1,2,5功能,其他不想寫(xiě)了
*/
public?class?GoodsArrays?{
private?static?VectorGoods?vec?=?new?VectorGoods();
public?static?void?main(String[]?args)?{
GoodsArrays?ga=new?GoodsArrays();
ga.run();
}
public?void?run()?{
info();
}
public?void?info()?{
System.out.println("**********商品管理**********");
while?(true)?{
System.out.println("請(qǐng)選擇你要操作的業(yè)務(wù)");
System.out.println("1.進(jìn)貨");
System.out.println("2.查詢商品信息");
System.out.println("3.修改商品信息");
System.out.println("4.刪除商品信息");
System.out.println("5.退出");
Scanner?sc=new?Scanner(System.in);
System.out.println("請(qǐng)輸入操作:");
int?op=sc.nextInt();
switch?(op)?{
case?1:
inGoods();
break;
case?2:
searchGoods();
break;
case?5:
System.out.println("退出系統(tǒng)");
System.exit(0);
break;
default:
break;
}
}
}
//?進(jìn)貨
public?void?inGoods()?{
try?{
Scanner?sc?=?new?Scanner(System.in);
System.out.println("請(qǐng)輸入條碼:");
int?gid?=?sc.nextInt();
System.out.println("請(qǐng)輸入商品類型:");
String?cname?=?sc.next();
System.out.println("請(qǐng)輸入商品名稱:");
String?gname?=?sc.next();
System.out.println("請(qǐng)輸入報(bào)警數(shù):");
int?minNumber?=?sc.nextInt();
System.out.println("請(qǐng)輸入市場(chǎng)價(jià):");
double?salePrice?=?sc.nextDouble();
System.out.println("請(qǐng)輸入會(huì)員價(jià):");
double?vipPrice?=?sc.nextDouble();
System.out.println("請(qǐng)輸入庫(kù)存量:");
int?amount?=?sc.nextInt();
vec.add(new?Goods(gid,?cname,?gname,?minNumber,?salePrice,?vipPrice,?amount));
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
//?查詢
public?void?searchGoods()?{
Scanner?sc?=?new?Scanner(System.in);
System.out.println("------查詢商品------");
System.out.println("請(qǐng)選擇查詢類型");
System.out.println("a.查詢所有商品:");
System.out.println("b.查詢單個(gè)商品:");
String?op?=?sc.next();
if?(op.equalsIgnoreCase("a"))?{
for?(Goods?goods?:?vec)?{
System.out.println(goods);
}
}?else?if?(op.equalsIgnoreCase("b"))?{
System.out.println("請(qǐng)輸入商品編號(hào):");
int?gid?=?sc.nextInt();
boolean?findIndex?=?true;
for?(Goods?goods?:?vec)?{
int?id?=?goods.getGid();
if?(id?==?gid)?{
System.out.println(goods);
break;
}?else?{
findIndex?=?false;
}
}
if?(findIndex?==?false)?{
System.out.println("查詢的商品不存在");
}
}
}
}
//實(shí)體類Goods
public?class?Goods?{
private?int?gid;
private?String?cname;
private?String?gname;
private?int?minNumber;
private?double?salePrice;
private?double?vipPrice;
private?int?amount;
//重寫(xiě)Goods?toString()方法,用于顯示信息
@Override
public?String?toString()?{
System.out.println("商品信息如下:");
return?"[條碼:"?+?gid?+?",商品類型:"?+?cname?+?",商品名稱:"?+?gname?+?",報(bào)警數(shù):"?+?minNumber
+?",市場(chǎng)價(jià):"?+?salePrice?+?",會(huì)員價(jià):"?+?vipPrice?+?",庫(kù)存量:"?+?amount?+?"]";
}
//Goods構(gòu)造函數(shù),
public?Goods(int?gid,?String?cname,?String?gname,?int?minNumber,?double?salePrice,?double?vipPrice,?int?amount)?{
super();
this.gid?=?gid;
this.cname?=?cname;
this.gname?=?gname;
this.minNumber?=?minNumber;
this.salePrice?=?salePrice;
this.vipPrice?=?vipPrice;
this.amount?=?amount;
}
public?int?getGid()?{
return?gid;
}
public?void?setGid(int?gid)?{
this.gid?=?gid;
}
public?String?getCname()?{
return?cname;
}
public?void?setCname(String?cname)?{
this.cname?=?cname;
}
public?String?getGname()?{
return?gname;
}
public?void?setGname(String?gname)?{
this.gname?=?gname;
}
public?int?getMinNumber()?{
return?minNumber;
}
public?void?setMinNumber(int?minNumber)?{
this.minNumber?=?minNumber;
}
public?double?getSalePrice()?{
return?salePrice;
}
public?void?setSalePrice(double?salePrice)?{
this.salePrice?=?salePrice;
}
public?double?getVipPrice()?{
return?vipPrice;
}
public?void?setVipPrice(double?vipPrice)?{
this.vipPrice?=?vipPrice;
}
public?int?getAmount()?{
return?amount;
}
public?void?setAmount(int?amount)?{
this.amount?=?amount;
}
}
新聞名稱:刪除商品Java代碼 java刪除代碼怎么寫(xiě)
當(dāng)前URL:http://vcdvsql.cn/article38/dooddsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、云服務(wù)器、微信小程序、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容