Created
November 20, 2017 07:52
-
-
Save s16003/5d86caf5f79fb9297fa5251eea864d8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| class testMoneyBox { | |
| public static void main(String[] args) { | |
| MoneyBox moneyBox = new MoneyBox(); | |
| moneyBox.run(); | |
| moneyBox.show(); | |
| } | |
| } | |
| class MoneyBox { | |
| private int n; | |
| private int sum; | |
| private Scanner sc = new Scanner(System.in); | |
| private int[][] box = {{1000, 0}, {5000, 0}, {10000, 0}}; | |
| public void run() { | |
| while (true) { | |
| System.out.print("額面を入力: "); | |
| n = sc.nextInt(); | |
| if (n == 0) { | |
| return; | |
| } | |
| if (n != 1000 && n != 5000 && n != 10000) { | |
| System.out.println("お札ではありません。"); | |
| continue; | |
| } | |
| put(n); | |
| } | |
| } | |
| private void put(int money) { | |
| switch (money) { | |
| case 1000: | |
| box[0][1]++; | |
| break; | |
| case 5000: | |
| box[1][1]++; | |
| break; | |
| case 10000: | |
| box[2][1]++; | |
| break; | |
| } | |
| } | |
| public void show() { | |
| for (int i = 0; i < box.length; i++) { | |
| System.out.printf("%d円札の数:%d\n", box[i][0], box[i][1]); | |
| sum += box[i][0] * box[i][1]; | |
| } | |
| System.out.printf("合計は%d円\n", sum); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment