我有一個問題,我想我知道答案但我不太確定。我將如何撥打和存儲此信息
所以我做了這個節目,以下是賬戶類,並使用它
賬戶類
import java.util.Scanner;
import java.util.UUID;
public class Account {
double balance;
String name;
UUID AcctN;
int pin;
public void Account()
{
UUID idOne = UUID.randomUUID();
Scanner sc = new Scanner (System.in);
Scanner sa = new Scanner (System.in);
System.out.println ("Your starting balance is 0.0");
double initBal = 0;
balance = initBal;
System.out.println ("Enter your full name");
String owner = sa.nextLine();
name = owner;
UUID number = idOne;
AcctN = number;
System.out.println ("Enter your pin number containing ONLY 4 numbers");
int pins = sc.nextInt();
pin = pins;
}
public void withdraw (double amount)
{
if (balance <= 0)
{
System.out.println ("Insufficent funds");
}
else
{
balance -= amount;
}
}
public void deposit (double amount)
{
if (amount <= 0)
{
System.out.println ("You cannot deposit negative or 0 funds");
}
else
{
balance += amount;
}
}
public void withdrawfee (double amount)
{
if (balance <= 0)
{
System.out.println ("Insufficent funds");
}
else
{
double fee = 10;
balance -= amount + fee;
}
}
public double getBalance()
{
return balance;
}
public String toString()
{
return String.format ("User info: %s\n Balance: $%s\n Account Number: %s\n Pin Number: %s", name, balance, AcctN, pin);
}
}
主要類
import java.util.Scanner;
public class Tester {
public static void main (String [] args)
{
Scanner sc = new Scanner (System.in);
boolean quit = false;
Account ACT = new Account();
do
{
System.out.println ("Welcome to the Bank\n\n***********\n 1: Create account\n 2: Check accounts\n 3: Withdraw funds\n 4: Withdraw with fee\n 5: Deposit funds\n 6: Quit");
int input = sc.nextInt();
switch (input)
{
case 1:
System.out.println ("Make an account");
ACT.Account();
System.out.println ("Current information: ");
System.out.println (ACT.toString());
break;
case 2:
System.out.println (ACT.toString());
break;
case 3:
System.out.println ("How much do you wish to withdraw?");
ACT.withdraw(sc.nextDouble());
System.out.println ("Thank you for your service");
break;
case 4:
System.out.println ("How much do you wish to withdraw?");
ACT.withdrawfee(sc.nextDouble());
System.out.println ("An additional 10 dollars has been deducted from your account");
System.out.println ("Thank you for your service");
break;
case 5:
System.out.println ("How much do you wish to deposit");
ACT.deposit(sc.nextDouble());
System.out.println ("Thank you for your service");
break;
case 6:
quit = true;
break;
}
}while(!quit);
System.out.println ("Thank you for using the Bank..");
}
}
所以「創建賬戶開戶銀行計劃'適用於一個人,如果我再次創建它,那麼它只會覆蓋名稱和平衡。
所以,如果我想本質上存儲所有這些信息,我只需要使用一個數組?但那麼我將如何能夠呼叫每個用戶並從這些特定賬戶中提取/存入資金。
我想二叉搜索樹可能會工作,但同時我不確定一個簡單的數組列表是否會有效?
爲了澄清我希望我能夠
1)撥打一個特定的用戶,可能會不得不使用。載有()和我想的是,含有應該鏈接到一個特定的唯一帳戶ID 。
2)一旦到達該用戶,他們就能夠像當前一樣使用開關菜單。
這只是一個個人項目,有助於更好地理解Java如何工作,而不是作業。