petshop java_petshop.java[通俗易懂]

petshop java_petshop.java[通俗易懂]importjava.util.Scanner;classPet{privateintnumber;privateStringvariety;privateStringcolor;privateintage;privateintprice;publicPet(intnumber,Stringvariety,Stringcolor,intage,intprice)…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

import java.util.Scanner;

class Pet{

private int number;

private String variety;

private String color;

private int age;

private int price;

public Pet(int number,String variety,String color,int age,int price){

this.setNumber(number);

this.setVariety(variety);

this.setColor(color);

this.setAge(age);

this.setPrice(price);

}

public int getNumber(){

return number;

}

public void setNumber(int number){

this.number=number;

}

public String getVariety(){

return variety;

}

public void setVariety(String variety){

this.variety=variety;

}

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 int getPrice(){

return price;

}

public void setPrice(int price){

this.price=price;

}

public String toString() {

return this.getNumber()+”\t”+this.getVariety()+”\t”+this.getColor()+

“\t”+this.getAge()+”岁\t”+this.getPrice()+”元”;

}

}

class Dog extends Pet{

private String SmallOrLarge;

private int CountDog;

private int DogPrice;

public Dog(int number,String variety,String color,int age,int price,String sol){

super(number,variety,color,age,price);

this.setSmallOrLarge(sol);

}

public void setSmallOrLarge(String sol){

this.SmallOrLarge=sol;

}

public String getSmallOrLarge(){

return SmallOrLarge;

}

public void setCountDog(int cd){

this.CountDog=cd;

}

public int getCountDog(){

return CountDog;

}

public void setDogPrice(int dp){

this.DogPrice=dp;

}

public int getDogPrice(){

return DogPrice;

}

public String toString1() {

return “狗:\t”+super.getNumber()+”\t”+super.getVariety()+”\t”+super.getColor()+

“\t”+super.getAge()+”岁\t”+super.getPrice()+”\t\t”+this.getSmallOrLarge();

}

public String toString() {

return “狗:\t”+super.getNumber()+”\t”+super.getVariety()+”\t”+super.getColor()+

“\t”+super.getAge()+”岁\t”+super.getPrice()+”\t\t”+this.getSmallOrLarge()+

“\t共”+this.getCountDog()+”只\t”+this.getDogPrice();

}

}

class Cat extends Pet{

private int CountCat;

private int CatPrice;

public Cat(int number,String variety,String color,int age,int price){

super(number,variety,color,age,price);

}

public void setCountCat(int ct){

this.CountCat=ct;

}

public int getCountCat(){

return CountCat;

}

public void setCatPrice(int cp){

this.CatPrice=cp;

}

public int getCatPrice(){

return CatPrice;

}

public String toString1() {

return “猫:\t”+super.getNumber()+”\t”+super.getVariety()+”\t”+super.getColor()+

“\t”+super.getAge()+”岁\t”+super.getPrice()+”元”;

}

public String toString() {

return “猫:\t”+super.getNumber()+”\t”+super.getVariety()+”\t”+super.getColor()+

“\t”+super.getAge()+”岁\t”+super.getPrice()+”\t\t\t共”+this.getCountCat()+

“只\t”+this.getCatPrice();

}

}

class Buy {

private Pet buy[];

public Buy(){};

public Pet[] getPet() {

return buy;

}

public void setPet(Pet[] buy) {

this.buy = buy;

}

}

public class InterfaceForUsers {

public static void main(String args[]){

int j=0;

Pet[] temp=new Pet[10];

Buy buy=new Buy();

Scanner input=new Scanner(System.in);

int choose1,choose2,choose3;

String choose4=”n”;

int price=0;

Dog dogs[]={

new Dog(1,”哈士奇”,”黑白色”,5,200,”大型犬”),

new Dog(2,”藏獒”,”棕色”,6,500,”大型犬”),

new Dog(3,”吉娃娃”,”黑色”,3,100,”小型犬”)

};

Cat cats[]={

new Cat(1,”黑猫”,”黑色”,5,200),

new Cat(2,”白猫”,”白色”,6,300),

new Cat(3,”大脸猫”,”白色”,6,300),

new Cat(4,”机器猫”,”蓝色”,20,1000)

};

int [] countdog=new int[dogs.length];

int [] countcat=new int[cats.length];

System.out.println(“*****欢迎使用宠物商店*****”);

System.out.println(“本店设有狗类和猫类供您选择:\n”);

do{

if(j==9){

System.out.println(“您一次只可以购买10只宠物哦!”);

break;

}

System.out.println(“狗类:\n”);

System.out.println(“宠物\t编号\t类型\t颜色\t年龄\t价格(单位:元)\t备注”);

for(int i=0;i

System.out.println(dogs[i].toString1());

}

System.out.println(“\n猫类:\n”);

System.out.println(“宠物\t编号\t类型\t颜色\t年龄\t价格(单位:元)\t备注”);

for(int i=0;i

System.out.println(cats[i].toString1());

}

System.out.println(“请选择购买:1.狗类 2.猫类 \n请输入编号”);

choose1=input.nextInt();

switch(choose1){

case 1:

System.out.println(“请输入宠物狗编号:”);

choose2=input.nextInt();

countdog[choose2-1]++;

break;

case 2:

System.out.println(“请输入宠物猫编号:”);

choose2=input.nextInt();

countcat[choose2-1]++;

break;

default:

System.out.println(“您侧输入有误,请重新输入:”);

break;

}

System.out.println(“下一步:1.继续购买 2.结束购买”);

choose3=input.nextInt();

if(choose3==1){

choose4=”n”;

}else if(choose3==2){

System.out.println(“是否退出?(y/n)”);

choose4=input.next();

}

}while(choose4.equals(“n”)==true || choose4.equals(“N”)==true);

for(int i=0;i

if(countdog[i]==0){

continue;

}else{

temp[j]=dogs[i];

j++;

dogs[i].setCountDog(countdog[i]);

dogs[i].setDogPrice(countdog[i]*dogs[i].getPrice());

price=price+dogs[i].getDogPrice();

}

}

for(int i=0;i

if(countcat[i]==0){

continue;

}else{

temp[j]=cats[i];

j++;

cats[i].setCountCat(countcat[i]);

cats[i].setCatPrice(countcat[i]*cats[i].getPrice());

price=price+cats[i].getCatPrice();

}

}

buy.setPet(temp);

System.out.println(“您所选择的宠物有:”);

System.out.println(“宠物\t编号\t类型\t颜色\t年龄\t价格(单位:元)\t备注\t数量\t共计(单位:元)”);

for(int i=0;i

System.out.println(buy.getPet()[i].toString());

}

System.out.println(“共计:”+price+”元”);

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181143.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux 软连接「建议收藏」

    Linux 软连接「建议收藏」1.Linux链接概念Linux链接分两种,一种被称为硬链接(HardLink),另一种被称为符号链接(SymbolicLink)。默认情况下,ln命令产生硬链接。【硬连接】硬连接指通过索引节点来进行连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(InodeIndex)。在Linux中,多个文件名指向同一索引节点是存在的。一

    2022年9月30日
    2
  • 值得收藏:一份非常完整的 MySQL 规范(一)[通俗易懂]

    值得收藏:一份非常完整的 MySQL 规范(一)

    2022年2月13日
    43
  • app制作好后怎么上线_app如何上线到应用市场

    app制作好后怎么上线_app如何上线到应用市场自己开发一款APP上线前的步骤问题额,是这样的,一款App想要上线的话,是不需要跟国家部分打交道的。你需要的是和其他公司去打交道。比如说苹果的App,你想在APPstr上线的话,首先你要有一个开发者账号。这个账号是直接跟美国苹果公司申请的,费用是99美元一年。申请的时间大约是一个月左右。账号下来了之后,就可以上传安装包,苹果公司会审核这款App,值得一提的是,苹果公司的审核机制很严格,审核的时间…

    2025年6月21日
    2
  • AdminLTE框架的基本使用

    AdminLTE框架的基本使用框架介绍:AdminLTE是一个完全响应管理模板。基于Bootstrap3,jQuery3.3.1这两个框架框架,易定制模板。适合多种屏幕分辨率,从小型移动设备到大型台式机。内置了多个页面,包括仪表盘、邮箱、日历、锁屏、登录及注册、404错误、500错误等页面。对于后台站点的模板渲染,有很大的作用。下载可以使用gitclone到本地gitclonehttp…

    2022年7月27日
    12
  • 二进制与或非逻辑计算机,深度学习(1):给感知机做准备,谈谈二进制和与或非门。…

    二进制与或非逻辑计算机,深度学习(1):给感知机做准备,谈谈二进制和与或非门。…过去的五年 人工智能已经是最热门的话题 从理论的完善到实践工具的丰富 慢慢发现 AI 已不再是专属于实验室的一种研究 每一个对此有兴趣的人都能自己动手在自己的电脑上完成属于自己的研究 本系列文章希望从零起步 帮助建立从理论到实践的深度学习知识 而读者不必担心自己的知识储备 只要你会打开电脑从头开始看就足以完成学习 万事开头难 实现人工智能的第一步 我准备先谈谈感知机 Perceptron 的实现 而

    2025年9月4日
    0
  • MySQL使用SQL语句修改表名

    MySQL使用SQL语句修改表名MySQL中可以使用renametable这个SQL语句来修改表名。renametable这个SQL语句来修改表名的基本语法是:RENAMETABLE<旧表名>TO<新表名>;我们来把test表修改为test1表。1、首先查看一下当前数据库中有哪些表。mysql>showtables;+——————-+…

    2022年5月6日
    56

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号