刪除商品Java代碼 java刪除代碼怎么寫

求一段java代碼,關(guān)與刪除表關(guān)系之類的。。

我只提供思路,代碼就不用了吧:先通過設(shè)備id找到模組,遍歷模組,通過模組id刪除中間表關(guān)系,再刪除模組,最后刪除設(shè)備(你應(yīng)該用的是JDBC吧,用hibernate就簡單多啦)

創(chuàng)新互聯(lián)主要從事成都網(wǎng)站制作、成都做網(wǎng)站、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)西城,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575

Java使用字符串生成器來保存購物車中的商品信息,并能實(shí)現(xiàn)商品信息的添加、刪除以及修改等功能

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("總計金額:"?+?total?+?"????")?;

System.out.println(data);

}

}

//Excute類里有點(diǎn)小錯誤,

//總覺得update方法?不對頭,你想怎么做?

求一個JAVA里用map集合寫一個購物車的代碼,購物車實(shí)現(xiàn)商品的添加,刪除,查詢和結(jié)算,寫了半天沒

建一個靜態(tài)的Map集合 做購物車的集合

key值 放商品的ID value 放 商品對象.

對map 增刪改查就好了.. 結(jié)算完了 清空map

想用JAVA敲一段商品管理員的程序,有登錄賬號和密碼,然后可以添加和刪除商品的功能?

項目:完成一個電商系統(tǒng)的商品模塊功能,商品類包含以下屬性:商品ID, 商品名,類別名,單價,庫存量,產(chǎn)地,計量單位等信息,要求實(shí)現(xiàn)商品管理功能以及管理員功能,具體如下:

1.管路員登錄(賬號密碼固定admin/admin)

2.修改管理員密碼

3.商品添加

4.商品列表

5.查詢指定id商品

6.根據(jù)商品id刪除商品

7.根據(jù)id修改商品價格

8.根據(jù)id修改指定商品庫存

9.根據(jù)商品類別查詢所有商品

10.查詢指定價格區(qū)間的商品信息

根據(jù)項目要求,我們首先分析題目,知道此項目至少四個類:管理員類、商品類、系統(tǒng)類、測試類。

由于我們決定對此系統(tǒng)進(jìn)行優(yōu)化,要求能夠?qū)?shù)據(jù)進(jìn)行保存,所以我們用流的相關(guān)知識,將數(shù)據(jù)寫入已經(jīng)創(chuàng)建好的文檔中,使其自動讀寫,以便管理,三個文檔分別用于保存商品信息、id、user。

Java求解答

import?java.util.Scanner;

import?java.util.Vector;

/*

*只寫了1,2,5功能,其他不想寫了

*/

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("請選擇你要操作的業(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("請輸入操作:");

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("請輸入條碼:");

int?gid?=?sc.nextInt();

System.out.println("請輸入商品類型:");

String?cname?=?sc.next();

System.out.println("請輸入商品名稱:");

String?gname?=?sc.next();

System.out.println("請輸入報警數(shù):");

int?minNumber?=?sc.nextInt();

System.out.println("請輸入市場價:");

double?salePrice?=?sc.nextDouble();

System.out.println("請輸入會員價:");

double?vipPrice?=?sc.nextDouble();

System.out.println("請輸入庫存量:");

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("請選擇查詢類型");

System.out.println("a.查詢所有商品:");

System.out.println("b.查詢單個商品:");

String?op?=?sc.next();

if?(op.equalsIgnoreCase("a"))?{

for?(Goods?goods?:?vec)?{

System.out.println(goods);

}

}?else?if?(op.equalsIgnoreCase("b"))?{

System.out.println("請輸入商品編號:");

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;

//重寫Goods?toString()方法,用于顯示信息

@Override

public?String?toString()?{

System.out.println("商品信息如下:");

return?"[條碼:"?+?gid?+?",商品類型:"?+?cname?+?",商品名稱:"?+?gname?+?",報警數(shù):"?+?minNumber

+?",市場價:"?+?salePrice?+?",會員價:"?+?vipPrice?+?",庫存量:"?+?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刪除代碼怎么寫
當(dāng)前URL:http://www.muchs.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)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)