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);
}

}

点赞