Java实例---简单的超市管理系统
代码分析
Customer.java
package test; public class Customer { private String name;
private int customerType; @Override
public String toString() {
return "顾客姓名:" + name + "\n 会员级别=" + customerType
+ "\n";
} public Customer(String name, int customerType) {
super();
this.name = name;
this.customerType = customerType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCustomerType() {
return customerType;
}
public void setCustomerType(int customerType) {
this.customerType = customerType;
} }
Order.java
package test; import java.util.Arrays; public class Order {
private Customer cus;
private Product[] pros; public Order(Customer cus, Product[] pros) {
super();
this.cus = cus;
this.pros = pros;
} public double getCustomerMoney()
{
double money = 0.0;
for(Product pro:pros)
{
if(!pro.isOnSale())
{
if(cus.getCustomerType() == Type.Customer_GOLEAN)
{
money = pro.getSumMoney() * 0.96;
}else{
money = pro.getSumMoney() ;
}
}
else if(cus.getCustomerType() == Type.Customer_Common)
{
money = pro.getSumMoney() * 0.99 ;
}
else if(cus.getCustomerType() == Type.Customer_PRIVARY)
{
money = pro.getSumMoney() * 0.98;
}
else if(cus.getCustomerType() == Type.Customer_ADVANCE)
{
money = pro.getSumMoney() * 0.97;
}else if(cus.getCustomerType() == Type.Customer_GOLEAN)
{
money = pro.getSumMoney() * 0.96;
}
}
return money;
} public Customer getCus() {
return cus;
}
public void setCus(Customer cus) {
this.cus = cus;
}
public Product[] getPros() {
return pros;
}
public void setPros(Product[] pros) {
this.pros = pros;
}
@Override
public String toString() {
String str = null;
for(Product pro:pros)
{
str = "======================================\n" +
"顾客信息:" + cus.toString() + "\n" +
"-------------------------------\n" +
"商品信息:" + pro.toString() + "\n" +
"商品原价:" + pro.getSumMoney() +"\n" +
"会员价格:"+ this.getCustomerMoney() + "\n" +
"======================================\n";
}
return str;
} }
Product.java
package test; public class Product { private String name;
private double price;
private int num;
private boolean onSale; public Product(String name, double price, int num, boolean onSale) {
super();
this.name = name;
this.price = price;
this.num = num;
this.onSale = onSale;
} public double getSumMoney()
{
return this.price * this.num;
} @Override
public String toString() {
return "商品名称:" + name + "\n 商品价格:" + price + "\n 商品数量:" + num
+ "\n 是否促销:" + onSale + "\n";
} public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public boolean isOnSale() {
return onSale;
}
public void setOnSale(boolean onSale) {
this.onSale = onSale;
} }
Type.java
package test; public class Type { public static int Customer_Common = 1;
public static int Customer_PRIVARY = 2;
public static int Customer_ADVANCE = 3;
public static int Customer_GOLEAN = 4; public static int PRODUCT_ON_SALE = 5;
public static int PRODUCT_NOT_SALE = 6;
}
Test.java
package test; public class Test { public static void main(String[] args) {
// TODO 自动生成的方法存根
Product pro = new Product("小米",12.2, 4,false);
Product pro1 = new Product("黄瓜",1.2, 6,false);
Product pro2 = new Product("香蕉",2.2, 14,true);
Product pro3 = new Product("果汁",7.8, 7,false);
Product pro4 = new Product("面包",22.4, 5,true); Customer cus = new Customer("小明",1);
Customer cus1 = new Customer("小白",2);
Customer cus2 = new Customer("小王",3); Customer cus3 = new Customer("小贵",4); Order oder = new Order(cus, new Product[]{pro, pro4});
Order oder1 = new Order(cus1, new Product[]{pro2, pro3});
Order oder2 = new Order(cus2, new Product[]{pro1, pro3});
Order oder3 = new Order(cus3, new Product[]{pro, pro4,pro2}); System.out.println(oder.toString());
System.out.println(oder1.toString());
System.out.println(oder2.toString());
System.out.println(oder3.toString());
} }
程序截图
源码下载
Java实例---简单的超市管理系统的更多相关文章
- Java实例---简单的宠物管理系统
代码分析 Cat.java package com.ftl.petshop; class Cat implements Pet { private String name; private Strin ...
- Java实例---简单的上课管理系统
源码分析 Course.java package com.ftl.many2many; import java.util.*; public class Course { private int cr ...
- Java实例---简单的个人管理系统
代码分析 FileOperate.java package com.ftl.testperson; import java.io.File ; import java.io.FileInputStre ...
- Java实例---简单的数据库操作
源码分析 DAOFactory.java package cn.ftl.mysql ; public class DAOFactory { public static IEmpDAO getIEmpD ...
- Java实例---简单的投票系统
代码分析 InputData.java package vote; import java.io.BufferedReader; import java.io.IOException; import ...
- Java 实现一个 能够 进行简单的增删改查的 超市管理系统
1. 首先编写一个 Fruitltem 的商品类, 描述 商品的基本信息. 代码如下: 保证详细, 运行的起来, 有什么 问题也可以评论留言. /* * 自定义类, 描述商品信息 * * 商品的属性: ...
- 主题:Java WebService 简单实例
链接地址:主题:Java WebService 简单实例 http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...
- Java之从头开始编写简单课程信息管理系统
编写简单的课程管理系统对于新手并不友好,想要出色的完成并不容易以下是我的一些经验和方法 详情可参考以下链接: https://www.cnblogs.com/dream0-0/p/10090828.h ...
- PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例
前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...
随机推荐
- 阿里云CentOS7.4上搭建FTP服务器
1 安装过程 第一步:首先判断是否安装了vsftpd # rpm -qa | grep vsftpd 第二步:如果没有安装则安装vsftpd # yum -y install vsftpd 从第三步开 ...
- 计算2..n的素数
def check(2) , do: true def check(n) when n >2 do b = for x <- (Enum.into 2..n-1,[]),do: x if ...
- 使用VNC访问Linux桌面
在一个严重依赖Windows的工作环境中,比如电子邮件被限定为Outlook(因为加密要求), VPN软件不支持Linux版本,那么,只使用Linux桌面是不够的,还需要在Linux桌面上跑个虚拟机运 ...
- 使用postman模拟上传文件到springMVC的坑:the request was rejected because no multipart boundary was found
参考该文解决问题:http://blog.csdn.net/sanjay_f/article/details/47407063 报错 threw exception [Request processi ...
- R语言统计字符串的字符数ncahr函数
函数计算字符数量,包括在一个字符串的空格的个数. 语法 nchar()函数的基本语法是: nchar(x) 以下是所使用的参数的说明: x - 向量输入. 示例 result <- nchar( ...
- An Introduction to Computer Thinking
1.Die Grundlage des Computers 1.1 Binärzahl in die Dezimalzahl umsetzen Bereiten nach Gewicht,dann b ...
- jsonp/ajax 自己的一些总结
data.json代码:[{"name": "张三", "age": 18}, {"name": "李四&qu ...
- 升级Ubuntu 到14.04 64位 后eclipse出现闪退现象
升级Ubuntu 到14.04 64位 后eclipse出现闪退现象,搜了各种方法,最后解决问题 解决方法: 在所装的eclipse的目录下有个configuration/config.ini 文件 ...
- 一、hbase单机安装
下文将快速构建并启动单节点hbase,不使用hdfs作为存储,不使用独立的zookeeper hbase官网:http://hbase.apache.org/ 一.JDK环境 hbase需要JDK环境 ...
- 【原】spring boot source 1.5 中不支持 diamond 运算符
最近要开发新的项目,就花了几天时间看了下spring boot的相关资料,然后做了一个demo,不得不说开发效率确实很快,几行注解就完成了事务,aop,数据库等相关配置:但由于先前习惯了spring ...