我是靠谱客的博主 激动大树,最近开发中收集的这篇文章主要介绍java购物车,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

0、人员分工

人员任务
王超俊系统描述、类设计说明、购物车类、结算类
林烨超前期调查、功能结构图、商品类、菜单类

1、前期调查

 2、功能结构图

 3、系统描述

创建商品类,存放商品信息

创建购物车类,能够添加商品到购物车,能够删除商品,清空购物车

创建结算类,能够结算购物车

4、类设计说明

菜单类能够显示菜单页面,购物车类能够存放商品类,商品类放置商品信息,结算类能够展示购物车商品,结算购物车,购物车类能够添加、删除商品类。

商品类包含商品标号,商品价格,商品名称,能够显示商品。

5、关键代码:

商品类:

package shopping;
import java.util.*;
 
public class Goods {//商品
 
	private static int[] goodsID = new int[100];
    private static String[] goodsName =new String[100];
	private static double[] goodsPrice = new double[100];
	
	public static void showGoods() {
		System.out.println("商品编号	商品名	商品价格");
		for(int i = 0;i < 10;i++) {
			System.out.println(goodsID[i]+"	"+goodsName[i]+"	"+goodsPrice[i]);
		}
	}
	
	public static void searchGoods() {
		@SuppressWarnings("resource")
		
		Scanner sc = new Scanner(System.in);
		while(true) {
			System.out.println("请输入商品编号:");
			int Search = sc.nextInt();
			for(int i = 0;i < 10;i++) {
				if(Search == goodsID[i]) {
					System.out.print("商品已找到 : rn");
					System.out.println("商品编号	商品名	商品价格");
					System.out.println(goodsID[i]+"	"+goodsName[i]+"	"+goodsPrice[i]);
					return;//商品找到
				}
			}
			
			System.out.println("商品没找到,请重新查找: rn");
			
		}
		
	}
	
	public static void list() {
		for(int i = 0;i<10;i++) {
			goodsID[i] = i;
			switch (i) {
				case 0:
					goodsName[i] = "帽子" ;
					goodsPrice[i] = 58.60 ;
					break;
				case 1:
					goodsName[i] = "咖啡" ;
					goodsPrice[i] = 89.00 ;
					break;
				case 2:
					goodsName[i] = "化妆镜" ;
					goodsPrice[i] = 49.00 ;
					break;
				case 3:
					goodsName[i] = "耳机" ;
					goodsPrice[i] = 228.00 ;
					break;
				case 4:
					goodsName[i] = "东北玉米";
					goodsPrice[i] = 12.00;
					break;
				case 5:
					goodsName[i] = "水杯";
					goodsPrice[i] = 42.90;
					break;
				case 6:
					goodsName[i] = "铁观音";
					goodsPrice[i] =  119.00 ;
					break;
				case 7:
					goodsName[i] = "水果糖" ;
					goodsPrice[i] = 15.60 ;
					break;
				case 8:
					goodsName[i] = "苹果";
					goodsPrice[i] = 41.90 ;
					break;
				case 9:
					goodsName[i] = "五香瓜子";
					goodsPrice[i] = 23.80 ;
					break;
			}
		}	
		
	}
 
	public static int[] getGoodsID() {
		return goodsID;
	}
 
	public static void setGoodsID(int[] goodsID) {
		Goods.goodsID = goodsID;
	}
	
	public static String[] getGoodsName() {
		return goodsName;
	}
 
	public static void setGoodsName(String[] goodsName) {
		Goods.goodsName = goodsName;
	}
 
	public static double[] getGoodsPrice() {
		return goodsPrice;
	}
 
	public static void setGoodsPrice(double[] goodsPrice) {
		Goods.goodsPrice = goodsPrice;
	}
 
 
}

购物车类:

package shopping;
 
public class ShoppingCart {//查看购物车
public static int[] payNum = new int[100];//购买数量
	public static int addGoods(int needGoods,int needAddNum) {//增加商品
		
		for(int i = 0;i < 10;i++) {
			if(i == needGoods) {
				payNum[i] = needAddNum;
				System.out.println("商品编号"+"	"+"商品名"+"	"+"商品单价"+"	  "+"购买数量");
				System.out.println(Goods.getGoodsID()[i]+"	"+Goods.getGoodsName()[i]+"	"+Goods.getGoodsPrice()[i]+"	* "+ShoppingCart.payNum[i]);
				return 1;
			}
		}
		return 0;
	}
	
	public static void showCart() {//显示购物车
		double cartPay=0;//购物车商品总价
		System.out.println("———————————— 您的购物车 ————————————");
		System.out.print("商品编号"+"	"+"商品名"+"	"+"商品单价"+"	  "+"购买数量rn");
		
		for(int i = 0;i < 10;i++) {
			if( ShoppingCart.payNum[i] != 0) {
				System.out.println(Goods.getGoodsID()[i]+"	"+Goods.getGoodsName()[i]+"	"+Goods.getGoodsPrice()[i]+"	* "+ShoppingCart.payNum[i]);
			}
			cartPay = cartPay + (ShoppingCart.payNum[i] * Goods.getGoodsPrice()[i]);
		}
		System.out.println();
		System.out.println("您的账单估算 :  "+String.format("%.2f", cartPay));
	}
 
}

结算类:

package shopping;
 
public class Order {//结算
	public static void showPay() {//显示购物车中的商品
		double willPay = 0;
		System.out.println("");
		System.out.println("----------------------------------");
		System.out.println("商品编号"+"	"+"商品名"+"	"+"商品单价"+"	* "+"购买数量");
		System.out.println("----------------------------------");
		
		for(int i = 0;i < 10;i++) {
			if( ShoppingCart.payNum[i] != 0) {
				System.out.println(Goods.getGoodsID()[i]+"	"+Goods.getGoodsName()[i]+"	"+Goods.getGoodsPrice()[i]+"	4 "+ShoppingCart.payNum[i]);
			}
			willPay = willPay + (ShoppingCart.payNum[i] * Goods.getGoodsPrice()[i]);
		}
		System.out.println("----------------------------------");
		System.out.println("	实 际 应 付 :  "+String.format("%.2f", willPay));
		System.out.println("----------------------------------");
	}
}

 程序及主要功能展示:

 

 

 

 

 

最后

以上就是激动大树为你收集整理的java购物车的全部内容,希望文章能够帮你解决java购物车所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部