返回列表 發帖
  1. package ch79;
  2. public class ch79 {

  3.     public static void main(String[] args) {
  4.         Human h1=new Human("湯尼","專業級","新手級","新不了情","父親","照顧小孩",35,70);
  5.         h1.showProfile();
  6.         h1.eat(0.85);
  7.         h1.showProfile();
  8.         h1.swim(1500.0);
  9.         h1.singProfile();
  10.         h1.homeProfile();
  11.     }

  12. }

  13. abstract class Animal
  14. {
  15.     int age;
  16.     double w;
  17.     Animal(int age,double w)
  18.     {
  19.         this.age=age;
  20.         this.w=w;
  21.     }
  22.     abstract void eat(double x);
  23.     abstract void showProfile();
  24. }

  25. class Human extends Animal
  26. {
  27.     String name,good,bad,song,character,thing;
  28.     Human(String name,String good,String bad,String song,String character,String thing,int age,double w)
  29.     {
  30.         super(age,w);      
  31.         this.name=name;
  32.         this.good=good;
  33.         this.bad=bad;
  34.         this.song=song;
  35.         this.character=character;
  36.         this.thing=thing;
  37.     }
  38.     void eat(double x)
  39.     {
  40.         System.out.println(name+"咕嚕咕嚕吃下了"+x+"公斤的食物.");
  41.         w+=x;
  42.     }
  43.     void showProfile()
  44.     {
  45.         System.out.println(name+"今年幾歲,體重"+w+"公斤.");   
  46.     }
  47.     void swim(double y)
  48.     {
  49.             System.out.println(name+"以"+good+"水準,刷刷刷快速的游了"+y);
  50.     }
  51.     void singProfile()
  52.     {
  53.             System.out.println(name+"以"+good+"水準,唱了一首"+song);
  54.     }
  55.     void homeProfile()
  56.     {
  57.             System.out.println(name+"以"+bad+"水準,開始扮演"+character+"的角色"+thing);
  58.     }
  59.    
  60. }
複製代碼

TOP

  1. package ch79;

  2. public class ch79 {

  3.     public static void main(String[] args) {
  4.         Human h1=new Human("湯尼",35,70);
  5.         h1.showProfile();
  6.         h1.eat(0.85);        
  7.         h1.showProfile();
  8.         h1.swim(1500);
  9.         h1.sing("心不了情");
  10.         h1.takeCare();
  11.     }

  12. }

  13. abstract class Animal
  14. {
  15.     int age;
  16.     double w;
  17.     Animal(int age,double w)
  18.     {
  19.         this.age=age;
  20.         this.w=w;
  21.     }
  22.     abstract void eat(double x);
  23.     abstract void showProfile();
  24. }
  25. interface Swimmer
  26. {
  27.            String Level="專業及";
  28.            void swim(double x);
  29. }
  30. interface Singer
  31. {
  32.        String Level="專業及";           
  33. }
  34. interface Father
  35. {
  36.        String Level="新手及";
  37.        void takeCare();
  38. }

  39. class Human extends Animal
  40. {
  41.     String name;
  42.     Human(String name,int age,double w)
  43.     {
  44.         super(age,w);      
  45.         this.name=name;
  46.     }
  47.     void eat(double x)
  48.     {
  49.         System.out.println(name+"咕嚕咕嚕吃下了"+x+"公斤的食物.");
  50.         w+=x;
  51.     }
  52.     void showProfile()
  53.     {
  54.         System.out.println(name+"今年幾歲,體重"+w+"公斤.");   
  55.     }
  56.     public void  swim(double x)
  57.     {
  58.             System.out.println(name+"以"+Swimmer.Level+"水準,刷刷刷快速游了"+x+"公尺");
  59.            
  60.     }
  61.     public void sing(String song)
  62.     {
  63.             System.out.println(name+"以"+Singer.Level+"水準,唱了首"+song+".");
  64.     }
  65.     public void takeCare()
  66.     {
  67.             System.out.println(name+"以"+Father.Level+"水準,開始扮演父親的角色,照顧小孩");
  68.     }
  69.    
  70.    
  71. }
複製代碼

TOP

返回列表