java买东西代码 java电商购物平台代码( 三 )


System.out.println("还要继续购物吗?(Y/N)");
String jx = in.nextLine();
if(jx.equals("N")){
break;
}
}
print(map);
}
public static void print(MapString, String m){
System.out.println("\n\n\n******************");
System.out.println("购物车清单");
Integer hj = 0;
for (EntryString, String entry : m.entrySet()) {
String key = entry.getKey();
String value = https://www.04ip.com/post/entry.getValue();
if(key.equals("1")){
hj += Integer.parseInt(value)*3;
System.out.println("哇哈哈纯净水: "+value+"件,合计:¥"+Integer.parseInt(value)*3);
}else if(key.equals("2")){
hj += Integer.parseInt(value)*5;
System.out.println("康师傅方便面: "+value+"件,合计:¥"+Integer.parseInt(value)*5);
}else if(key.equals("3")){
hj += Integer.parseInt(value)*4;
System.out.println("可口可乐: "+value+"件,合计:¥"+Integer.parseInt(value)*4);
}
}
System.out.println("合计金额:¥"+hj);
}
public static void init(){
System.out.println("******************");
System.out.println("\t商品列表\n");
System.out.println("商品名称价格");
System.out.println("1.哇哈哈纯净水¥3");
System.out.println("2.康师傅方便面¥5");
System.out.println("3.可口可乐¥4");
System.out.println("******************");
}
public static MapString,String buy(Scanner scan,MapString,String m){
System.out.print("请输入编号:");
String bh = scan.nextLine();
System.out.print("请输入购买数量:");
String num = scan.nextLine();
if(m.size()0m.keySet().contains(bh)){
m.put(bh,(Integer.parseInt(bh)+Integer.parseInt(num))+"");
}else{
m.put(bh, num);
}
return m;
}
}
急求java购物车代码package bean;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Administrator
* 购物车类:
* 为了方便将商品信息绑订到session上面而设计的一个
* 工具,提供了商品的添加,删除,列表,计价,清空,
* 修改功能 。
*/
public class Cart {
//items属性:用来保存商品
private ListCartItem items =
new ArrayListCartItem();
/**
* 将商品添加到购物车
*/
public boolean add(CartItem item){
for(int i=0;iitems.size();i++){
CartItem curr = items.get(i);
if(curr.getC().getId() == item.getC().getId()){
//该商品已经购买过
return false;
}
}
//没有购买过,则添加该商品
items.add(item);
return true;
}
/**
* 从购物车当中删除某件商品
*/
public void delete(int id){
for(int i=0;iitems.size();i++){
CartItem curr = items.get(i);
if(curr.getC().getId() == id){
items.remove(curr);
return;
}
}
}
/**
* 获得购物车中所有商品信息
*/
public ListCartItem list(){
return items;
}
/**
* 商品总价
*/
public double cost(){
double total = 0;
for(int i=0;iitems.size();i++){
CartItem curr = items.get(i);
total += curr.getC().getPrice() * curr.getQty();
}
return total;
}
/**
* 清空购物车中的所有商品
*/
public void clear(){
items.clear();
}
/**
* 修改购物车中某种商品的数量
*/
public void modify(int id,int qty){
for(int i=0;iitems.size();i++){
CartItem curr = items.get(i);
if(curr.getC().getId() == id){
curr.setQty(qty);
return;
}
}
}
}
你好,java购物车代码?import java.awt.*;
import java.awt.event.*;
class ShopFrame extends Frame implements ActionListener

推荐阅读