目录

  • 一、实验目的
  • 二、实验环境
  • 三、实验内容与要求
    • (一) 问题描述
    • (二) 实验要求
  • 四、实现提示
  • 五、代码
    • 1、Pets(宠物类)
    • 2、Dog(狗类)
    • 3、Cat(猫类)
    • 4、PetStore(宠物商店类)
    • 5、Main(主函数)

一、实验目的

  1. 掌握java类的继承、多态等的基本概念;
  2. 掌握简单的信息管理系统的设计与实现。

二、实验环境

实验建议在安装了以下软件的计算机上完成:

  1. Windows xp/win7/win8/win10操作系统
  2. JDK 1.6以上版本
  3. Eclipse或NetBeans IDE或EditPlus或其它开发工具

三、实验内容与要求

(一) 问题描述
  1. 要求采用java面向对象的基本知识,实现宠物商店管理系统。
(二) 实验要求
  1. 宠物商店有狗和猫两种动物,请为这两种动物创建各自的类,而且它们都继承宠物类,为这些类定义基本的属性和方法;
  2. 为宠物商店也创建一个类,该类有基本属性,比如商店名称等,还有宠物笼子的属性,此外,还具备一些方法,比如:买进宠物、销售宠物、清点宠物库存、销售统计和盈利情况等;
  3. 实现买进宠物的方法,输入狗或猫的基本属性和进货价格,并把该买进的宠物放进宠物笼子;
  4. 实现销售宠物的方法,输入狗或猫的基本属性和销售价格,并把宠物从宠物笼子取出;
  5. 实现清点宠物库存方法,列出所有库存的宠物清单;
  6. 实现销售和盈利统计,查询所有已销售的宠物清单,包括进货价格和销售价格,还有总利润;

四、实现提示

  1. 宠物系统采用集合、接口、泛型等混合实现各个类;
  2. 销售清单也采用集合实现。

五、代码

1、Pets(宠物类)

public class Pets {private String color; //颜色private int age; //年龄private String sex; //性别private String kind;private double inPrice; //进货价格private double outPrice; //销售价格private double profit; //盈利public Pets(String color, int age, String sex) {this.color = color;this.age = age;this.sex = sex;}public Pets() {}public String getKind() {return kind;}public void setKind(String kind) {this.kind = kind;}public double getProfit() {return profit;}public void setProfit(double profit) {this.profit = profit;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getColor() {return color;}public void setColor(String color) {this.color = color;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public double getInPrice() {return inPrice;}public void setInPrice(double inPrice) {this.inPrice = inPrice;}public double getOutPrice() {return outPrice;}public void setOutPrice(double outPrice) {this.outPrice = outPrice;}}

2、Dog(狗类)

public class Dog extends Pets{public Dog(String color, int age, String sex) {super(color, age, sex);}public Dog() {}}

3、Cat(猫类)

public class Cat extends Pets{public Cat(String color, int age, String sex) {super(color, age, sex);}public Cat() {}}

4、PetStore(宠物商店类)

import java.util.Scanner;
import java.util.Date;public class PetsStore {Scanner input = new Scanner(System.in);private String name;private Cat[] cats;private Dog[] dogs;private Pets[] pets;private int dogFoot = 0; // 狗的当前长度private int catFoot = 0; //猫的当前长度private int petFoot = 0;private int num = 0; //库存数量private int inNum = 0; //进货数量private int outNum = 0; //销售数量public PetsStore(int len) {if (len > 0) {this.cats = new Cat[len]; // 开辟数组大小this.dogs = new Dog[len];this.pets = new Pets[len];} else {this.dogs = new Dog[1]; // 至少开辟一个空间this.cats = new Cat[1];this.pets = new Pets[1];}}public String getName() {return name;}public void setName(String name) {this.name = name;}public void add() { // 添加的是一个宠物System.out.println("您添加的是狗还是猫?\n" + "1.狗 2.猫");String choice = input.next();if(choice.equals("1")) {Dog dog = new Dog();System.out.println("请输入您要添加的宠物的信息");System.out.print("颜色:");dog.setColor(input.next());System.out.print("年龄:");dog.setAge(input.nextInt());System.out.print("性别:");dog.setSex(input.next());System.out.print("进货价格:");dog.setInPrice(input.nextDouble());System.out.print("出售价格:");dog.setOutPrice(input.nextDouble());if(dogFoot < dogs.length) {dogs[dogFoot] = dog;dogFoot++;System.out.println("添加成功!");inNum++;num++;}else {System.out.println("添加失败!");}}else if(choice.equals("2")) {if(catFoot < cats.length) {Cat cat = new Cat();System.out.println("请输入您要添加的宠物的信息");System.out.print("颜色:");cat.setColor(input.next());System.out.print("年龄:");cat.setAge(input.nextInt());System.out.print("性别:");cat.setSex(input.next());System.out.print("进货价格:");cat.setInPrice(input.nextDouble());System.out.print("出售价格:");cat.setOutPrice(input.nextDouble());cats[catFoot] = cat;catFoot++;System.out.println("添加成功!");inNum++;num++;}else {System.out.println("添加失败!");}}else {System.out.println("没有这个选项,请重新输入!");}}public void print() {Date date = new Date();System.out.println("===============宠物商店库存清单===============");System.out.println("*******************C A T S*******************");System.out.println("Color Age Sex InPrice OutPrice");for (int i = 0; i < cats.length; i++) {if (cats[i] != null) {System.out.println(cats[i].getColor() + "\t" + cats[i].getAge() + "\t" + cats[i].getSex() + "\t" + cats[i].getInPrice() + "\t" + cats[i].getOutPrice());}}System.out.println("\n*******************D O G S*******************");System.out.println("Color Age Sex InPrice OutPrice");for (int i = 0; i < dogs.length; i++) {if (dogs[i] != null) {System.out.println(dogs[i].getColor() + "\t" + dogs[i].getAge() + "\t" + dogs[i].getSex() + "\t" + dogs[i].getInPrice() + "\t" + dogs[i].getOutPrice());}}System.out.println("=============================================");System.out.println("date: " + date);}public void sell() {if(num == 0) {System.out.println("库存为零,请及时购进宠物!\n");}else {System.out.println("您要出售的是猫还是狗?\n" + "1.猫 2.狗");String choice = input.next();if(choice.equals("1")) {System.out.println("请输入您要出售的猫的特征");System.out.print("颜色:");String color1 = input.next();System.out.print("年龄:");int age1 = input.nextInt();System.out.print("性别:");String sex1 = input.next();int i, flag = catFoot;for(i = 0; i < catFoot; i++) {if(color1.equals(cats[i].getColor()) && age1 == cats[i].getAge() && sex1.equals(cats[i].getSex())) {flag = i; break;}}if(i == catFoot) {System.out.println("查无此猫!请核对后重新输入 \n");sell();}else {pets[petFoot] = cats[i];pets[petFoot].setKind("cat");petFoot++;for(int j = flag; j < catFoot; j++) {cats[j] = cats[j + 1];}System.out.println("售出成功!\n");catFoot -= 1; //不减1会报数组越界的错误outNum++;num--;}}else if(choice.equals("2")) {System.out.println("请输入您要出售的狗的特征");System.out.print("颜色:");String color1 = input.next();System.out.print("年龄:");int age1 = input.nextInt();System.out.print("性别:");String sex1 = input.next();int i, flag = dogFoot;for(i = 0; i < dogFoot; i++) {if(color1.equals(dogs[i].getColor()) && age1 == dogs[i].getAge() && sex1.equals(dogs[i].getSex())) {flag = i; break;}}if(i == dogFoot) {System.out.println("查无此狗!请核对后重新输入 ");sell();}else {pets[petFoot].setKind("dog");pets[petFoot] = dogs[i];petFoot++;for(int j = flag; j < catFoot; j++) {dogs[j] = dogs[j + 1];}System.out.println("售出成功!\n");dogFoot -= 1; //不减1会报数组越界的错误outNum++;num--;}}else {System.out.println("没有这个选项,请重新输入!");}}}public void note() {Date date = new Date();System.out.println("===============宠物商店销售记录清单===============");System.out.println("Kind Color Age Sex InPrice OutPrice");for(int i = 0; i < pets.length; i++) {if(pets[i] != null) {System.out.println(pets[i].getKind() + "\t" + pets[i].getColor() + "\t" + pets[i].getAge() + "\t" + pets[i].getSex() + "\t" + pets[i].getInPrice() + "\t" + pets[i].getOutPrice());}}System.out.println("=================================================");System.out.println("date: " + date);}public void profitNote() {Date date = new Date();System.out.println("===========宠物商店盈利情况===========");double cost = 0.0;double income = 0.0;double myProfit = 0.0;for(int i = 0; i < pets.length; i++) {if(pets[i] != null) {cost += pets[i].getInPrice();income += pets[i].getOutPrice();}}myProfit = income - cost;System.out.println("成本:" + cost + "\n" + "总收入:" + income + "\n" + "利润:" + myProfit);if(myProfit > 0) {System.out.println("恭喜,您的店处于盈利状态!");}else {System.out.println("很遗憾,您的店处于亏损状况!");}System.out.println("=======================================");System.out.println("date: " + date);}public int getOutNum() {return outNum;}public int getInNum() {return inNum;}public int getNum() {return num;}}

5、Main(主函数)

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner input = new Scanner(System.in);PetsStore store = new PetsStore(100);System.out.print("请为您的宠物商店取个名字:");store.setName(input.nextLine());System.out.println("您好!" + store.getName() + "的店长,欢迎使用宠物商店管理系统!");String choice = "1";while(choice.equals("0") == false) {System.out.println("==========宠物商店管理系统==========");System.out.println("1.查看库存\n" + "2.添加宠物\n" + "3.出售宠物\n" + "4.查看盈利\n" + "5.销售记录\n" + "0.退出程序");System.out.println("===================================");System.out.print("请输入你的选择:");choice = input.next();switch(choice) {case "1":store.print();System.out.println("请问您还需要什么服务?");break;case "2":String choice1 = "1";do {store.add();System.out.println("是否继续添加?\n" + "1.是 2.否");choice1 = input.next();} while(choice1.equals("1"));System.out.println("请问您还需要什么服务?");break;case "3":String choice2 = "1";do {store.sell();System.out.println("是否继续出售?\n" + "1.是 2.否");choice2 = input.next();} while(choice2.equals("1"));System.out.println("请问您还需要什么服务?");break;case "4":store.profitNote();System.out.println("请问您还需要什么服务?");break;case "5":store.note();System.out.println("请问您还需要什么服务?");break;case "0":System.out.println("谢谢您的使用,欢迎下次再来!\n" + "**********按任意键结束程序**********");break;default:System.out.println("错误输入, 请重新输入!");break;}}}}

