fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. 銀行口座 カラカラ口座 = new 銀行口座(100000);
  7. カラカラ口座.set名義("カラカラ");
  8. カラカラ口座.set口座番号(1234567);
  9. カラカラ口座.showInfomation();
  10. System.out.print("引き出す金額を入力:");
  11. int money = sc.nextInt();
  12. カラカラ口座.drawingMoney(money);
  13. カラカラ口座.showInfomation();
  14. }
  15. }
  16.  
  17. class 銀行口座 {
  18. private int 口座番号;
  19. private String 名義;
  20. private int 預金残高 = 0;
  21.  
  22. public 銀行口座(int money) {
  23. 預金残高 = money;
  24. }
  25.  
  26. public int get口座番号() {
  27. return 口座番号;
  28. }
  29.  
  30. public void set口座番号(int number) {
  31. 口座番号 = number;
  32. }
  33.  
  34. public String get名義() {
  35. return 名義;
  36. }
  37.  
  38. public void set名義(String name) {
  39. 名義 = name;
  40. }
  41.  
  42. public int get預金残高() {
  43. return 預金残高;
  44. }
  45.  
  46. public void set預金残高(int money) {
  47. 預金残高 = money;
  48. }
  49.  
  50. public boolean drawingMoney(int money) {
  51. boolean check = money <= 預金残高;
  52. if (check) {
  53. 預金残高 -= money;
  54. } else {
  55. System.out.println("預金残高を超える金額を引き出そうとしましたので、引き出すことはできません");
  56. }
  57. return check;
  58. }
  59.  
  60. public void showInfomation() {
  61. System.out.printf("口座番号:%d%n名義:%s%n預金残高:%d円%n",
  62. 口座番号, 名義, 預金残高);
  63. }
  64. }
  65.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty