代码分析

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. WPF 将TextBox更改为PasswordBox样式(文字显示方式为密码)

    在TextBox样式中增加如下所诉: <Style x:Key="TxtPwd" TargetType="{x:Type TextBox}"> &l ...

  2. UVM序列篇之一:新手上路

          声明:本人所有权属路科验证,本人仅为个人学习方便将文章整理至此. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 有了UVM的世界观,知道这座城市的建 ...

  3. Oracle 存储过程A

    create or replace procedure users_procedure is cursor users_cursor is select * from users; v_id user ...

  4. Flex4 outerDocument

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  5. System.Transactions事务超时设置

    System.Transactions 有2个超时属性(timeout 与 maxTimeout),可以通过配置文件来进行设置. 1. timeout System.Transactions 默认的t ...

  6. android studio不能预览

    错误:Failed to load the LayoutLib: com/android/layoutlib/bridge/Bridge : Unsupported major.minor versi ...

  7. 利用jquery判断点是否在椭圆内

    源码例子下载 : <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...

  8. PHP-redis英文文档

    作为程序员,看英文文档是必备技能,所以尽量还是多看英文版的^^ PhpRedis The phpredis extension provides an API for communicating wi ...

  9. aabb问题

    输出所有aabb型的完全平方数 这个问题主要是提供一个判断完全平方的思路,就是用floor函数 #include <iostream> #include <string> #i ...

  10. Linux 更改时区

    原文:https://www.cnblogs.com/st-jun/p/7737188.html Linux修改时区的正确方法 CentOS和Ubuntu的时区文件是/etc/localtime,但是 ...