代码分析

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实例---简单的超市管理系统的更多相关文章

  1. Java实例---简单的宠物管理系统

    代码分析 Cat.java package com.ftl.petshop; class Cat implements Pet { private String name; private Strin ...

  2. Java实例---简单的上课管理系统

    源码分析 Course.java package com.ftl.many2many; import java.util.*; public class Course { private int cr ...

  3. Java实例---简单的个人管理系统

    代码分析 FileOperate.java package com.ftl.testperson; import java.io.File ; import java.io.FileInputStre ...

  4. Java实例---简单的数据库操作

    源码分析 DAOFactory.java package cn.ftl.mysql ; public class DAOFactory { public static IEmpDAO getIEmpD ...

  5. Java实例---简单的投票系统

    代码分析  InputData.java package vote; import java.io.BufferedReader; import java.io.IOException; import ...

  6. Java 实现一个 能够 进行简单的增删改查的 超市管理系统

    1. 首先编写一个 Fruitltem 的商品类, 描述 商品的基本信息. 代码如下: 保证详细, 运行的起来, 有什么 问题也可以评论留言. /* * 自定义类, 描述商品信息 * * 商品的属性: ...

  7. 主题:Java WebService 简单实例

    链接地址:主题:Java WebService 简单实例    http://www.iteye.com/topic/1135747 前言:朋友们开始以下教程前,请先看第五大点的注意事项,以避免不必要 ...

  8. Java之从头开始编写简单课程信息管理系统

    编写简单的课程管理系统对于新手并不友好,想要出色的完成并不容易以下是我的一些经验和方法 详情可参考以下链接: https://www.cnblogs.com/dream0-0/p/10090828.h ...

  9. PureMVC和Unity3D的UGUI制作一个简单的员工管理系统实例

    前言: 1.关于PureMVC: MVC框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...

随机推荐

  1. hadoop-2.6.0-cdh5.4.5.tar.gz(CDH)的3节点集群搭建(含zookeeper集群安装)

    前言 本人呕心沥血所写,经过好一段时间反复锤炼和整理修改.感谢所参考的博友们!同时,欢迎前来查阅赏脸的博友们收藏和转载,附上本人的链接 http://www.cnblogs.com/zlslch/p/ ...

  2. @SafeVarargs注解

    被@SafeVarargs注解标注的方法必须是由static或者final修饰的方法. 使用泛型的变长参数方法产生编译器警告的示例: public static <T> T useVara ...

  3. devise在引擎中安装后,设置访问自定义页面

    rails generate devise:views User Turn on scoped_views in config/initializer/devise.rb view config.sc ...

  4. Java对zip格式压缩和解压缩

    Java对zip格式压缩和解压缩 通过使用java的相关类可以实现对文件或文件夹的压缩,以及对压缩文件的解压. 1.1 ZIP和GZIP的区别 gzip是一种文件压缩工具(或该压缩工具产生的压缩文件格 ...

  5. 服务器php启动

    php.ini放在--with-config-file-path设置路径下lib文件夹中才找的到!!!! fpm的配置文件需要放在这个位置/usr/local/etc/php-fpm.conf,暂时不 ...

  6. [PY3]——IO——文件读写

    文件打开和关闭 # 使用open 打开文件,返回时值是一个 File-like对象 f.open('/test/file') # 使用read读取文件 f.read( ) # 使用close关闭文件 ...

  7. ansible 回调函数处理

    https://www.u3v3.com/ar/1421 https://serversforhackers.com/c/running-ansible-2-programmatically

  8. CADisplayLink+弹簧动画实现果冻效果

    项目中在Tabbar中间的按钮要从底部弹出视图并有果冻效果,在CocoaChina中找了一篇博客用 UIBezierPath 实现果冻效果,github,自己就按着上面的demo修改了一下( 之前也是 ...

  9. EntityFramework CodeFirst 学习

    个人学习笔记仅供分享,如有错误还请指出 demo结构:models类库和控制台程序 1.首先在model中建立,ADO.NET 实体数据模型---空模型,然后新建数据实体,并且生成数据库 2.控制台想 ...

  10. spring底层原理解析

    注解测试:如何使用注解(去掉配置文件)开发 新建MainConfig类 注解测试:新建MainTest2注解测试,用来测试//AnnoatationConfigApplicationContext: ...