ava实现宠物商店管理系统,宠物,宠物商店,数组,您的,还需要

Java实现宠物商店管理系统

易采站长站,站长之家为您整理了Java实现宠物商店管理系统的相关内容。

本文实例为大家分享了Java实现宠物商店管理系统的具体代码,供大家参考,具体内容如下

一、实验目的

1.掌握java类的继承、多态等的基本概念;

2.掌握简单的信息管理系统的设计与实现。

二、实验环境

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

1. Windows xp/win7/win8/win10操作系统

2. JDK 1.6以上版本

3. Eclipse或NetBeans IDE或EditPlus或其它开发工具

三、实验内容与要求

(一) 问题描述

要求采用java面向对象的基本知识,实现宠物商店管理系统。

(二) 实验要求

1、宠物商店有狗和猫两种动物,请为这两种动物创建各自的类,而且它们都继承宠物类,为这些类定义基本的属性和方法;

2、为宠物商店也创建一个类,该类有基本属性,比如商店名称等,还有宠物笼子的属性,此外,还具备一些方法,比如:买进宠物、销售宠物、清点宠物库存、销售统计和盈利情况等;

3、实现买进宠物的方法,输入狗或猫的基本属性和进货价格,并把该买进的宠物放进宠物笼子;

4、实现销售宠物的方法,输入狗或猫的基本属性和销售价格,并把宠物从宠物笼子取出;

5、实现清点宠物库存方法,列出所有库存的宠物清单;

6、实现销售和盈利统计,查询所有已销售的宠物清单,包括进货价格和销售价格,还有总利润;

四、实现提示

1. 宠物笼子采用数组实现,数组的数据类型为宠物类;

2. 销售清单也采用数组实现。

五、代码

Pet类

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;

}

}

Cat类

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

}

public Cat() {
}

}

Dog类

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

}

public Dog() {
}

}

PetsStore类

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;

}

}

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实现宠物商店管理系统的详细介绍。欢迎大家对Java实现宠物商店管理系统内容提出宝贵意见
————————————————
版权声明:本文为CSDN博主「weixin_39585070」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_39585070/article/details/114235996

Java宠物商店源代码相关推荐

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

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

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

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

  3. 2023最新SSM计算机毕业设计选题大全(附源码+LW)之java宠物商店信息展示与服务订购系统7q5ic

    面对老师五花八门的设计要求,首先自己要明确好自己的题目方向,并且与老师多多沟通,用什么编程语言,使用到什么数据库,确定好了,在开始着手毕业设计. 1:选择课题的第一选择就是尽量选择指导老师擅长的课题, ...

  4. java s2 宠物商店_北大青鸟accp S2 java宠物商店项目案例代码有数据库表

    [实例简介] 这是 北大青鸟 6.0 S2 JAVA课本的项目案例 代码有注视 [实例截图] [核心代码] 51071f31-b79d-42d6-9b52-feb0304525bc └── ch15 ...

  5. bd青鸟Java宠物商店2017

    环境 mysql5.7 myeclipse10 jdk7 源码在下面,最新最完整的,不收费的,绝对原创的,别的地方下载需要积分,我这里是完整的项目代码 和数据库sql文件 只求评论转发,谢谢! 百度云 ...

  6. java实例分析宠物商店_java实例分析:宠物商店.ppt

    JAVA 应用开发详解 面向对象(高级) -- 实例分析:宠物商店 实例要求 实现一个宠物商店,在宠物商店中可以有多种(由用户决定数量)宠物,试表示出此种关系,并要求可以根据宠物的关键字查找到相应的宠 ...

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

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

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

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

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

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

  10. [附源码]java毕业设计网上宠物商店

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

最新文章

  1. AJAX跨域访问解决方案
  2. 配置Vim的显示样式
  3. qq android2.0,取代QQ?腾讯TIM安卓2.0发布:10GB云盘免费用
  4. 如何给按钮加上链接功能
  5. 动态加载___import__动态加载技术
  6. 老李分享:接口测试之jmeter
  7. windows 添加开始菜单
  8. 宇宙是什么,有尽头吗,为什么?
  9. python随机数列_Python2随机数列生成器简单实例
  10. Centos 7 密码重置
  11. Python之turtle画奥运五环、斜眼笑脸
  12. C语言 — 数据类型,基本整型所占字节数
  13. 6.深入分布式缓存:从原理到实践 --- Memcached 周边技术
  14. 200套web前端期末大作业 HTML+CSS+JavaScript网页设计实例 企业网站制作 [建议收藏]
  15. 四款亲试好用的PDF编辑器推荐,看看哪款最适合你
  16. My97DatePicker时间控件在asp.net的应用
  17. svn服务器搭建ip指定,mac 局域网svn服务器搭建
  18. win10卸载office2016提示:安装程序包的语言不受系统支持
  19. 小S坐月子的方法,难怪她身材那么好!
  20. java服务端用到的javase的基础知识_javase基础篇知识归纳

热门文章

  1. 基于JavaWeb的新闻发布管理系统设计与实现 毕业论文+任务书+开题报告+答辩PPT+项目源码及数据库文件
  2. persistent
  3. Python基础(8)字符串及常用操作
  4. Chrome浏览器的复用
  5. JAVA图片管理工具
  6. Spring Security 配置
  7. 概率运算中C(k,n)是怎么算的啊? 比如C(6,3)等于几?怎么来的.
  8. 个人职场工作感悟总结「如何尽快地提升自我」
  9. arm64汇编中orr 和 mov的交替使用
  10. activex服务器与com组件,COM和ActiveX控件设计.ppt