伊莉討論區

標題: 最后一題不會做 TwT [打印本頁]

作者: wilsontiang95    時間: 2018-4-11 11:15 PM     標題: 最后一題不會做 TwT

[attach]122963709[/attach]
求救 最后一題 不知道要做什麼


作者: codewice    時間: 2018-4-13 01:37 AM

看起來就是定義三個 class,Deposit 跟 SavingAccount 都要繼承 General,而且這三個 class 都要有三個 constructor,最直接的寫法可以是這樣
  1. class General {
  2.     String name;
  3.     String address;

  4.     General() {
  5.         this(null);
  6.     }

  7.     General(String name) {
  8.         this(name, null);
  9.     }

  10.     General(String name, String address) {
  11.         this.name = name;
  12.         this.address = address;
  13.     }

  14.     public void getDetails() {
  15.         // do nothing
  16.     }

  17.     public void setDetails() {
  18.         // do nothing
  19.     }

  20. }


  21. class SavingAccount extends General {
  22.     int accountNo;
  23.     int balance;

  24.     SavingAccount() {
  25.         this(0);
  26.     }

  27.     SavingAccount(int no) {
  28.         this(0, 0);
  29.     }

  30.     SavingAccount(int no, int balance) {
  31.         this.accountNo = no;
  32.         this.balance = balance;
  33.     }

  34.     public int getAccount() {
  35.         return 0;
  36.     }

  37.     public void setAccount() {
  38.         // do nothing
  39.     }

  40.     public void searchAccount() {
  41.         // do nothing
  42.     }
  43. }


  44. class Deposit extends General {
  45.     int receiptNo;
  46.     String date;
  47.     int amount;

  48.     Deposit() {
  49.         this(0);
  50.     }

  51.     Deposit(int no) {
  52.         this(0, 0);
  53.     }

  54.     Deposit(int no, int amount) {
  55.         this.receiptNo = no;
  56.         this.amount = amount;
  57.     }

  58.     public void setDeposit() {
  59.         // do nothing
  60.     }

  61.     public void printDeposit() {
  62.         // do nothing
  63.     }
  64. }
複製代碼

作者: wilsontiang95    時間: 2018-4-13 06:56 AM

codewice 發表於 2018-4-13 01:37 AM
看起來就是定義三個 class,Deposit 跟 SavingAccount 都要繼承 General,而且這三個 class 都要有三個 con ...

感激不盡 大大




歡迎光臨 伊莉討論區 (http://www207.eyny.com/) Powered by Discuz!