代码实现:
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:查询本店宠物信息");
推荐阅读
- 天权运营直播,天权星传媒
- 视频年鉴是什么意思,视频鉴定
- 买服务器赚,买服务器违法吗
- oracle增加索引表空间,oracle数据库如何添加索引
- go语言条件判断 go 类型判断
- cad的坐标怎么转到gis中xy坐标反,cad坐标转gps坐标
- win7做服务器,win7电脑做服务器
- ppt怎么裁剪阴影部分,如何用ppt裁剪功能裁剪出奇妙效果
- mysql中的外键怎么用 mysql 外键的作用