5-2习题代码的实现,不知行不行,望大家给点建议!!

释放双眼,带上耳机,听听看~!

package Test2;

import java.util.Scanner;

public class Intail extends Human {
static Human ch= new Chinese();
static Human am = new American();
static Human ger = new Germany();

public static void main(String[] args) {
    System.out.println("请输入您要查询的国家");
    Scanner input = new Scanner(System.in);
    String  words = input.next();
 switch (words) {
case "Chinese":
   ch.speak();
    break;
case"American":
    am.speak();
    break;
case"Germany":
    ger.speak();
    break;

default:
    System.out.println("您的输入有问题!!");
    break;
}

}
}

package Test2;

public class Human{
public String skilColor ;
public String liveLocation ;
public String language;
public String countryName;

public void speak(){
    System.out.println("人可以用语言交流");
}

}

package Test2;

public class Chinese extends Human {
public String skilColor = “黄色”;
public String liveLocation= “亚洲” ;
public String language= “汉语”;
public String capital = “北京”;

@Override
public void speak() {
    // TODO Auto-generated method stub
          System.out.println("chinese的基本资料"); 
          System.out.println("skilColor:"+skilColor);
          System.out.println("liveLocation:"+liveLocation);
          System.out.println("language:"+language);
          System.out.println("capital"+capital);
}

}

package Test2;

public class American extends Human {
public String skilColor = “白色,黑色,黄色” ;
public String liveLocation =”北美洲”;
public String language= “English”;
public String capital =”华盛顿”;
@Override
public void speak() {
// TODO Auto-generated method stub
System.out.println(“American的基本资料”);
System.out.println(“skilColor:”+skilColor);
System.out.println(“liveLocation:”+liveLocation);
System.out.println(“language:”+language);
System.out.println(“capital:”+capital);
}

}

package Test2;

import java.security.PublicKey;

public class Germany extends Human {
public String skilColor = “白色”;
public String liveLocation= “欧洲中部” ;
public String language =”German”;
public String capital =”柏林”;

@Override
public void speak() {
    // TODO Auto-generated method stub
      System.out.println("Germany的基本资料"); 
    System.out.println("skilColor:"+skilColor);
    System.out.println("liveLocation:"+liveLocation);
    System.out.println("language:"+language);
    System.out.println("capiyal"+ capital);
}

}

【转自慕课】https://www.imooc.com

JAVA

嗒嗒租车系统深夜无聊版

2022-3-3 18:58:58

JAVA

“JDBC之对岸的女孩走过来”第二章代码整理

2022-3-3 18:59:36

搜索