java购物车系统源代码.docx

上传人:b****6 文档编号:13824116 上传时间:2023-06-17 格式:DOCX 页数:29 大小:20.56KB
下载 相关 举报
java购物车系统源代码.docx_第1页
第1页 / 共29页
java购物车系统源代码.docx_第2页
第2页 / 共29页
java购物车系统源代码.docx_第3页
第3页 / 共29页
java购物车系统源代码.docx_第4页
第4页 / 共29页
java购物车系统源代码.docx_第5页
第5页 / 共29页
java购物车系统源代码.docx_第6页
第6页 / 共29页
java购物车系统源代码.docx_第7页
第7页 / 共29页
java购物车系统源代码.docx_第8页
第8页 / 共29页
java购物车系统源代码.docx_第9页
第9页 / 共29页
java购物车系统源代码.docx_第10页
第10页 / 共29页
java购物车系统源代码.docx_第11页
第11页 / 共29页
java购物车系统源代码.docx_第12页
第12页 / 共29页
java购物车系统源代码.docx_第13页
第13页 / 共29页
java购物车系统源代码.docx_第14页
第14页 / 共29页
java购物车系统源代码.docx_第15页
第15页 / 共29页
java购物车系统源代码.docx_第16页
第16页 / 共29页
java购物车系统源代码.docx_第17页
第17页 / 共29页
java购物车系统源代码.docx_第18页
第18页 / 共29页
java购物车系统源代码.docx_第19页
第19页 / 共29页
java购物车系统源代码.docx_第20页
第20页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

java购物车系统源代码.docx

《java购物车系统源代码.docx》由会员分享,可在线阅读,更多相关《java购物车系统源代码.docx(29页珍藏版)》请在冰点文库上搜索。

java购物车系统源代码.docx

java购物车系统源代码

java购物车系统源代码

importjava.util.Scanner;

