一、父类

 public class Father{                            //父类

     protected static int stock1 = 10;            //库存
protected static int stock2 = 12;
protected static int stock3 = 15;
protected static int stock4 = 21;
protected static int stock5 = 9;
protected static int stock6 = 15; protected static float p1 = 1200; //商品价格
protected static float p2 = 89;
protected static float p3 = 688;
protected static float p4 = 5900;
protected static float p5 = 399;
protected static float p6 = 2588; protected static int integral1=10; //会员积分
protected static int integral2=200;
protected static int integral3=900;
protected static int integral4=3000; protected static int id1 = 1; //商品id
protected static int id2 = 2;
protected static int id3 = 3;
protected static int id4 = 4;
protected static int id5 = 5;
protected static int id6 = 6; int vipName; //会员编号
String name; //商品名
float price; //商品价格
int stock; //商品库存
int integral; //会员积分
int id; //商品id
protected static float sumprice = 0; public Father(String name,float price,int stock,int id){ //有参构造(商品)
this.name = name;
this.price = price;
this.stock = stock;
this.id = id;
}
public Father(int vipName,int integral){ //有参构造(会员)
this.vipName = vipName;
this.integral = integral;
} public Father() {
super();
} }

二、会员登陆

import java.util.Scanner;
public class Welcome extends Father{
Scanner land= new Scanner(System.in);
Father vip0 = new Father(0,integral1); //创建对象(会员)
Father vip1 = new Father(1,integral2);
Father vip2 = new Father(2,integral3);
Father vip3 = new Father(3,integral4);
public void vip(Scanner land){
System.out.println("您好 欢迎光临!\n");
System.out.println("请您先登陆!\n");
System.out.println("请输入会员编号:");
vipName=land.nextInt(); Father [] vip = new Father[4]; //创建对象数组(会员)
vip[0]=vip0;
vip[1]=vip1;
vip[2]=vip2;
vip[3]=vip3; //用户名正确
if(vipName==1||vipName==2||vipName==3||vipName==4||vipName==5||vipName==6){
System.out.println("请输入密码:");
String pasW = land.next();
//密码正确
if(pasW.equals("123")){
System.out.println("登陆成功!\n"+vipName+"号vip,欢迎您!");
System.out.println("您的当前积分为:"+vip[vipName].integral); }
//密码错误
else{
System.out.println("密码错误0.0,请重新输入!");
this.vip(land);
}
}
//用户名错误
else{
System.out.println("用户不存在0.0,请重新输入!");
this.vip(land);
}
}
public static void main(String[]args){
Scanner land= new Scanner(System.in);
Welcome landVip = new Welcome();
landVip.vip(land); } }

三、商品列表及购买

