Guest User

Untitled

a guest
Nov 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class testMoneyBox {
  4. public static void main(String[] args) {
  5. MoneyBox moneyBox = new MoneyBox();
  6.  
  7. moneyBox.run();
  8. moneyBox.show();
  9.  
  10. }
  11. }
  12.  
  13. class MoneyBox {
  14. private int n;
  15. private int sum;
  16. private Scanner sc = new Scanner(System.in);
  17. private int[][] box = {{1000, 0}, {5000, 0}, {10000, 0}};
  18.  
  19. public void run() {
  20. while (true) {
  21. System.out.print("額面を入力: ");
  22. n = sc.nextInt();
  23.  
  24. if (n == 0) {
  25. return;
  26. }
  27.  
  28.  
  29. if (n != 1000 && n != 5000 && n != 10000) {
  30. System.out.println("お札ではありません。");
  31. continue;
  32. }
  33.  
  34. put(n);
  35. }
  36. }
  37.  
  38. private void put(int money) {
  39. switch (money) {
  40. case 1000:
  41. box[0][1]++;
  42. break;
  43. case 5000:
  44. box[1][1]++;
  45. break;
  46. case 10000:
  47. box[2][1]++;
  48. break;
  49. }
  50. }
  51.  
  52. public void show() {
  53. for (int i = 0; i < box.length; i++) {
  54. System.out.printf("%d円札の数:%d\n", box[i][0], box[i][1]);
  55. sum += box[i][0] * box[i][1];
  56. }
  57. System.out.printf("合計は%d円\n", sum);
  58. }
  59. }
Add Comment
Please, Sign In to add comment