一、父类

 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. Leetcode 1005. K 次取反后最大化的数组和

    1005. K 次取反后最大化的数组和  显示英文描述 我的提交返回竞赛   用户通过次数377 用户尝试次数413 通过次数385 提交次数986 题目难度Easy 给定一个整数数组 A,我们只能用 ...

  2. PostgreSQL查看表大小的命令

    SELECT table_name, pg_size_pretty(table_size) AS table_size, pg_size_pretty(indexes_size) AS indexes ...

  3. python 多进程练习 调用 os.system命令

    import sys import getopt import os import multiprocessing def list_all_file(path): """ ...

  4. tf.expand_dims 来增加维度

    主要是因为tflearn官方的例子总是有embeding层,去掉的话要conv1d正常工作,需要加上expand_dims network = input_data(shape=[None, 100] ...

  5. python heapq模块使用

    Python内置的heapq模块 Python3.4版本中heapq包含了几个有用的方法: heapq.heappush(heap,item):将item,推入heap >>> it ...

  6. ntpd修改版本号教程

    1.查看当前ntpd版本号 执行:ntpd -v 2.查看当前ntpd位置 执行:which ntpd 3.备份ntpd 执行:cp /usr/sbin/ntpd /usr/sbin/ntpd.bak ...

  7. IOS中position:fixed弹出框中的input出现光标错位的问题

    解决方案是 在弹框出现的时候给body添加fixed <style type="text/css"> body{ position: fixed; width: 100 ...

  8. oracle中查询当前系统时间用到的dual是什么?

    oracle我们查询当前系统时间的时候,经常用到dual,这个是什么东西呢? -- 查询系统时间 结果:2018/04/17 15:00:48 -- select sysdate from dual; ...

  9. VIM编辑配置文件基本操作

    vim  /etc/apt/sources.list 按insert键进入编辑状态 编辑完成以后按ESC退出编辑状态 输入 ":"进入命令状态,常用命令: 1.W:write ,写 ...

  10. POJ 1936 All in All 匹配, 水题 难度:0

    题目 http://poj.org/problem?id=1936 题意 多组数据,每组数据有两个字符串A,B,求A是否是B的子串.(注意是子串,也就是不必在B中连续) 思路 设置计数器cnt为当前已 ...