代码分析

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. grub2配置关键(三个核心变量prefix、root、cmdpath)和几点疑问

    前置知识:你必须知道grub的启动过程以及bios和uefi的相关基础知识,可以参考:<Unified Extensible Firmware Interface Wikipedia>.& ...

  2. 66_Plus-One

    目录 66_Plus-One Description Solution Java solution Python solution 1 Python solution 2 Python solutio ...

  3. javascript图形动画设计--以简单正弦波轨迹移动

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. rust by example 2

    本来这篇准备明天在写的,但正好今天的Release没出问题,就接着写吧 rust里的原生类型: 有符号整数: i8, i16, i32, i64和isize(指针大小) 无符号整数:u8, u16,  ...

  5. 如鹏网学习笔记(十二)HTML5

    一.HTML5简介 HTML5是HTML语言第五次修改产生的新的HTML语言版本 改进主要包括: 增加新的HTML标签或者属性.新的CSS样式属性.新的JavaScript API等.同时删除了一些过 ...

  6. android studio 中由于网络问题,编译错误

    由于网络原因,需要连外网实现下载相关依赖包,导致编译失败 在 build.gradle文件中 将原来是jcenter()的地址改成 maven{ url 'http://maven.aliyun.co ...

  7. iptables-linux(ls)-inode-block

    Part1:iptables 环境:centos6.7 目前我只配置了INPUT.OUTPUT和FORWORD都是ACCEPT的规则 由于想要先实现防火墙规则,所以前面的内容讲的是方法,后面是详解ip ...

  8. [LeetCode]Maximum Length of Repeated Subarray

    Maximum Length of Repeated Subarray: Given two integer arrays A and B, return the maximum length of ...

  9. FATAL bad indentation of a mapping entry at line 83, column 3: branch: master 已解决;

    部署hexo 时候,修改完_config.yml  文件后更新报错如下,问题解决: FATAL bad indentation of a mapping entry at line 83, colum ...

  10. 精选10款HTML5手机模板

    1.Stroller | Mobile & Tablet Responsive Template 演示地址   购买地址 2.Ocean Mobile Template 演示地址   购买地址 ...