宠物商店管理系统(java)相关推荐

  1. Eclipse+Java+Swing实现宠物商店管理系统

    Java+Swing实现宠物商店 一.系统介绍 二.系统展示 1.主界面 2.增加宠物 3.删除宠物 4.修改宠物 5.查询宠物 6.模块查询 三.系统实现 Cat.java Dog.java Mou ...

  2. java宠物商店管理系统_Java实现宠物商店管理系统

    Java实现宠物商店管理系统,宠物,宠物商店,数组,您的,还需要 Java实现宠物商店管理系统 易采站长站,站长之家为您整理了Java实现宠物商店管理系统的相关内容. 本文实例为大家分享了Java实现 ...

  3. [附源码]java毕业设计宠物商店管理系统

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

  4. Java实现简单的宠物商店管理系统

    一.实验目的 1.掌握java类的继承.多态等的基本概念: 2.掌握简单的信息管理系统的设计与实现. 二.实验环境 实验建议在安装了以下软件的计算机上完成: Windows xp/win7/win8/ ...

  5. [附源码]计算机毕业设计JAVA宠物商店管理系统

    [附源码]计算机毕业设计JAVA宠物商店管理系统 项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(Inte ...

  6. 基于javaweb的在线宠物商店系统(java+ssm+mysql+tomcat)

    基于javaweb的在线宠物商店系统(java+ssm+mysql+tomcat) 运行环境 Java≥8.MySQL≥5.7.Tomcat≥8 开发工具 eclipse/idea/myeclipse ...

  7. 通过宠物商店理解java面向对象

    前言:本篇博客,适合刚刚学完java基础语法的但是,对于面向对象,理解不够深刻的读者,本文通过经典的宠物商店,来让读者深刻的理解,面向对象,IS-A,HAS-A法则.本文不仅仅是简单的用java来模拟 ...

  8. 【宠物商店管理系统】基于SSM的宠物商店系统(ppt+论文+源代码)

    技术架构 SSM +jsp+spring.javascript.servlet. 数据库:mysql 系统功能 ![在这里插入图片描述](https://img-blog.csdnimg.cn/b09 ...

  9. [附源码]SSM计算机毕业设计宠物医院管理系统JAVA

    项目运行 环境配置: Jdk1.8 + Tomcat7.0 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclis ...

最新文章

  1. php7 thinkphp5,thinkphp5+phpstudy+php7.0连接SQL Server 2008 | 睿客网
  2. idea springboot 发布webservice 发布服务_太赞了:Spring boot+redis实现消息发布与订阅...
  3. python平稳性检验_Python数据分析0.3 用statsmodels进行ADF平稳性检验
  4. 使用Vistual Studio N年,推荐2个异常捕获的技巧
  5. 设计模式3—行为型模式
  6. 一加7 Pro高清渲染图曝光:A+屏幕 超棒手感
  7. H5自带的type=date或者month等日期控件移动端显示placeholder
  8. java实现modbus rtu协议与 modscan等工具(4)rtu转tcp
  9. 远程计算机或设备将不接受连接,谷歌浏览器无法上网
  10. 金融二叉树模型-给期权定价
  11. 常用RGB颜色表 色值
  12. 怎么更换linux桌面管理,切换窗口管理器/桌面环境?
  13. OutMan——集合对象的内存管理、copy的介绍及使用
  14. gc buffer busy release gc buffer busy acquire
  15. CAD如何创建图层并绘制图形
  16. 一文搞定Centos7.x安装ELK的7.6.2版本以及Cerebro集群监控
  17. 币圈暴涨暴跌有这五大技巧就够了
  18. ap导入 ebs oracle_Oracle EBS AP发票接口导入
  19. 微信公众平台为什么会火
  20. 关于ping带源地址和不带源地址有什么区别呢

热门文章

  1. 地图+Three.js参考
  2. React ajax 发送请求(六)
  3. Retina 屏幕与二倍图
  4. Excel数字 转 人民币 繁体大写
  5. js实现金额数转简体/繁体中文
  6. EasyExcel导出详解
  7. windows10修改管理员账户用户名
  8. 击剑,格斗中的“古典芭蕾”
  9. 用友nc633与oracle,用友NC63安装到SQL server 2008 R2和oracle上的表空间创建语句
  10. 手机学python用什么浏览器_Python+Appium学习之启动手机浏览器