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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 9300反编译apk「建议收藏」

    9300反编译apk「建议收藏」1.首先,下载这货apktool_ics_jb_imobile.com.cn.rar(7.39MB,下载次数:589)奇怪版本的apktool,由1.4.2和1.4.4版混和而成2.请确保你已经安装了JDK,还有WinRAR之类的解压软件,如果没有自行解决吧3.将下载好的东西解压到某个文件夹里,如图(文件以压缩包实际所含文件为准,此图仅示意,下同):…

    2022年9月16日
    2
  • 永磁同步电机矢量控制(四)——simulink仿真搭建

    永磁同步电机矢量控制(四)——simulink仿真搭建由于是初学,对于simulink很多地方不熟悉,在此记下整个仿真搭建的选择元件的细节。1电机模型的选择及参数设置永磁同步电机的英文缩写为PMSM,全称PermanentMagnetSynchronousMachine。在library内搜索Permanent即可找到它。Numberofphase电机相数Back…

    2022年6月4日
    70
  • C语言switch语句的用法详解_c语言switch语句例题

    C语言switch语句的用法详解_c语言switch语句例题C语言虽然没有限制ifelse能够处理的分支数量,但当分支过多时,用ifelse处理会不太方便,而且容易出现ifelse配对出错的情况。例如,输入一个整数,输出该整数对应的星期几的英文表示:#includeintmain(){inta;printf(“Inputintegernumber:”);scanf(“%d”,&a);if(a==1){printf(“Mo…

    2022年8月30日
    2
  • 纯净版系统怎么安装_纯净版安装版win7

    纯净版系统怎么安装_纯净版安装版win7百度网盘下载:1.链接:https://pan.baidu.com/s/1o-HcKddSG6IAz_0COKhq8Q提取码:hkhr2.扫码下载:

    2022年8月4日
    5
  • Java 并发编程中的死锁 ( Kotlin 语言讲解)

    Java 并发编程中的死锁 ( Kotlin 语言讲解)什么是死锁?在操作系统中的并发处理场景中,进程对资源的持有与请求过程中,会产生死锁.Say,ProcessAhasresourceR1,ProcessBhasresourceR2.IfProcessArequestresourceR2andProcessBrequestsresourceR1,atthesametime,thend…

    2022年7月16日
    15
  • 电商网站的搭建研究报告_连连跨境电商网站构建

    电商网站的搭建研究报告_连连跨境电商网站构建电商网站的搭建研究Researchontheconstructionofe-commercewebsite摘要互联网给全世界提供了最强大的网络平台,在互联网上不仅能同时快速传递大量的信息(数据、文件),而且还实现了网络营销、电子支付,提供各种新型的服务。经济全球化的发展态势和全球经济贸易的规模发展迫切需要一种新型的经济运作模式和商业运营模式。随着互联网的普及,还有各大电商平…

    2022年10月1日
    2

发表回复

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

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