gpt4 book ai didi

java - 为什么我的构造函数中充满了 "shouldn' t"

转载 作者:行者123 更新时间:2023-11-29 08:26:29 26 4
gpt4 key购买 nike

<分区>

首先,对于宽泛的标题,我很抱歉,我不确定如何措辞。不管怎样,我正在制作一个允许多人拥有多个账户的银行程序。但是,每当一个新人创建一个帐户时,它就会将该帐户添加到其他所有人,这就是原因。我已经尝试了我能想到的一切,但没有运气。我知道可能不需要管理类,但这是我试图解决问题的方法之一。另外,最后两个类是关于支票和储蓄账户的,一旦我解决了这个问题,我就会完成这些类(class)。感谢任何帮助:)

import java.util.ArrayList;
import javax.swing.*;

class Bank implements Comparable {

private double bal;
private int accountNumber;
private String accountName;

public Bank() {
}

void display_details() {
System.out.println("Account Number : " + accountNumber);
System.out.println("Account Balance : " + bal + "\n\n\n");
JOptionPane.showMessageDialog(null,
"Account Name:" + accountName + "\nAccount Number : " + accountNumber + "\nAccount Balance : " + bal,
"You own " + FinancialFolk.Bank.size() + " account[s]", JOptionPane.INFORMATION_MESSAGE);
}

public void deposit(double depositAmount) {
bal += depositAmount;
JOptionPane.showMessageDialog(null, "Your new balance is: $" + bal);
}

public void withdraw(double withdrawAmount) {
if (withdrawAmount > bal) {
JOptionPane.showMessageDialog(null, "Insufficient Funds");
} else {
bal -= withdrawAmount;
JOptionPane.showMessageDialog(null, "Your new balance is: $" + bal);
}
}

public void transfer() {

}

@Override
public int compareTo(Object arg0) {
// TODO Auto-generated method stub
return 0;
}

public double getBal() {
return bal;
}

public void setBal(double baL) {
bal = baL;
}

public int getAccountNumber() {
return accountNumber;
}

public void setAccountNumber(int accountNumbe) {
accountNumber = accountNumbe;
}

public String getAccountName() {
return accountName;
}

/**
* @param accountName the accountName to set
*/
public void setAccountName(String accountName) {
this.accountName = accountName;
}

}

