Java实例---简单的超市管理系统
2023-09-11 14:20:11 时间
代码分析
Customer.java
1 package test; 2 3 public class Customer { 4 5 private String name; 6 private int customerType; 7 8 @Override 9 public String toString() { 10 return "顾客姓名:" + name + "\n 会员级别=" + customerType 11 + "\n"; 12 } 13 14 public Customer(String name, int customerType) { 15 super(); 16 this.name = name; 17 this.customerType = customerType; 18 } 19 public String getName() { 20 return name; 21 } 22 public void setName(String name) { 23 this.name = name; 24 } 25 public int getCustomerType() { 26 return customerType; 27 } 28 public void setCustomerType(int customerType) { 29 this.customerType = customerType; 30 } 31 32 33 34 }
Order.java
1 package test; 2 3 import java.util.Arrays; 4 5 public class Order { 6 private Customer cus; 7 private Product[] pros; 8 9 10 public Order(Customer cus, Product[] pros) { 11 super(); 12 this.cus = cus; 13 this.pros = pros; 14 } 15 16 17 18 public double getCustomerMoney() 19 { 20 double money = 0.0; 21 for(Product pro:pros) 22 { 23 if(!pro.isOnSale()) 24 { 25 if(cus.getCustomerType() == Type.Customer_GOLEAN) 26 { 27 money = pro.getSumMoney() * 0.96; 28 }else{ 29 money = pro.getSumMoney() ; 30 } 31 } 32 else if(cus.getCustomerType() == Type.Customer_Common) 33 { 34 money = pro.getSumMoney() * 0.99 ; 35 } 36 else if(cus.getCustomerType() == Type.Customer_PRIVARY) 37 { 38 money = pro.getSumMoney() * 0.98; 39 } 40 else if(cus.getCustomerType() == Type.Customer_ADVANCE) 41 { 42 money = pro.getSumMoney() * 0.97; 43 }else if(cus.getCustomerType() == Type.Customer_GOLEAN) 44 { 45 money = pro.getSumMoney() * 0.96; 46 } 47 } 48 return money; 49 } 50 51 52 public Customer getCus() { 53 return cus; 54 } 55 public void setCus(Customer cus) { 56 this.cus = cus; 57 } 58 public Product[] getPros() { 59 return pros; 60 } 61 public void setPros(Product[] pros) { 62 this.pros = pros; 63 } 64 @Override 65 public String toString() { 66 String str = null; 67 for(Product pro:pros) 68 { 69 str = "======================================\n" + 70 "顾客信息:" + cus.toString() + "\n" + 71 "-------------------------------\n" + 72 "商品信息:" + pro.toString() + "\n" + 73 "商品原价:" + pro.getSumMoney() +"\n" + 74 "会员价格:"+ this.getCustomerMoney() + "\n" + 75 "======================================\n"; 76 } 77 return str; 78 } 79 80 81 }
Product.java
1 package test; 2 3 public class Product { 4 5 private String name; 6 private double price; 7 private int num; 8 private boolean onSale; 9 10 public Product(String name, double price, int num, boolean onSale) { 11 super(); 12 this.name = name; 13 this.price = price; 14 this.num = num; 15 this.onSale = onSale; 16 } 17 18 public double getSumMoney() 19 { 20 return this.price * this.num; 21 } 22 23 @Override 24 public String toString() { 25 return "商品名称:" + name + "\n 商品价格:" + price + "\n 商品数量:" + num 26 + "\n 是否促销:" + onSale + "\n"; 27 } 28 29 30 public String getName() { 31 return name; 32 } 33 public void setName(String name) { 34 this.name = name; 35 } 36 public double getPrice() { 37 return price; 38 } 39 public void setPrice(double price) { 40 this.price = price; 41 } 42 public int getNum() { 43 return num; 44 } 45 public void setNum(int num) { 46 this.num = num; 47 } 48 public boolean isOnSale() { 49 return onSale; 50 } 51 public void setOnSale(boolean onSale) { 52 this.onSale = onSale; 53 } 54 55 }
Type.java
1 package test; 2 3 public class Type { 4 5 public static int Customer_Common = 1; 6 public static int Customer_PRIVARY = 2; 7 public static int Customer_ADVANCE = 3; 8 public static int Customer_GOLEAN = 4; 9 10 public static int PRODUCT_ON_SALE = 5; 11 public static int PRODUCT_NOT_SALE = 6; 12 }
Test.java
1 package test; 2 3 public class Test { 4 5 public static void main(String[] args) { 6 // TODO 自动生成的方法存根 7 Product pro = new Product("小米",12.2, 4,false); 8 Product pro1 = new Product("黄瓜",1.2, 6,false); 9 Product pro2 = new Product("香蕉",2.2, 14,true); 10 Product pro3 = new Product("果汁",7.8, 7,false); 11 Product pro4 = new Product("面包",22.4, 5,true); 12 13 Customer cus = new Customer("小明",1); 14 Customer cus1 = new Customer("小白",2); 15 Customer cus2 = new Customer("小王",3); 16 17 Customer cus3 = new Customer("小贵",4); 18 19 Order oder = new Order(cus, new Product[]{pro, pro4}); 20 Order oder1 = new Order(cus1, new Product[]{pro2, pro3}); 21 Order oder2 = new Order(cus2, new Product[]{pro1, pro3}); 22 Order oder3 = new Order(cus3, new Product[]{pro, pro4,pro2}); 23 24 System.out.println(oder.toString()); 25 System.out.println(oder1.toString()); 26 System.out.println(oder2.toString()); 27 System.out.println(oder3.toString()); 28 } 29 30 }
程序截图
源码下载
相关文章
- Jmeter里的全能java测试sampler - Java request
- JAVA 注解教程(四)Java 预置的注解
- java面向对象高级分层实例_接口类
- Java 8怎么了之二:函数和原语
- Java实现 LeetCode 833 字符串中的查找与替换(暴力模拟)
- Java实现 LeetCode 768 最多能完成排序的块 II(左右便利)
- Java实现 蓝桥杯 算法训练 Bit Compressor(暴力)
- Java实现 LeetCode 477 汉明距离总和
- Java实现 LeetCode 24 两两交换链表中的节点
- java实现排列序数
- Java实习生面试题整理
- 【JAVA】Java循环语句中的continue跳转进入下一次循环是否判断循环条件
- 【JAVA】java编译错误:编码UTF8/GBK的不可映射字符
- Java Web 常用实例
- 【JAVA】java中split以"." 、""、“|”分隔字符串
- Java经典设计模式之五大创建型模式(附实例和详解)
- Java迭代器模式:优雅遍历集合,实现简洁高效的迭代器设计
- java学习——入门扫盲篇
- 浅析JAVA设计模式之工厂模式(一)
- Java基础(14)-流程控制之break和continue
- 【java】Java 封装
- 基于JAVA实现的WEB端UI自动化 - WebDriver高级篇 - grid [跨浏览器远程测试-可分布式]
- JAVA开发讲义(二)-Java程序设计之数据之谜一