Bankkonto client in java mit mehreren Klassen

Ich versuche, ein Konto Programm, aber ich kann nicht herausfinden, wie man alle meine Variablen sichtbar zu jeder Klasse, die ich habe, oder wie man einen Rückzug und Einzahlungsmethoden meinem code sichtbar. Kann jemand Blick auf meine code und sagt mir, was ist falsch? Ich möchte nur input und output in der client-Klasse.

Dank

Client-Klasse

public class Client {
  public static void main(String args[]) {
    Scanner input = new Scanner(System.in);       
    System.out.println("Enter your Name: ");
    String cusName = input.nextLine();
    System.out.println("Enter Account Type: ");
    String type = input.next();
    System.out.println("Enter Initial Balance: ");
    int bal = input.nextInt();
    BankAccount b1 = new BankAccount(cusName, num, type, bal);
    int menu;
    System.out.println("Menu");
    System.out.println("1. Deposit Amount");
    System.out.println("2. Withdraw Amount");
    System.out.println("3. Display Information");
    System.out.println("4. Exit");
    boolean quit = false;
    do {
      System.out.print("Please enter your choice: ");
      menu = input.nextInt();
      switch (menu) {
      case 1:
        b1.deposit();
        break;

      case 2:
        b1.withdraw();
        System.out.println("Current Account Balance=" + Balance);
        System.out.print("Enter withdrawal amount:");
        amount = input.nextInt();
        break;

      case 3:
        b1.display();
        break;

      case 4:
        quit = true;
        break;
      }
    } while (!quit);
  }
}

Geld, Klasse

public class Money
{

  static int accountNumber, Balance, amount;
  Scanner input = new Scanner(System.in);
  static String name, actype;
  public int deposit() {
    System.out.print("Enter depost amount:");
    amount = input.nextInt();
    if (amount < 0) {
      System.out.println("Invalid");
      return 1;
    }
    Balance = Balance + amount;
    return 0;
  }

  int withdraw()  {

    if (Balance < amount) {
      System.out.println("Not enough funds.");
      return 1;
    }
    if (amount < 0) {
      System.out.println("Invalid");
      return 1;
    }
    Balance = Balance - amount;
    return 0;
  }

}

BankAccount-Klasse

class BankAccount {
  Scanner input = new Scanner(System.in);
  static String name, actype;
  static int bal, amt;
  Random randomGenerator = new Random();
  int accNo = randomGenerator.nextInt(100);

  BankAccount(String name, int accNo, String actype, int bal) {
    this.name = name;
    this.accNo = accNo;
    this.actype = actype;
    this.bal = bal;
  }
  void display() {
    System.out.println("Name:" + name);
    System.out.println("Account No:" + accNo);
    System.out.println("Balance:" + bal);

  }

  void dbal() {
    System.out.println("Balance:" + bal);
  }
}
  • Letzte Woche waren es die Studenten Hausaufgaben, die es in dieser Woche scheint der Bankverbindung Hausaufgaben
Schreibe einen Kommentar