class FinancialFolk implements PasswordVerifivation {
private String accountUsername, accountHolderName, accountPassword;
protected ArrayList<Bank> accounts = new ArrayList<>();
protected static ArrayList<FinancialFolk> Bank = new ArrayList<>();
private int memberTime;

public FinancialFolk(String username, String name, String password) {
accountUsername = username;
accountHolderName = name;
accountPassword = password;
}

public FinancialFolk() {
accountUsername = "";
accountHolderName = "";
accountPassword = "";
}

public void passwordCreation() {
accountPassword = JOptionPane.showInputDialog("Please choose a secure password for your account.");
}

public boolean passwordVerify(String attemptedPassword) {
return accountPassword.equals(attemptedPassword);

}

public boolean createNewPerson() { // Creates a new FinancialFolk.
accountHolderName = (JOptionPane.showInputDialog("Please enter your name."));
if (accountHolderName == null)
return false;
String Username = (JOptionPane.showInputDialog("Please enter a username for your account."));
for (FinancialFolk fk : Bank) {
if (fk.getAccountUsername().equals(Username)) {
JOptionPane.showMessageDialog(null, "That username is taken!");
return false;
}
}
accountUsername = Username;
passwordCreation();
return true;
}

public void createNewAccount() { // Adds an account to an existing FinancialFolk.
Bank check = new Checking();
Bank save = new Savings();
String[] buttons = { "Checking", "Savings" };
int acc = JOptionPane.showOptionDialog(null, "What type of account would you like to make?", "Bank",
JOptionPane.PLAIN_MESSAGE, 1, null, buttons, buttons[1]);
switch (acc) {
case 0:
check.setAccountName((JOptionPane.showInputDialog("Please enter a name for this account.")));
check.setAccountNumber((int) (Math.random() * 3000 + 1091));
accounts.add(check);
check.display_details();
break;
case 1:
save.setAccountName((JOptionPane.showInputDialog("Please enter a name for this account.")));
save.setAccountNumber((int) (Math.random() * 3310 + 789));
accounts.add(save);
save.display_details();
break;
}
}

public static void main(String[] args) {
Bank user = new Bank();
FinancialFolk FF = new FinancialFolk();
boolean exit = false;
do {
String[] buttons = { "Create Account For The First Time", "Login", "Exit Bank", "" };
int rc = JOptionPane.showOptionDialog(null, "What would you like to do?", "Bank", JOptionPane.PLAIN_MESSAGE,
3, null, buttons, buttons[3]);
switch (rc) {
case 0: // create account
if (FF.createNewPerson()) {
Bank.add(FF);
Bank.get(Bank.size() - 1).createNewAccount();
}
break;
case 1: // login
boolean logout = false;
boolean incun = true;

String an = JOptionPane.showInputDialog("Enter your username.\n");
String ps = JOptionPane.showInputDialog("Enter your acccount password.\n");
for (FinancialFolk x : Bank) {
if (x.getAccountUsername().equals(an)) {
incun = false;
if (x.passwordVerify(ps)) {
do {
String[] buttons2 = { "View all accounts.", "Deposit into an account",
"Withdraw from your account", "Change password", "Create another bank account",
"Logout" };
int rc2 = JOptionPane.showOptionDialog(null, "What would you like to do?", "Bank",
JOptionPane.PLAIN_MESSAGE, 3, null, buttons2, buttons2[4]);
switch (rc2) {
case 0: // all accounts
int networth = 0;
for (Bank acct : FF.accounts) {
acct.display_details();
networth += acct.getBal();
}
JOptionPane.showMessageDialog(null,
"Your account total between all accounts: $" + networth);
break;
case 1: { // deposit
if (x.accounts.size() == 0)
JOptionPane.showMessageDialog(null, "You do not have any accounts!");
else if (x.accounts.size() == 1) {
x.accounts.get(0).deposit(Integer.parseInt(JOptionPane
.showInputDialog("Enter how many dollars you want to deposit.\n")));
} else {
JOptionPane.showMessageDialog(null, x.accounts.size());
String a = (JOptionPane
.showInputDialog("Enter the account name to deposit into.\n"));
for (Bank act : x.accounts) {
if (act.getAccountName().equalsIgnoreCase(a))
act.deposit(Integer.parseInt(JOptionPane.showInputDialog(
"Enter how many dollars you want to deposit.\n")));
}
}
}
break;
case 2:
if (x.accounts.size() == 0)
JOptionPane.showMessageDialog(null, "You do not have any accounts!");
else if (x.accounts.size() == 1) {
x.accounts.get(0).withdraw(Integer.parseInt(JOptionPane
.showInputDialog("Enter how many dollars you want to withdraw.\n")));
} else {
String a = (JOptionPane
.showInputDialog("Enter the account name to withdraw from.\n"));
for (Bank act : x.accounts) {
if (act.getAccountName().equalsIgnoreCase(a))
act.deposit(Integer.parseInt(JOptionPane.showInputDialog(
"Enter how many dollars you want to withdraw.\n")));
}
}
break;
case 3:
x.passwordSet((JOptionPane.showInputDialog("Enter your new password.\n")));
break;
case 4:
x.createNewAccount();
break;
case 5:
logout = true;
break;
}
} while (!logout);
} else
incun = true;
}
}
if (incun)
JOptionPane.showMessageDialog(null, "Invalid Username or password");
break;
case 2:
JOptionPane.showMessageDialog(null, "Thank you for using the JacoBank");
exit = true;
break;
case 3:
System.out.print(Bank.size());
System.out.print(FF.accounts.size());
break;

}
} while (!exit);
}

public String getAccountHolderName() {
return accountHolderName;
}

public void setAccountHolderName(String accountHolderName) {
this.accountHolderName = accountHolderName;
}

public String getAccountUsername() {
return accountUsername;
}

@Override
public void passwordSet(String password) {
accountPassword = password;

}
}

class Manage {

}

class Checking extends Bank {
private int checkCount;
}

class Savings extends Bank {
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com