import java.util.Scanner;
public class CommodityList extends Welcome{
Father com1 = new Father("格力空调 ",p1,stock1,id1); //创建对象(商品)
Father com2 = new Father("蓝色圆领polo衫(男)",p2,stock2,id2);
Father com3 = new Father("Nice平底运动鞋透气型",p3,stock3,id3);
Father com4 = new Father("华硕笔记本FL5900 ",p4,stock4,id4);
Father com5 = new Father("adidas黑白户外双肩背包",p5,stock5,id5);
Father com6 = new Father("chanel男士香水",p6,stock6,id6); Father comAll = new Father(); //无参构造对象
Scanner sort= new Scanner(System.in); public void allCom(){ Object selected=sort.next(); Father [] com = new Father[6]; //商品对象数组
com[0] = com1; //创建对象(商品)
com[1] = com2;
com[2] = com3;
com[3] = com4;
com[4] = com5;
com[5] = com6;
if(selected.equals("all")|selected.equals("0")|selected.equals("所有")){ //所有商品列表 for(int i=0;i<6;i++){ //遍历打印数组
System.out.print("name:"+com[i].name+" \t");
System.out.print("stock:"+com[i].stock+" \t");
System.out.print("price:"+com[i].price+" \t");
System.out.print("id:"+com[i].id+"\t");
System.out.println();
System.out.println();
}
}
else if(selected.equals("assort")|selected.equals("1")|selected.equals("分类")){//分类商品列表
System.out.println('\u2605'+"数码电器"+'\u2605');
System.out.print("name:"+com[0].name+" \t");
System.out.print("stock:"+com[0].stock+" \t");
System.out.print("price:"+com[0].price+" \t");
System.out.print("id:"+com[0].id+"\t");
System.out.println();
System.out.println();
System.out.print("name:"+com[3].name+" \t");
System.out.print("stock:"+com[3].stock+" \t");
System.out.print("price:"+com[3].price+" \t");
System.out.print("id:"+com[3].id+"\t");
System.out.println();
System.out.println();
System.out.println('\u2605'+"男士专区"+'\u2605');
System.out.print("name:"+com[1].name+" \t");
System.out.print("stock:"+com[1].stock+" \t");
System.out.print("price:"+com[1].price+" \t");
System.out.print("id:"+com[1].id+"\t");
System.out.println();
System.out.println();
System.out.print("name:"+com[5].name+" \t");
System.out.print("stock:"+com[5].stock+" \t");
System.out.print("price:"+com[5].price+" \t");
System.out.print("id:"+com[5].id+"\t");
System.out.println();
System.out.println();
System.out.println('\u2605'+"户外运动"+'\u2605');
System.out.print("name:"+com[2].name+" \t");
System.out.print("stock:"+com[2].stock+" \t");
System.out.print("price:"+com[2].price+" \t");
System.out.print("id:"+com[2].id+"\t");
System.out.println();
System.out.println();
System.out.print("name:"+com[4].name+" \t");
System.out.print("stock:"+com[4].stock+" \t");
System.out.print("price:"+com[4].price+" \t");
System.out.print("id:"+com[4].id+"\t");
System.out.println();
System.out.println();
}
else{
System.out.println("输入错误!\n请重新输入");
this.allCom();
} }
public void shopping(){
Father [] com = new Father[6]; //商品对象数组
com[0] = com1; //创建对象(商品)
com[1] = com2;
com[2] = com3;
com[3] = com4;
com[4] = com5;
com[5] = com6;
//是否购买判断
System.out.println("是否购买商品(yes/no/是/否)");
String sure = sort.next(); //购买
if(sure.equals("yes")|sure.equals("是")){ System.out.println("请输入您选中的商品id");
int shopId = sort.nextInt();
for(int i=0;shopId<=com.length;i++){
comAll.sumprice +=com[shopId-1].price; //商品总价格
--com[shopId-1].stock; //库存-1
System.out.println("继续添加?(yes/no)");
String cont = sort.next();
//继续
if(cont.equals("yes")){
System.out.println("请输入您选中的商品id");
shopId = sort.nextInt();
}
//不继续
else if(cont.equals("no")){ System.out.println("谢谢惠顾!您购买的商品总价格为:"+comAll.sumprice+"元!积分增加"+comAll.sumprice/100); break;
}
//其他回答
else{
System.out.println("不好意思,没听清!");
CommodityList Com = new CommodityList(); //创建对象
Com.shopping();
}
} } //不购买
else if(sure.equals("no")|sure.equals("否")){
System.out.println("欢迎下次光临!");
}
//输入错误
else{
System.out.println("不好意思,没听清!请您再说一次0.0");
CommodityList Com = new CommodityList(); //创建对象
Com.shopping();
}
} public static void main(String[]args){
CommodityList Com = new CommodityList(); //创建对象
System.out.println("0 所有商品列表"); //提示信息
System.out.println("1 商品分类列表");
System.out.println("请选择商品显示列表(0/1/all/assort/“所有”/“分类”)");//提示输入信息
Com.allCom();
Com.shopping(); }
}

