资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

删除商品Java代码 java删除代码怎么写

求一段java代码,关与删除表关系之类的。。

我只提供思路,代码就不用了吧:先通过设备id找到模组,遍历模组,通过模组id删除中间表关系,再删除模组,最后删除设备(你应该用的是JDBC吧,用hibernate就简单多啦)

创新互联主要从事成都网站制作、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务西城,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

Java使用字符串生成器来保存购物车中的商品信息,并能实现商品信息的添加、删除以及修改等功能

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类里有点小错误,

//总觉得update方法 不对头,你想怎么做?

求一个JAVA里用map集合写一个购物车的代码,购物车实现商品的添加,删除,查询和结算,写了半天没

建一个静态的Map集合 做购物车的集合

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

对map 增删改查就好了.. 结算完了 清空map

想用JAVA敲一段商品管理员的程序,有登录账号和密码,然后可以添加和删除商品的功能?

项目:完成一个电商系统的商品模块功能,商品类包含以下属性:商品ID, 商品名,类别名,单价,库存量,产地,计量单位等信息,要求实现商品管理功能以及管理员功能,具体如下:

1.管路员登录(账号密码固定admin/admin)

2.修改管理员密码

3.商品添加

4.商品列表

5.查询指定id商品

6.根据商品id删除商品

7.根据id修改商品价格

8.根据id修改指定商品库存

9.根据商品类别查询所有商品

10.查询指定价格区间的商品信息

根据项目要求,我们首先分析题目,知道此项目至少四个类:管理员类、商品类、系统类、测试类。

由于我们决定对此系统进行优化,要求能够对数据进行保存,所以我们用流的相关知识,将数据写入已经创建好的文档中,使其自动读写,以便管理,三个文档分别用于保存商品信息、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("请选择你要操作的业务");

System.out.println("1.进货");

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("退出系统");

System.exit(0);

break;

default:

break;

}

}

}

// 进货

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("请输入报警数:");

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("查询的商品不存在");

}

}

}

}

//实体类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 + ",报警数:" + minNumber

+ ",市场价:" + salePrice + ",会员价:" + vipPrice + ",库存量:" + amount + "]";

}

//Goods构造函数,

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删除代码怎么写
文章位置:http://cdkjz.cn/article/dooddsp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220