java
1 2 private String shopName; 3 4 private String[] commodityList; 5 6 private final int PRICE = 100; 7 8 private int totalMoney; 9 10 11 12 public OneHundredYenShop(String shopName){ 13 14 this.shopName = shopName; 15 } 16 17 18 19 public void setCommodity(String[] commodity){ 20 21 this.commodityList = commodity; 22 } 23 24 25 public void sayHello(){ 26 27 System.out.println(this.shopName + "へようこそ!"); 28 } 29 30 public String getCommodity(int no, int money){ 31 32 String msg = ""; 33 34 if(no < this.commodityList.length){ 35 36 if(this.jugeMoney(money)){ 37 38 String comoddityName = this.commodityList[no]; 39 40 int oturi = money - this.PRICE; 41 42 msg = "おつりは" + oturi + "円です" + comoddityName + "のお買い上げです。"; 43 44 this.totalMoney += this.PRICE; 45 46 }else{ 47 msg = "お金が足りません"; 48 } 49 50 }else{ 51 52 msg = "該当する商品はありません。"; 53 } 54 return msg; 55 } 56 57 public boolean jugeMoney(int money){ 58 59 boolean flg = false; 60 61 if(money >= this.PRICE){ 62 63 flg = true; 64 } 65 return flg; 66 } 67 68 69 public void showTotalMoney(){ 70 71 System.out.println(this.shopName +"の売り上げは" + this.totalMoney + "円です"); 72 73 }
このソースに更にでお釣りをちょうどもらったときに「お釣りをちょうどいただきました。購入した商品は○○です。と表示したのですが、どこに条件を指定してあげればわかりません。
よろしければ、教えてください。
説明がへたくそですみません。
回答1件
あなたの回答
tips
プレビュー