求宠物管理系统Java代码,具有增删改查功能,用数组实现,并且有输入功能
2个回答
展开全部
代码实现:
1.宠物类
package 宠物商店;
public abstract class 宠物类 {
public String species; //种类
public String name; //名字
public String sex; //雌雄
public int age; //年龄
public 宠物类() {
}
public 宠物类(String species,String name,String sex,int age) {
this.species=species;
this.name=name;
this.sex=sex;
this.age=age;
}
public abstract void pet1();
public void setspecies(String species) {
this.species=species;
}
public String getspecies() {
return species;
}
public void setname(String name) {
this.name=name;
}
public String getname() {
return name;
}
public void setsex(String sex) {
this.sex=sex;
}
public String getsex() {
return sex;
}
public void setage(int age) {
this.age=age;
}
public int getage() {
return age;
}
}
2.商店类
package 宠物商店;
public class 商店类 extends 宠物类{
public 商店类(String species,String name,String sex,int age) {
super(species, name, sex,age);
}
public void pet1() {
System.out.println("宠物种类:"+species+"\t宠物名称:"+name+"\t宠物性别"+sex+"\t宠物年龄"+age+"岁");
}
static 商店类 doug1=new 商店类("金毛","豆豆","雄性",1);
static 商店类 doug2=new 商店类("牧羊犬","花花","雌性",2);
static 商店类 doug3=new 商店类("泰迪","毛毛","雄性",1);
static 商店类 doug4=new 商店类("二哈","笨笨","雌性",2);
static 商店类 cat1=new 商店类("加菲猫","胖胖","雄性",1);
static 商店类 cat2=new 商店类("波斯猫","玲玲","雌性",2);
}
3.下架类
package 宠物商店;
import java.util.Scanner;
public class 下架类 {
public static void XJ() {
Scanner scanner = new Scanner(System.in);
System.out.println("现在本店有以下宠物:");
商店类.doug1.pet1();
商店类.doug2.pet1();
商店类.doug3.pet1();
商店类.doug4.pet1();
商店类.cat1.pet1();
商店类.cat2.pet1();
System.out.println("请您选择要下架的宠物名称");
String name = scanner.next();
System.out.println("您好,您已成功下架名字为:"+name+"的宠物");
}
}
4.上架类
package 宠物商店;
import java.util.Scanner;
public class 上架类 {
public static String species; //种类
public static String name; //名字
public static String sex; //雌雄
public static int age; //年龄
public static void SJ() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要上架宠物的种类:");
species=scanner.next();
System.out.println("请输入你要上架宠物的名字:");
name=scanner.next();
System.out.println("请输入你要上架宠物的雌雄:");
sex=scanner.next();
System.out.println("请输入你要上架宠物的年龄:");
age=scanner.nextInt();
商店类 cw=new 商店类(species,name,sex,age);
System.out.println("恭喜您,您已经成功上架:");
cw.pet1();
System.out.println("现在本商店有:");
商店类.doug1.pet1();
商店类.doug2.pet1();
商店类.doug3.pet1();
商店类.doug4.pet1();
商店类.cat1.pet1();
商店类.cat2.pet1();
cw.pet1();
}
}
5.查询类
package 宠物商店;
import java.util.Scanner;
public class 查询类 {
public static void CX() {
Scanner scanner = new Scanner(System.in);
System.out.println("尊敬的顾客您好,我会为您提供最优的服务");
System.out.println("1:查询本店宠物种类\t2:查询本店宠物信息");
int n = scanner.nextInt();
if(n==1) {
System.out.println("尊敬的顾客,目前本店有:1、宠物狗\t2、宠物猫");
}
if(n==2) {
System.out.println("请输入您要查询宠物的种类信息:");
String name = scanner.next();
if(name.equals("狗")||name.equals("gou")) {
System.out.println("本店提供"+name+"的品种为:");
商店类.doug1.pet1();
商店类.doug2.pet1();
商店类.doug3.pet1();
商店类.doug4.pet1();
}
else if(name.equals("猫")||name.equals("mao")) {
System.out.println("本店提供"+name+"的品种为:");
商店类.cat1.pet1();
商店类.cat2.pet1();
}
else {
System.out.println("给常抱歉,本店不能提供你所需要的宠物:"+name);
}
}
}
}
6.测试类
package 宠物商店;
import java.util.Scanner;
public class 测试类 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("**********欢迎来到宠物商店在线系统**********");
System.out.println("我们将为您提供最优秀的服务,请您做以下选择");
System.out.println("1:员工登录\t2:尊敬的顾客");
int i = scanner.nextInt();
if(i==1){
System.out.println("亲爱的员工您好,请选择您要进行的操作:");
System.out.println("1:对宠物进行上架操作\t2:对宠物进行下架操作");
int n = scanner.nextInt();
if(n==1) {
//转到上架类
上架类.SJ();
}
if(n==2) {
//转到下架类
下架类.XJ();
}
}
if(i==2) {
查询类.CX();
}
}
}
1.宠物类
package 宠物商店;
public abstract class 宠物类 {
public String species; //种类
public String name; //名字
public String sex; //雌雄
public int age; //年龄
public 宠物类() {
}
public 宠物类(String species,String name,String sex,int age) {
this.species=species;
this.name=name;
this.sex=sex;
this.age=age;
}
public abstract void pet1();
public void setspecies(String species) {
this.species=species;
}
public String getspecies() {
return species;
}
public void setname(String name) {
this.name=name;
}
public String getname() {
return name;
}
public void setsex(String sex) {
this.sex=sex;
}
public String getsex() {
return sex;
}
public void setage(int age) {
this.age=age;
}
public int getage() {
return age;
}
}
2.商店类
package 宠物商店;
public class 商店类 extends 宠物类{
public 商店类(String species,String name,String sex,int age) {
super(species, name, sex,age);
}
public void pet1() {
System.out.println("宠物种类:"+species+"\t宠物名称:"+name+"\t宠物性别"+sex+"\t宠物年龄"+age+"岁");
}
static 商店类 doug1=new 商店类("金毛","豆豆","雄性",1);
static 商店类 doug2=new 商店类("牧羊犬","花花","雌性",2);
static 商店类 doug3=new 商店类("泰迪","毛毛","雄性",1);
static 商店类 doug4=new 商店类("二哈","笨笨","雌性",2);
static 商店类 cat1=new 商店类("加菲猫","胖胖","雄性",1);
static 商店类 cat2=new 商店类("波斯猫","玲玲","雌性",2);
}
3.下架类
package 宠物商店;
import java.util.Scanner;
public class 下架类 {
public static void XJ() {
Scanner scanner = new Scanner(System.in);
System.out.println("现在本店有以下宠物:");
商店类.doug1.pet1();
商店类.doug2.pet1();
商店类.doug3.pet1();
商店类.doug4.pet1();
商店类.cat1.pet1();
商店类.cat2.pet1();
System.out.println("请您选择要下架的宠物名称");
String name = scanner.next();
System.out.println("您好,您已成功下架名字为:"+name+"的宠物");
}
}
4.上架类
package 宠物商店;
import java.util.Scanner;
public class 上架类 {
public static String species; //种类
public static String name; //名字
public static String sex; //雌雄
public static int age; //年龄
public static void SJ() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要上架宠物的种类:");
species=scanner.next();
System.out.println("请输入你要上架宠物的名字:");
name=scanner.next();
System.out.println("请输入你要上架宠物的雌雄:");
sex=scanner.next();
System.out.println("请输入你要上架宠物的年龄:");
age=scanner.nextInt();
商店类 cw=new 商店类(species,name,sex,age);
System.out.println("恭喜您,您已经成功上架:");
cw.pet1();
System.out.println("现在本商店有:");
商店类.doug1.pet1();
商店类.doug2.pet1();
商店类.doug3.pet1();
商店类.doug4.pet1();
商店类.cat1.pet1();
商店类.cat2.pet1();
cw.pet1();
}
}
5.查询类
package 宠物商店;
import java.util.Scanner;
public class 查询类 {
public static void CX() {
Scanner scanner = new Scanner(System.in);
System.out.println("尊敬的顾客您好,我会为您提供最优的服务");
System.out.println("1:查询本店宠物种类\t2:查询本店宠物信息");
int n = scanner.nextInt();
if(n==1) {
System.out.println("尊敬的顾客,目前本店有:1、宠物狗\t2、宠物猫");
}
if(n==2) {
System.out.println("请输入您要查询宠物的种类信息:");
String name = scanner.next();
if(name.equals("狗")||name.equals("gou")) {
System.out.println("本店提供"+name+"的品种为:");
商店类.doug1.pet1();
商店类.doug2.pet1();
商店类.doug3.pet1();
商店类.doug4.pet1();
}
else if(name.equals("猫")||name.equals("mao")) {
System.out.println("本店提供"+name+"的品种为:");
商店类.cat1.pet1();
商店类.cat2.pet1();
}
else {
System.out.println("给常抱歉,本店不能提供你所需要的宠物:"+name);
}
}
}
}
6.测试类
package 宠物商店;
import java.util.Scanner;
public class 测试类 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("**********欢迎来到宠物商店在线系统**********");
System.out.println("我们将为您提供最优秀的服务,请您做以下选择");
System.out.println("1:员工登录\t2:尊敬的顾客");
int i = scanner.nextInt();
if(i==1){
System.out.println("亲爱的员工您好,请选择您要进行的操作:");
System.out.println("1:对宠物进行上架操作\t2:对宠物进行下架操作");
int n = scanner.nextInt();
if(n==1) {
//转到上架类
上架类.SJ();
}
if(n==2) {
//转到下架类
下架类.XJ();
}
}
if(i==2) {
查询类.CX();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询