java小程序-----用if for写会员登陆和商品列表的更多相关文章

  1. 微信小程序云开发-云存储-带图片的商品列表携带id跳转至商品详情

    一.商品列表页 1.wxml文件 在view中添加点击事件goToGoodDetail,绑定数据data-id <!-- 添加点击事件goToGoodDetail --> <view ...

  2. 输出多行字符的一个简单JAVA小程序

    public class JAVA { public static void main(String[] args) { System.out.println("-------------- ...

  3. 浏览器兼容java小程序配置说明

    最近在使用的一个web应用系统是内嵌了java小程序,遇到了各种浏览器兼容性问题,现梳理如下: 1.通过以下链接检测当前电脑是否已经安装有java https://java.com/zh_CN/dow ...

  4. 框架一般用作Java应用程序的窗口,而Applet是Java小程序的窗口

    框架一般用作Java应用程序的窗口,而Applet是Java小程序的窗口. 与Frame不同,Applet是在网页中显示的,也可以通过添加Panel进行组件布局. package TomAwt; im ...

  5. 微信小程序_(校园视)开发用户注册登陆

    微信小程序_(校园视) 开发用户注册登陆 传送门 微信小程序_(校园视) 开发上传视频业务 传送门 微信小程序_(校园视) 开发视频的展示页-上 传送门 微信小程序_(校园视) 开发视频的展示页-下 ...

  6. 1_python小程序之实现用户的注册登陆验证功能

    python小程序之实现用户的注册登陆验证功能 程序扼要简述:  一.程序流程:1.程序开始2.判断本地文件/数据库是否已存在用户信息,存在则跳转到登陆,否则跳转到注册,注册成功后后跳转到登陆3.判断 ...

  7. java 小程序开发PKCS7Padding 解密方法实现,以及错误Cannot find any provider supporting AES/CBC/PKCS7Padding 解决办法

    近日在对接小程序API,其中wx.getUserInfo api返回的数据encryptedData 的解密算法要求为: AES-128-CBC,数据采用PKCS#7填充. 经过一番查询,得到java ...

  8. 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用

    有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...

  9. 2015.11.27初识java一集简单的java小程序

    JAVA配置环境变量方法: 1.打开我的电脑--属性--高级--环境变量 2.新建系统变量JAVA_HOME 和CLASSPATH 变量名:JAVA_HOME变量值:D:\Java\jdk1.7.0_ ...

随机推荐

  1. 用swoole简单实现MySQL连接池

    MySQL连接池 在传统的网站开发中,比如LNMP模式,由Nginx的master进程接收请求然后分给多个worker进程,每个worker进程再链接php-fpm的master进程,php-fpm再 ...

  2. Mybatis中,当插入数据后,返回最新主键id的几种方法,及具体用法

    insert元素 属性详解 其属性如下: parameterType ,入参的全限定类名或类型别名 keyColumn ,设置数据表自动生成的主键名.对特定数据库(如PostgreSQL),若自动生成 ...

  3. ActiveMQ Advisory Message

    http://activemq.apache.org/advisory-message.html ActiveMQ broker 内部维持了一些 topic,保存了一些系统信息,客户端可以订阅这些 t ...

  4. 常用Linux源小记

    常用国内镜像站: 阿里云:http://mirrors.aliyun.com/ 中科大:http://mirrors.ustc.edu.cn/ 清华:https://mirrors.tuna.tsin ...

  5. js图片时间和倒计时

    图片时间原理        原理:使用定时器每秒获取时间,获取时间的时,分,秒,组成一个6位数的字符串,然后用charAt,截取出对应的字符,图片命名和数字相对应就ok拉 倒计时原理        原 ...

  6. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. bzoj1239

    题解: 首先计算出两两之间的距离 然后二分答案 然后贪心判断是否可以放置少于等于k个 代码: #include<bits/stdc++.h> using namespace std; ; ...

  8. nginx在linux上的安装与配置详解(一)

    Nginx的安装与配置详解 (1)nginx简介     nginx概念: Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like ...

  9. Docker使用jenkins部署java项目到远程linux(三)

    实现功能:从本地提交代码到gogs上,本地的代码会被检测一遍 如果检测通过才能commit成功 然后可以继续执行push命令 .push后在gogs上使用web钩子自动推送到jenkins触发构建,j ...

  10. Unix分类学习

    调试 shell # bash -x script.sh 设置终端背景色 setterm -background black 一.网络 1.网卡状态 mii-tool -v ethtool eth0 ...