zoukankan      html  css  js  c++  java
  • java购物车系统 团队博客

    1. 团队名称、团队成员介绍(需要有照片)

    • 团队名称:一颗LFL
    • 团队成员:廖余俊 计算机工程学院网络工程1512 学号201521123053
    • 方旭 计算机工程学院网络工程1512 学号201521123048
    • 蓝锦明 计算机工程学院网络工程1512 学号201521123052.

    照片

    • 迷途小书童
    • 一只琳娜c
    • 岛歌

    2. 项目git地址

    课程设计

    3. 项目git提交记录截图(要体现出每个人的提交记录、提交说明),老师将点击进去重点考核。

    4. 项目功能架构图与主要功能流程图

    5. 项目运行截图

    首页

    商品展示页面

    成功添加至购物车

    删除商品

    修改商品

    最后显示

    6. 项目关键代码(不能太多)

    public class Item 
    { 
    	private int no;
    	private String name; 
    	private String brand; 
    	private double price; 
    
    	// ------------------------------------------------------- 
    	//  Create a new item with the given attributes. 
    	// ------------------------------------------------------- 
    
    	public name(int no, String name, String brand, double price) {
    		this.no = no;
    		this.name = name;
    		this.brand = brand;
    		this.price = price;
    	}
    	
    	public void setNo(int no) {
    		this.no = no;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	public void setBrand(String brand) {
    		this.brand = brand;
    	}
    
    	public void setPrice(double price) {
    		this.price = price;
    	}
    
    	/**
    	 * 获取价格
    	 * @return
    	 */
    	public double getPrice() 
    	{ 
    		return price; 
    	} 
    
    	/**
    	 * 获取产品名称
    	 * @return
    	 */
    	public String getName() 
    	{ 
    		return name; 
    	} 
    
    	/**
    	 * 获取品牌名称
    	 * @return
    	 */
    	public String getBrand() {
    		return brand;
    	}
    	/**
    	 * 获取商品编号
    	 * @return
    	 */
    	public int getNo() {
    		return no;
    	}
    
    	public String toString () 
    	{ 
    		NumberFormat fmt = NumberFormat.getCurrencyInstance(); 
    
    		return (no + "		" + name + "		" + brand + "		" + fmt.format(price));
    	} 
    
    }  
    
    public class ShoppingCart 
    { 
    	private int itemCount;      // 商品数量
    	private double totalPrice;  // 购物车总价格
    	private int capacity;       // 数组大小 
    	private Item[] cart;
    
    
    	// ----------------------------------------------------------- 
    	//  Creates an empty shopping cart with a capacity of 5 items. 
    	// ----------------------------------------------------------- 
    	public ShoppingCart() 
    	{ 
    		capacity = 5; 
    		itemCount = 0; 
    		totalPrice = 0.0; 
    		cart = new Item[capacity];
    	} 
    
    	/**
    	 * 
    	 * 添加功能
    	 */
    	public void buy(Item item) 
    	{
    		if(itemCount == capacity){
    			increaseSize();
    		}
    		cart[itemCount] = item;
    		totalPrice += cart[itemCount].getPrice();
    		itemCount++;
    		return;
    	}
    	
    	/**
    	 * 删除功能
    	 */
    	public void deleteCart(int No) {
    		int i;
    		for (i = 0; i < cart.length; i++) {
    			if(cart[i].getNo() == No){
    				totalPrice -= cart[i].getPrice();
    				for (int j = i; j < cart.length-1; j++) {
    					cart[j] = cart[j+1];
    				}
    				itemCount--;
    				break;
    			}
    		}
    		if(i == cart.length){
    			System.out.println("无此商品,无法删除。");
    		}
    		return;
    	}
    	/**
    	 * 修改功能
    	 */
    	public void updateCart(int No) {//修改编号
    		int i;
    		
    		@SuppressWarnings("resource")
    		Scanner scan = new Scanner(System.in);
    		
    		for (i = 0; i < cart.length; i++) {
    			if(cart[i].getNo() == No){
    				totalPrice -= cart[i].getPrice();
    				System.out.println("需要修改的信息如下:");
    				System.out.println(cart[i]);
    				System.out.println("请输入新的产品信息:");
    				cart[i].setNo(scan.nextInt());
    				cart[i].setName(scan.next());
    				cart[i].setBrand(scan.next());
    				cart[i].setPrice(scan.nextDouble());
    				totalPrice += cart[i].getPrice();
    				break;
    			}
    		}
    		if(i == cart.length){
    			System.out.println("无此商品");
    		}
    		return;
    	}
    
    	/**
    	 * 增加购物车容量
    	 */
    	private void increaseSize() 
    	{ 
    		Item[] temp = new Item[capacity + 3];
    		for (int i = 0; i < cart.length; i++) {
    			temp[i] = cart[i];
    		}
    		cart = temp;
    	} 
    	
    	/**
    	 *获取商品总值
    	 */
    	public double getTotalPrice() {
    		return totalPrice;
    	}
    
    	public Item[] getCart() {
    		return cart;
    	}
    
    	public void setCart(Item[] cart) {
    		this.cart = cart;
    	}
    
    	/**
    	 * 输出购物车信息
    	 */
    	public String toString() 
    	{ 
    		String contents = "您的购物车信息如下:"; 
    		contents += "
    no		name		brand		price
    "; 
    		
    		for (int i = 0; i < itemCount; i++) 
    			contents += cart[i].toString() + "
    "; 
    		
    		return contents; 
    	} 
    }
    

    7. 尚待改进或者新的想法

    浏览商品界面未对商品进行分类,商品的分类有利于用户更快查找到需要购买的商品
    购买购物车中的商品时未进行支付方式的选择并支付,未实现支付功能
    每个用户的购物车信息还未实现与用户一一对应

    8. 团队成员任务分配,团队成员课程设计博客链接(以表格形式呈现),标明组长。

    组员博客链接

  • 相关阅读:
    restapi(6)- do it the functional way, 重温函数式编程
    JS模块化
    socket.io websocket
    CSS 文字换行
    webpack初识
    升级nodejs至最新
    JavaScript Promise迷你书(中文版)
    时间格式化
    npm yarn
    深入浅出MongoDB应用实战开发
  • 原文地址:https://www.cnblogs.com/fx8023/p/7067630.html
Copyright © 2011-2022 走看看