課程
/后端開發(fā)
/Java
/JAVA遇見HTML——Servlet篇
我明白商品編號(hào)和名稱是Items的toString()方法打印出來的,但是我不知道控制臺(tái)的=4是怎么來的?沒看見有關(guān)于這個(gè)的輸出方法,求教大家
2017-07-18
源自:JAVA遇見HTML——Servlet篇 2-9
正在回答
map的鍵值對(duì)
obj應(yīng)該是包含了兩部分內(nèi)容:一部分就是Items,此時(shí)輸出的就是Items類中toString方法的內(nèi)容“?"商品編號(hào):"+this.getId()+",商品名稱:"+this.getName(); ?”;第二部分是Integer,就是商品的數(shù)量。至于為什么有等號(hào),我也沒搞清楚。。。。
同問+1
public static void main(String[] args) {
//創(chuàng)建商品對(duì)象
Items item1 = new Items(1,"沃特籃球鞋","溫州",200,500,"001.jpg");
Items item2 = new Items(2,"李寧運(yùn)動(dòng)鞋","廣東",300,500,"002.jpg");
Items item3 = new Items(1,"沃特籃球鞋","溫州",200,500,"001.jpg");
Cart c = new Cart();
c.addGoodsInCart(item1, 1);
c.addGoodsInCart(item2, 2);
//再次購買沃特籃球鞋,購買3雙
c.addGoodsInCart(item3, 3);
Set<Map.Entry<Items, Integer>> entries = c.getGoods().entrySet();
for(Map.Entry<Items, Integer> entry : entries){
System.out.println("商品編號(hào):"+entry.getKey().getId()
+", 商品名稱:"+entry.getKey().getName()
+", 購買數(shù)量:"+entry.getValue());
}
System.out.println(c.getTotalPrice());
ZoeHom 提問者
舉報(bào)
本門課程在JSP課程的基礎(chǔ)上,深入介紹Servlet的基礎(chǔ)知識(shí)
3 回答servlet課程中購物車的設(shè)計(jì)
1 回答servlet購物車項(xiàng)目問題
1 回答購物車的表
1 回答有了購物車怎么將購物車提交訂單呢?
2 回答購物車為空時(shí),查看購物車
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2019-01-06
2018-11-09
obj應(yīng)該是包含了兩部分內(nèi)容:一部分就是Items,此時(shí)輸出的就是Items類中toString方法的內(nèi)容“?"商品編號(hào):"+this.getId()+",商品名稱:"+this.getName(); ?”;第二部分是Integer,就是商品的數(shù)量。至于為什么有等號(hào),我也沒搞清楚。。。。
2018-02-27
同問+1
2017-07-18
public static void main(String[] args) {
//創(chuàng)建商品對(duì)象
Items item1 = new Items(1,"沃特籃球鞋","溫州",200,500,"001.jpg");
Items item2 = new Items(2,"李寧運(yùn)動(dòng)鞋","廣東",300,500,"002.jpg");
Items item3 = new Items(1,"沃特籃球鞋","溫州",200,500,"001.jpg");
Cart c = new Cart();
c.addGoodsInCart(item1, 1);
c.addGoodsInCart(item2, 2);
//再次購買沃特籃球鞋,購買3雙
c.addGoodsInCart(item3, 3);
Set<Map.Entry<Items, Integer>> entries = c.getGoods().entrySet();
for(Map.Entry<Items, Integer> entry : entries){
System.out.println("商品編號(hào):"+entry.getKey().getId()
+", 商品名稱:"+entry.getKey().getName()
+", 購買數(shù)量:"+entry.getValue());
}
System.out.println(c.getTotalPrice());
}