Ⅰ 用JAVA 写个超市,超市里面有购物车。购物车里面能放一些商品(老师提示购物车用hashMap,键
你Map里面可以存一个自己定义的商品类,商品类里面有这特定属性,比如是不是买一送一,满多少减多少。
结算取出map的时候进行判断进行相应操作就好了
Ⅱ 编程 java 关于购物车
将session中的商品定义为对象
放入ArrayList中
修改了购物车内容后
把ArrayList.size()赋值到现在是0的位置回
如:
购物车添加物品答
List proctList = new ArrayList();
Proct proct1 = new Proct();
proctList.add(proct1);
...
Proct proctN = new Proct();
proctList.add(proctN);
session.setAttribute("proct", proctList);
页面可以写
List proctList = (List)session.getAttribute("proct");
把proctList.size()放到个数的位置
Ⅲ 请java高手进来 帮忙看看 我的购物车~!
List cartList = new ArrayList();
……
for(int j = 0; j < cartList.size(); j++){
……(这里是永远都不会执行的)
}
这个程序有问题不好说哪里,反正一点一点改吧专,先改好这里再属说
Ⅳ 在java中,怎么通过javascript来实现购物车里所有商品价格的总价结算
用JQuery选择器,操作DOM元素,进行商品加减操作(动态数据可以参考ajax技术)
Ⅳ JAVA SQL问题 购物车 把商品加入购物车使用什么方法
再加一个表格列:是否已加入购物车
点击按钮后,进行入库操作,insert语句
不行,这样的话内,只能加,不能容减
你应该在每行添加一个checkbox复选框
勾选了,就代表入库了,取消了就delete
对,就是这样
Ⅵ java web 做购物车的大概思路,和实现步奏是什么
购物车是网上购物平台中的一个重要模块,模拟超市中的购物车功能,即用户在结账前挑选商品的过程。
看完图就会明白,采纳哦。
Ⅶ java里选中checkbox怎么获得该行的ID
思路是:先获取复选框的值 然后进行循环看多少被选中 然后将参数进行提交 最后在后台用集合接收!!!!代码在下面,由于代码复制不上来,我是手写的,不知道有没有错~~反正给你一个思路吧!!!呵呵~~function add() { count = 0; // 进行判定的临时变量 var i = 0; //计数器的作用 就是看你提交啦多少产品 for( var j = 0 ; j < document.getElementsByName("复选框的ID值").length ; i++) { if(document.getElementsByName("复选框的ID值").[j].checked) { i = j; count++; } if( count == 0) { alert("请选择你要的产品"); return; } if( count > 0) { window.self.location = "你要转到的页面" + document.getElementsByName("复选框的ID值").value; } }}
Ⅷ Java使用字符串生成器来保存购物车中的商品信息,并能实现商品信息的添加、删除以及修改等功能
publicclassCart{
publicStringBuilderdata;
publicfloattotal;
publicCart(){
data=newStringBuilder();
}
publicvoidbuy(Goodsg){
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("]");
}
publicvoiddelete(Goodsg){
ints=data.indexOf(g.gname);
inte=data.indexOf("]",s);
data.delete(s-1,e+1);
total=total-g.gtotal;//删除商品,需要修改总额
}
publicvoipdate(Goodsg){
data.replace(3,10,"["+g.gname+"|"+g.gprice+"|"+g.gnum+"|"+g.gtotal);
}
publicvoidshow(){
System.out.print("总计金额:"+total+"");
System.out.println(data);
}
}
//Excute类里有点小错误,
//总觉得update方法不对头,你想怎么做?
Ⅸ 购物车的Java代码
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;public class ShoppingCartManager {
HashMap<String, String> hm=new HashMap<String, String>();
float totlePrice=0;
//添加book到购物车
public void addBook(String bookId,String bookQuantity){
if(hm.containsKey(bookId)){
int value=Integer.parseInt(hm.get(bookId));
value+=Integer.parseInt(bookQuantity);
hm.put(bookId, value+"");
}else{
hm.put(bookId, bookQuantity);
}
}
//修改数量
public void updateQuantity(String bookId,String bookQuantity){
hm.put(bookId, bookQuantity);
}
//获取购物车的所有信息 并计算总价
public ArrayList<BookBean> getShoppingCart(){
ArrayList<BookBean> al=new ArrayList<BookBean>();
Iterator<String> i=hm.keySet().iterator();
String ids="";
BookTableManager btm=new BookTableManager();
while(i.hasNext()){
ids=ids+","+i.next();
}
al= btm.selectByBookIds(ids);
totlePrice=0; //清空总价,防止无限累计
for(int j=0;j<al.size();j++){
BookBean bb=al.get(j);
totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+""));
}
return al;
}
//获取总价
public float getTotlePrice(){
return totlePrice;
}
//根据ID获取数量
public String getQuantityById(String id){
String quantity=hm.get(id);
return quantity;
}
//清空购物车
public void clear(){
hm.clear();
}
//删除购物车中的一本书
public void deleteById(String id){
hm.remove(id);
}
}
Ⅹ java中写商品购物车怎么实现每种商品总价都随商品数量变化而变化
一般就是你在页面增加监听事件,每次修改商品数量就重新计算总价