Java实例---简单的超市管理系统

代码分析

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 }
View Code

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 }
View Code

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 }
View Code

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 }
View Code

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 }
View Code

程序截图

源码下载

点击下载

转载于:https://www.cnblogs.com/ftl1012/p/supermarket.html

基于struts网上书店 JSP+Access论坛 网络招标信息管理系统 sql2000网络教学平台 mySQL超市管理系统 超市管理系统 教学管理系统 基于网络环境的选课系统 学生信息管理系统 新闻系统 新闻文章发布系统 考试系统 网络教学系统 网上书店系统 问卷管理... www.yateshi.com/service/13519.html 21K 2009-4-8 - 百度快照 求职java方向的web开发! - 程序员/软件工程师 - 58.com 2.熟悉STRUTS结构、MVC的开发;熟练Hibernate数据库持久层的开发及Spring。 3.能熟练应用多种JAVA应用服务器(Tomcat ,...武汉星星超市管理系统(2007-10-2007-12) 项目描述:对超市的货物、员工、财务进行管理 职责:模块开发,系统设计,数据... bj.58.com/tech/35220795x.shtml 11K 2009-2-13 - 百度快照 源码下载列表 - 纽纶网 | Nulung.com 600G IT资料,文档,书籍,... 1568_fjswpic12人气:超市管理系统\\数据库脚本和数据库备份超市管理系统\\数据库脚本和数据库备份-Supermarket ...所属分类:发布日期:2008-10-13文件大小:3845697提供者:StrutsNETBOOK6人气:一款网上书店的J2EE代码,采用STRUTS技术 ... www.dssz.net/100304-size-asc/1249.html 15K 2009-4-21 - 百度快照 新东方一搏职业培训学校 开发基于桌面的J2SE应用系统;(...2、MVC模式、Struts框架 3、...系统分析师。主要研究方向为软件项目管理、软件产品生命...曾主持参与铁路系统多个大型项目设计与开发,如全国铁路货车大修财务清算系统、车号标签自动识别系统、货车检修成本管理... www.hrbrcw.com/job/1920.aspx?jid=5165 53K 2009-4-22 - 百度快照
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值