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框架在很多项目当中拥有广泛的应用,很多时候做项目前人开坑开了一半就消失了,后人为了填补各种的坑就遭殃的不得了.嘛,程序猿大家都不喜欢像文案策划一样组织文字写东西 ...
随机推荐
- Mac版sublime text右键open in browser 不能识别中文名解决办法
问题描述: Mac下sublime text下打开中文命名的html文件,右键open in browser,浏览器无反应. 解决思路: 要么适应软件,要么改进软件来适应. 1. 将中文名的html ...
- c++ 网络编程课设入门超详细教程 ---目录
原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/9663167.html c++ 网络编程(一)TCP/UDP windows/linux 下入门 ...
- PHP之string之ltrim()函数使用
ltrim (PHP 4, PHP 5, PHP 7) ltrim - Strip whitespace (or other characters) from the beginning of a s ...
- secret
## 概览 Secret是用来保存小片敏感数据的k8s资源,例如密码,token,或者秘钥.这类数据当然也可以存放在Pod或者镜像中,但是放在Secret中是为了更方便的控制如何使用数据,并减少暴露的 ...
- R语言paste函数
中许多字符串使用 paste() 函数来组合.它可以将任意数量的参数组合在一起. 语法 粘贴(paste)函数的基本语法是: paste(..., sep = " ", colla ...
- 第4章 scrapy爬取知名技术文章网站(2)
4-8~9 编写spider爬取jobbole的所有文章 # -*- coding: utf-8 -*- import re import scrapy import datetime from sc ...
- php中数组和字符串的相互转换
数组转字符串: implode('!', $arr);//将一维数组以!分隔组合成一个字符串,参数一可以为"" 字符串转数组: explode('!', $str);//将字符串以 ...
- javascript的ajax功能的概念和示例
AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML). 个人理解:ajax就是无刷新提交,然后得到返回内容. 对应的不使用ajax时的传统网 ...
- Odata简介和Demo
转:http://www.cnblogs.com/shanyou/archive/2013/06/11/3131583.html 在SOA的世界中,最重要的一个概念就是契约(contract).在云计 ...
- Cheatsheet: 2018 08.01 ~ 2018 10.31
Other Building the Ultimate Developer PC 3.0 - The Parts List for my new computer, IronHeart Face re ...