publicclassShopCar_Client{

ShopCar_Managermanager=newShopCar_Manager();

Scannerinput=newScanner(System.in);

//购物车

intsaveNo[]=newint[10];//存储商品编号

StringsaveName[]=newString[10];//存储商品名称

intsavePrice[]=newint[10];//存储商品价格

StringsaveInfo[]=newString[10];//存储商品信息

intsaveAmount[]=newint[10];//存储商品数量

intshuliang=0;//购买商品的数量

intNum;//购买商品的编号

//显示仓库中的商品

publicvoidshowShop(int[]quotID,String[]quotName,int[]quotNum,

String[]quotInfo,int[]quotPrice){

System.out.println("现在库存里的商品数量有:

");

System.out.println("商品编号\t\t"+"商品名称\t\t"+"商品数量"+"\t\t商品信息"

+"\t\t"+"商品价格");

for(inti=0;i<quotID.length;i++){

if(quotID[i]==0){

break;

}

System.out.println(quotID[i]+"\t\t"+quotName[i]+"\t\t"

+quotNum[i]+"\t\t"+quotInfo[i]+"\t"+quotPrice[i]);

}

}

//购买商品

publicvoidgoumai(int[]quotID,String[]quotName,int[]quotNum,

String[]quotInfo,int[]quotPrice){//购买商品

Stringanswer="";

do{

System.out.println("********************************************");

System.out.println("请选择1.购买商品2.查询购物车3.保存商品订单4.退出");

System.out.println("********************************************");

intnum1=input.nextInt();

switch(num1){

case1:

//购买商品

System.out.print("请输入你要够买的商品的编号:

");

Num=input.nextInt();

intindex=-1;

for(intx=0;x<quotID.length;x++){//在库存中循环找到需购买商品的编号

if(quotID[x]==0){

break;

}

if(quotID[x]==Num){

index=x;

break;

}

}

if(index!

=-1){

System.out.print("请输入你要够买的商品的数量:

");//若有此商品就提示用户输入购买的数量

shuliang=input.nextInt();

if(shuliang>0){//判断输入的数量是否大于0

for(inti=0;i<quotNum.length;i++){

if(saveNo[i]==Num){//判断购物车里是否有此商品

quotNum[index]=quotNum[index]+saveAmount[i];//货架上商品数量

saveAmount[i]=saveAmount[i]+shuliang;//购物车内商品数量

manager.quotNum[index]=manager.quotNum[index]-saveAmount[index];//购买商品后台减少数量

showShop(manager.quotID,manager.quotName,

manager.quotNum,manager.quotInfo,

manager.quotPrice);

break;

}

if(saveNo[i]==0){//找到存储商品的空数组

saveNo[i]=quotID[index];//编号

saveName[i]=quotName[index];//名称

savePrice[i]=quotPrice[index];//价格

saveInfo[i]=quotInfo[index];//

信息

if(shuliang<=quotNum[index]){

saveAmount[i]=saveAmount[i]+shuliang;//购物车内的商品数量

manager.quotNum[index]=manager.quotNum[index]-saveAmount[i];//购买商品后台减少数量

System.out.println("操作完成!

!

");

showShop(manager.quotID,manager.quotName,

manager.quotNum,manager.quotInfo,

manager.quotPrice);

}else{

System.out.println("抱歉,商品数量只有:

"

+quotNum[index]);

}

break;

}

}

}else{

System.out.println("抱歉,你的输入有错误!

");

}//

}else{

System.out.println("抱歉,没有该商品!

");

}

break;

case2:

purchasesn();//查询购物车内商品

break;

case3:

//确定购买商品结账退出

getAllMoney();//打折前的总价格

getScore();//计算积分

getZheKou();//计算折扣

payPrice();//打折后的价格

saveMenu();//结账菜单

break;

case4:

break;

default:

System.out.println("没有你所选的选项!

!

!

");

}

System.out.println("是否继续:

(y/n)");//是否回到购买菜单

answer=input.next();

}while(answer.equals("y"));

}

/**

*查看商品修改商品删除商品

*

*/

Stringanswer="";

booleanbig=true;

publicvoidpurchasesn(){

intindex1=-1;

intindex2=-1;

System.out.println("商品编号\t\t"+"商品名称\t\t"+"商品数量"+"\t\t商品信息"

+"\t\t商品价格");

for(inta=0;a<saveNo.length;a++){//循环输出购物车里的商品

if(saveNo[a]!

=0){

System.out.println(saveNo[a]+"\t\t"+saveName[a]+"\t\t"

+saveAmount[a]+"\t\t"+saveInfo[a]+"\t\t"

+savePrice[a]);

big=false;

}

}

System.out.println("\n1.修改商品2.删除商品3.返回");

System.out.println("(如果你要查询库存请去购买商品)");

intnum=input.nextInt();

switch(num){

case1:

System.out.print("请选择需修改的商品编号:

");

intnum1=input.nextInt();

for(inti=0;i<saveNo.length;i++){//循环查找购物车内相对应是商品

if(saveNo[i]==0){

break;

}

if(saveNo[i]==num1){

index1=i;

break;////

}

}

for(inti=0;i<manager.quotID.length;i++){//循环查找货架上相对应是商品

if(manager.quotID[i]==0){

break;

}

if(manager.quotID[i]==num1){

index2=i;

}

}

if(index1!

=-1){

System.out.print("请输入要修改的商品数量:

");

intxiugaiNum=input.nextInt();

if(xiugaiNum>0&&xiugaiNum<(manager.quotNum[index2]+saveAmount[index1])){//修改的数量的小于总数量

manager.quotNum[index2]=manager.quotNum[index2]+saveAmount[index1];

saveAmount[index1]=xiugaiNu

m;

manager.quotNum[index2]=manager.quotNum[index2]-saveAmount[index1];

System.out.println("修改成功!

!

");

}else{

System.out.println("库存商品不足,您不能修改!

!

");

}

}else{

System.out.println("没有您要修改的商品!

!

!

");

}

break;

case2:

System.out.print("请输入要删除的商品编号:

");

intnum2=input.nextInt();

for(inti=0;i<saveNo.length;i++){//循环查找购物车内的相对应是商品

if(saveNo[i]==0){

break;

}

if(saveNo[i]==num2){

index1=i;

}

}

for(inti=0;i<manager.quotID.length;i++){//循环查找货架上的相对应是商品

if(manager.quotID[i]==0){

break;

}

if(manager.quotID[i]==num2){

index2=i;

}

}

if((index1!

=-1)&&(index2!

=-1)){//

if(num2==saveNo[index1]){//删除

manager.quotNum[index2]=manager.quotNum[index2]

+saveAmount[index1];

if(index1==saveNo.length-1){//删除最后一个商品

saveNo[index1]=0;//编号

saveName[index1]=null;//名称

savePrice[index1]=0;//价格

saveInfo[index1]=null;//信息

saveAmount[index1]=0;//数量

}

for(inti=index1;i<saveNo.length-1;i++){

saveNo[i]=saveNo[i+1];//编号

saveName[i]=saveName[i+1];//名称

savePrice[i]=savePrice[i+1];//价格

saveInfo[i]=saveInfo[i+1];//信息

saveAmount[i]=saveAmount[i+1];//数量

}

System.out.println("删除成功!

!

");

}

}else{

System.out.println("没有您要删除的商品!

!

");//

}

break;

default:

showShop(manager.quotID,manager.quotName,manager.quotNum,

manager.quotInfo,manager.quotPrice);

goumai(manager.quotID,manager.quotName,manager.quotNum,

manager.quotInfo,manager.quotPrice);

}

if(big){

System.out.println("购物车暂时没有商品,请先购买商品然后再查看!

");

}

}

/***************************************************************************

*用户在购买商品时,根据用户购买商品所花的钱来给用户加积分

*

*/

intallMoney=0;//购买商品,计算折扣前的总价

intscore=100;//定义初始积分。

这里大家可以有多个会员进行登录,每个会员设置不同的积分变量存放各自的积分

doublezhekou=0.0;//具体的折扣数

doublepay;//实际应付款数

publicdoublegetAllMoney(){//购买商品,计算折扣前的总价

for(inti=0;i<saveNo.length;i++){

if(saveNo[i]==0){

break;

}

allMoney=allMoney+savePrice[i]*saveAmount[i];//价格累加

}

returnallMoney;

}

publicintgetScore(){//购物所得的积分

score=score+(int)(allMoney*3/100);

returnscore;

}

//根据积分求折扣

publicdouble

getZheKou(){

if(score<200){

zhekou=0.9;

}elseif(score>=200&&score<400){

zhekou=0.8;

}elseif(score>=400&&score<800){

zhekou=0.7;

}elseif(score>=800){

zhekou=0.6;

}

returnzhekou;

}

/***************************************************************************

*用户在选择“保存商品订单”的时候,用来下订单,根据用户积分来算折扣,然后求出实际应该付的钱数

*

*@parammoney:

*用户输入的钱数

*

*/

publicdoublepayPrice(){//打折后的价格

pay=zhekou*allMoney;

returnpay;

}

//用户窗体菜单类,调用总金额,积分,折扣等方法

publicvoidsaveMenu(){

Stringanswer="";

System.out.println("您购买商品的总价为:

\t"+allMoney+"元");

System.out.println("您目前的积分是:

\t"+score+"分");

System.out.println("根据您购物的金额,您享有:

\t"+zhekou+"的折扣优惠!

");

System.out.println("您最后应付款为:

\t"+pay);

do{

System.out.println("请输入您要付款的金额:

\t");

doublemoney=input.nextDouble();

if(money<pay){//输入的金额不足时

System.out.println("不好意思您输入的金额不足!

不能完成交易!

"+"\n是否继续交易(y/n):

");

answer=input.next();

}else{

System.out.println("您好!

交易成功!

!

"+"\n找回您:

"+(money-pay));

System.out.println("感谢您的购物,你可以享受本超市的抽奖活动!

");

System.out.println("规则:

输入1~3");//结账完了进行抽奖活动

intshuzi=input.nextInt();

intrandom=(int)((Math.random()*3)+1);

if(random==shuzi){

System.out.println("恭喜你,获得苹果电脑一台!

欢迎下次光临");

}else{

System.out.println("谢谢参与,欢迎下次光临!

");

}

break;

}

}while(answer.equals("y"));

}

}

importjava.util.Scanner;

publicclassShopCar_Manager{

StringuserName="manager";//定义管理员的用户名和密码

Stringpassword="0000";

Stringuser="";//定义输入的管理员用户名和密码

Stringpwd="";

publicinti=0;//用来记录输入的管理员用户名或密码错误的次数.定义成全局的是为了在测试类中能用到

publicint[]quotID=newint[10];//商品编号

publicString[]quotName=newString[10];//商品名称

publicint[]quotNum=newint[10];//商品数量

publicString[]quotInfo=newString[10];//商品介绍

publicint[]quotPrice=newint[10];//商品价格

Scannerinput=newScanner(System.in);

/**

*初始化库存的商品信息

*/

publicvoidinitial(){

quotID[0]=1;

quotName[0]="java";

quotNum[0]=20;

quotInfo[0]="真是太牛了!

!

!

";

quotPrice[0]=87;

quotID[1]=2;

quotName[1]="net";

quotNum[1]=28;

quotInfo[1]="太好

用了!

!

!

";

quotPrice[1]=69;

quotID[2]=3;

quotName[2]="c#";

quotNum[2]=34;

quotInfo[2]="太方便了!

!

!

";

quotPrice[2]=56;

quotID[3]=4;

quotName[3]="sql";

quotNum[3]=42;

quotInfo[3]="太实用啦!

!

!

";

quotPrice[3]=59;

}

 

//编写管理员用户登录的方法

publicvoidlogin(){

booleanbig=true;

for(inti=3;i>0;i--){

System.out.print("请输入管理员用户名:

");

user=input.next();

System.out.print("请输入管理员密码:

");

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2