[Java] 138-打球过程 →→→→→进入此内容的聊天室

来自 , 2020-06-18, 写在 Java, 查看 135 次.
URL http://www.code666.cn/view/a51c896c
  1. import java.util.Scanner;
  2. public class Main{
  3.     public static void main(String[] args) {
  4.          Scanner scan = new Scanner(System.in);    
  5.  
  6.          int no = scan.nextInt();
  7.          String score = scan.next();    
  8.          if( no == 1)
  9.          {
  10.                  FootballMatch f = new FootballMatch(score);
  11.                  f.checkin();
  12.              f.start();
  13.              f.play();
  14.              f.end();
  15.              f.annouceResult();
  16.          }
  17.         else
  18.         {
  19.                 BasketBallMatch b= new BasketBallMatch(score);
  20.             b.checkin();
  21.             b.start();
  22.             b.play();
  23.             b.end();
  24.             b.annouceResult();
  25.         }
  26.          scan.close();
  27.     }
  28. }
  29. abstract class BallMatch
  30. {
  31.         public void checkin()
  32.         {
  33.                 System.out.println("now checking in");
  34.         }
  35.         public void start()
  36.         {
  37.                 System.out.println("now starting");
  38.         }
  39.         abstract public void play();
  40.         public void end()
  41.         {
  42.                 System.out.println("now ending");
  43.         }
  44.         abstract public void annouceResult();
  45. }
  46. class FootballMatch extends BallMatch
  47. {
  48.         private String score;
  49.         public FootballMatch(String s)
  50.         {
  51.                 score = s;
  52.         }
  53.         public void play()
  54.         {
  55.                 System.out.println("now playing football");
  56.         }
  57.         public void annouceResult()
  58.         {
  59.                 System.out.print("now annoucing result: ");
  60.                 System.out.println(score);
  61.         }
  62. }
  63. class BasketBallMatch extends BallMatch
  64. {
  65.         private String score;
  66.         public BasketBallMatch(String s)
  67.         {
  68.                 score = s;
  69.         }
  70.         public void play()
  71.         {
  72.                 System.out.println("now playing basketball");
  73.         }
  74.         public void annouceResult()
  75.         {
  76.                 System.out.print("now annoucing result: ");
  77.                 System.out.println(score);
  78.         }
  79. }

回复 "138-打球过程"

这儿你可以回复上面这条便签

captcha