Ⅰ 用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中寫商品購物車怎麼實現每種商品總價都隨商品數量變化而變化
一般就是你在頁面增加監聽事件,每次修改商品數量就重新計算總價