欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

  • <i id='1jc5c95q'><tr id='wco4n11b'><dt id='kjk7ih3c'><q id='hyixjb9l'><span id='nmpdtysb'><b id='03wigz7s'><form id='9k0o5xdp'><ins id='fg5mg67a'></ins><ul id='jvh67197'></ul><sub id='fzxgevls'></sub></form><legend id='dvohy2tg'></legend><bdo id='hbd64lf1'><pre id='92prunlv'><center id='h3ndm6b2'></center></pre></bdo></b><th id='3ysjm0wm'></th></span></q></dt></tr></i><div class="c8jzdxauzz" id='pyry9aeg'><tfoot id='hn3func2'></tfoot><dl id='cjnmvnzr'><fieldset id='uf61i0rl'></fieldset></dl></div>
    <legend id='2ewkxc1e'><style id='1cuqcgjg'><dir id='lwvovswn'><q id='yfmcpuxj'></q></dir></style></legend>

        <bdo id='rridx46k'></bdo><ul id='lvn2jjef'></ul>
      <tfoot id='c0cujlwk'></tfoot>
      1. <small id='4flviz05'></small><noframes id='n6j41nfz'>

      2. 歡迎來到入門教程網(wǎng)!

        Java編程

        當前位置:主頁 > 軟件編程 > Java編程 >

        java購物車原代碼實現(xiàn) java購物車應該用哪個集合實現(xiàn)

        來源:本站原創(chuàng)|時間:2023-04-11|欄目:Java編程|點擊: 次

        java購物車怎么寫?

        用Vector 或者是HashMap去裝

        下面有部分代碼你去看吧

        package com.aptech.restrant.DAO;

        import java.util.ArrayList;

        import java.util.HashMap;

        import java.util.List;

        import java.util.Map;

        import java.util.Set;

        import java.sql.Connection;

        import com.aptech.restrant.bean.CartItemBean;

        import com.aptech.restrant.bean.FoodBean;

        public class CartModel {

        private Connection conn;

        public CartModel(Connection conn) {

        this.conn=conn;

        }

        /**

        * 得到訂餐列表

        *

        * @return

        */

        public List changeToList(Map carts) {

        // 將Set中元素轉(zhuǎn)換成數(shù)組,以便使用循環(huán)進行遍歷

        Object[] foodItems = carts.keySet().toArray();

        // 定義double變量total,用于存放購物車內(nèi)餐品總價格

        double total = 0;

        List list = new ArrayList();

        // 循環(huán)遍歷購物車內(nèi)餐品,并顯示各個餐品的餐品名稱,價格,數(shù)量

        for (int i = 0; i foodItems.length; i++) {

        // 從Map對象cart中取出第i個餐品,放入cartItem中

        CartItemBean cartItem = (CartItemBean) carts

        .get((String) foodItems[i]);

        // 從cartItem中取出FoodBean對象

        FoodBean food1 = cartItem.getFoodBean();

        // 定義int類型變量quantity,用于表示購物車中單個餐品的數(shù)量

        int quantity = cartItem.getQuantity();

        // 定義double變量price,表示餐品單價

        double price = food1.getFoodPrice();

        // 定義double變量,subtotal表示單個餐品總價

        double subtotal = quantity * price;

        // // 計算購物車內(nèi)餐品總價格

        total += subtotal;

        cartItem.setSubtotal(subtotal);

        cartItem.setTotal(total);

        list.add(cartItem);

        }

        return list;

        }

        /**

        * 增加訂餐

        */

        public Map add(Map cart, String foodID) {

        // 購物車為空

        if (cart == null) {

        cart = new HashMap();

        }

        FoodModel fd = new FoodModel(conn);

        FoodBean food = fd.findFoodById(foodID);

        // 判斷購物車是否放東西(第一次點餐)

        if (cart.isEmpty()) {

        CartItemBean cartBean = new CartItemBean(food, 1);

        cart.put(foodID, cartBean);

        } else {

        // 判斷當前菜是否在購物車中,false表示當前菜沒有被點過。。

        boolean flag = false;

        // 得到鍵的集合

        Set set = cart.keySet();

        // 遍歷集合

        Object[] obj = set.toArray();

        for (int i = 0; i obj.length; i++) {

        Object object = obj[i];

        // 如果購物車已經(jīng)存在當前菜,數(shù)量+1

        if (object.equals(foodID)) {

        int quantity = ((CartItemBean) cart.get(object))

        .getQuantity();

        quantity += 1;

        System.out.println(quantity);

        ((CartItemBean) cart.get(object)).setQuantity(quantity);

        flag = true;

        break;

        }

        }

        if (flag == false) {

        // 把當前菜放到購物車里面

        CartItemBean cartBean = new CartItemBean(food, 1);

        cart.put(foodID, cartBean);

        }

        }

        return cart;

        }

        /**

        * 取消訂餐

        */

        public Map remove(Map cart, String foodID) {

        cart.remove(foodID);

        return cart;

        }

        /**

        * 更新購物車信息

        *

        * @param cart

        * @param foodID

        * @return

        */

        public MapString, CartItemBean update(Map cart, String foodID,

        boolean isAddorRemove) {

        Map map;

        if (isAddorRemove) {

        map = add(cart, foodID);

        } else {

        map = remove(cart, foodID);

        }

        return map;

        }

        }

        你好,java購物車代碼?

        import java.awt.*;

        import java.awt.event.*;

        class ShopFrame extends Frame implements ActionListener

        { Label label1,label2,label3,label4;

        Button button1,button2,button3,button4,button5;

        TextArea text;

        Panel panel1,panel2;

        static float sum=0.0f;

        ShopFrame(String s)

        { super(s);

        setLayout(new BorderLayout());

        label1=new Label("面紙:3元",Label.LEFT);

        label2=new Label("鋼筆:5元",Label.LEFT);

        label3=new Label("書:10元",Label.LEFT);

        label4=new Label("襪子:8元",Label.LEFT);

        button1=new Button("加入購物車");

        button2=new Button("加入購物車");

        button3=new Button("加入購物車");

        button4=new Button("加入購物車");

        button5=new Button("查看購物車");

        text=new TextArea("商品有:"+"\n",5,10);

        text.setEditable(false);

        addWindowListener(new WindowAdapter()

        { public void windowClosing(WindowEvent e)

        { System.exit(0);

        }

        }

        );

        button1.addActionListener(this);

        button2.addActionListener(this);

        button3.addActionListener(this);

        button4.addActionListener(this);

        button5.addActionListener(this);

        panel1=new Panel();

        panel2=new Panel();

        panel1.add(label1);

        panel1.add(button1);

        panel1.add(label2);

        panel1.add(button2);

        panel1.add(label3);

        panel1.add(button3);

        panel1.add(label4);

        panel1.add(button4);

        panel2.setLayout(new BorderLayout());

        panel2.add(button5,BorderLayout.NORTH);

        panel2.add(text,BorderLayout.SOUTH);

        this.add(panel1,BorderLayout.CENTER);

        this.add(panel2,BorderLayout.SOUTH);

        setBounds(100,100,350,250);

        setVisible(true);

        validate();

        }

        public void actionPerformed(ActionEvent e)

        { if(e.getSource()==button1)

        { text.append("一個面紙、");

        sum=sum+3;

        }

        else if(e.getSource()==button2)

        { text.append("一只鋼筆、");

        sum=sum+5;

        }

        else if(e.getSource()==button3)

        { text.append("一本書、");

        sum=sum+10;

        }

        else if(e.getSource()==button4)

        { text.append("一雙襪子、");

        sum=sum+8;

        }

        else if(e.getSource()==button5)

        {

        text.append("\n"+"總價為:"+"\n"+sum);

        }

        }

        }

        public class Shopping {

        public static void main(String[] args) {

        new ShopFrame("購物車");

        }

        }

        我沒用Swing可能顯示不出來你的效果。不滿意得話我在給你編一個。

        java中購物車的功能怎么實現(xiàn)

        一般利用session,當貨物提交后,讓session失效,這樣就可以完成簡單的購物車。用cookie保存本地也可以??茨愕木唧w需求了。

        <small id='jrqiyd29'></small><noframes id='525w8j01'>

            <tbody id='4is5b3d4'></tbody>

              <bdo id='2n6mtj5j'></bdo><ul id='y8wse463'></ul>
              <legend id='6qcc22x5'><style id='gwkpxs4h'><dir id='v4q16ikr'><q id='st1esz25'></q></dir></style></legend>
              <i id='n0v6e1hr'><tr id='ynzvdu1u'><dt id='6aieuxqf'><q id='a9ds7fw2'><span id='id5quh2y'><b id='s14tczsf'><form id='vibc321i'><ins id='0nr25hzd'></ins><ul id='ewq2oxo3'></ul><sub id='cgrpuk0t'></sub></form><legend id='8iiy074q'></legend><bdo id='r0knmg9o'><pre id='8qtbz7zt'><center id='lr1apkel'></center></pre></bdo></b><th id='0oc35q0p'></th></span></q></dt></tr></i><div class="c8jzdxauzz" id='sar22j6a'><tfoot id='5b3ypiih'></tfoot><dl id='7bkaks2z'><fieldset id='epojzqfz'></fieldset></dl></div>
            • <tfoot id='2fdsx6hx'></tfoot>

                • 上一篇:穿梭框后端JAVA代碼 穿梭框如何獲取右邊數(shù)據(jù)

                  欄    目:Java編程

                  下一篇:沒有了

                  本文標題:java購物車原代碼實現(xiàn) java購物車應該用哪個集合實現(xiàn)

                  本文地址:http://mengdiqiu.com.cn/a1/Javabiancheng/17369.html

                  網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

                  如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

                  聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

                  Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有

                    1. <i id='ctbyqn63'><tr id='2c7tu2rd'><dt id='g1qcqshe'><q id='sandvzfe'><span id='nojq4v19'><b id='do7v9lld'><form id='mp7t3x70'><ins id='c1oh0egz'></ins><ul id='d4ua3c1d'></ul><sub id='wu7qyngx'></sub></form><legend id='ettclrlz'></legend><bdo id='6twqxcrc'><pre id='0qvj9cwf'><center id='youb6rzl'></center></pre></bdo></b><th id='axn7z3dv'></th></span></q></dt></tr></i><div class="c8jzdxauzz" id='veqy9lgk'><tfoot id='e4c61e3a'></tfoot><dl id='9q3urwb6'><fieldset id='kwgstabl'></fieldset></dl></div>
                    2. <tfoot id='7ns01vvo'></tfoot>
                    3. <small id='pb89037c'></small><noframes id='khpe11nl'>

                    4. <legend id='zkprn9j1'><style id='z6sj7l24'><dir id='dg719ia2'><q id='ir5qlk5t'></q></dir></style></legend>

                        <bdo id='aa22hn2x'></bdo><ul id='4dz1stfe'></ul>