返回列表 發帖
本帖最後由 李知易 於 2016-7-8 21:00 編輯
  1. public class Ch59
  2. {
  3.     public static void main(String args[])
  4.     {
  5.          Gun g1=new Gun("恐懼惡魔",165,105);
  6.          Gun g2=new Gun("狂龍awp",160,100);
  7.          Gun g3=new Gun("m82a1",145,96);
  8.          Gun g4=new Gun("m200",136,95);

  9.          g1.showProfile();
  10.          g1.makeSound(6);
  11.          g2.showProfile();
  12.          g2.makeSound(5);
  13.          g3.showProfile();
  14.          g3.makeSound(4);
  15.          g4.showProfile();
  16.          g4.makeSound(3);

  17.     }
  18. }
  19. class Gun
  20. {
  21.     String name;
  22.     int a;
  23.     int g;


  24.     Gun(String n, int a, int g)
  25.     {
  26.         name=n;
  27.         this.a=a;
  28.         this.g=g;
  29.     }
  30.     void showProfile()
  31.     {
  32.         System.out.println(name+"的傷害為:"+a+" , 精度為:"+g);
  33.     }
  34.     void makeSound(int n)
  35.     {
  36.        for(int i=1;i<=n;i++)
  37.            System.out.print("碰~");
  38.        System.out.println();
  39.     }
  40. }
複製代碼

TOP

返回列表