1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | package cc.openhome; import java.util.*; public class CashCard { private String number; private int balance; private int bonus; Scanner in = new Scanner(System.in); public CashCard(String number, int balance, int bonus) { this.number = number; this.balance = balance; this.bonus = bonus; } public int store() { System.out.println("請輸入儲值金額:"); int store = in.nextInt(); bonus += store / 50; balance += store; System.out.println("目前餘額:" + balance); return balance; } public int charge() { System.out.println("請輸入扣款金額:"); int charge = in.nextInt(); balance -= charge; if (balance < 0) { System.out.println("error balance < 0"); } else { System.out.println("目前餘額:" + balance); } return balance; } public void getBalance() { System.out.println("目前餘額:" + balance); } public void getBonus() { System.out.println("目前紅利:" + bonus); } } package cc.util; import cc.openhome.*; import java.util.*; public class S401631741 { public static void main(String[] s) { int choise1 = 0 ; Scanner in = new Scanner(System.in); System.out.println("請輸入IDnumber"); String number = in.next(); System.out.println("請輸入初始金額"); int balance = in.nextInt(); System.out.println("請輸入初始紅利"); int bonus = in.nextInt(); CashCard c1 = new CashCard("number", balance, bonus); System.out.println("請選擇(1)儲值(2)扣款(3)顯示餘額(4)讀取紅利"); int choise = in.nextInt(); do{ if (choise == 1) { c1.store(); } else if (choise == 2) { c1.charge(); } else if (choise == 3) { c1.getBalance(); } else if (choise == 4) { c1.getBonus(); } else { System.out.println("error"); } System.out.println("(1)繼續(其他)離開") ; choise1 = in.nextInt() ;} while(choise1 == 1 ) ; } } |
Direct link: https://paste.plurk.com/show/1721235