Я создаю банковскую программу.Я должен быть в состоянии внести, снять, просмотреть баланс, а затем, конечно, выйти.
Моя проблема в том, что мы еще не просмотрели массивы, и это то, что я пытаюсь использовать.Когда я инициализирую массив с [0], поскольку это только один тип данных за раз, я получаю: Исключение в потоке "main" java.lang.ArrayIndexOutOfBoundsException: 0
Так что мой вопрос, как я могубыть в состоянии сделать это, изменяя баланс, пока пользователь не выйдет.Я немного застрял ...
Любая помощь приветствуется, и я заранее прошу прощения за грязный код.
Спасибо всем за помощь.Я поставил: double [] balance = New Double [1];
Но теперь я возвращаюсь к проблеме, что я не могу продолжать модифицировать массив с большим количеством депозитов и выводов.Я инициализирую его обратно в 0.0.
Может ли кто-нибудь указать мне правильное направление?
Основной класс:
public class Project3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Introduction();
Banking obj1 = new Banking();
}
public static void Introduction()
{
//this message tells the user exactly what this program does.
JOptionPane.showMessageDialog(null,
"This is a small conversion program which allows you to do "
+ "\nDeposit "
+ "\nWithdrawl."
+ "\nView Balance."
+ "\nExit",
"Conversion Calculator",
JOptionPane.INFORMATION_MESSAGE);
}
}
Класс:
public class Banking
{
double deposit;
double newbalance;
double[] balance = new double[0];
public Banking()
{
Menu();
}
public void Menu()
{
JDialog.setDefaultLookAndFeelDecorated(true);
Object[] selectionValues = { "Deposit", "Withdrawl"};
String initialSelection = "Deposit";
Object selection = JOptionPane.showInputDialog(null, "Would you like to "
+ "do today?",
"Home Banking Selection Screen", JOptionPane.PLAIN_MESSAGE, null, selectionValues, initialSelection);
// If statements used to call the method selected
if (selection == "Deposit")
Deposit();
if (selection == "Withdrawl")
Withdrawl();
}
public void Deposit()
{
balance[0] = Double.parseDouble(JOptionPane.showInputDialog(null,
"Please enter the total number of degrees in Fahrenheit to be Converted into Celcius? and press 'Ok'",
"Deposit",
JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null,
"You doposited $ " +balance+ "\n You now have $" ,
"The End",
JOptionPane.PLAIN_MESSAGE);
JDialog.setDefaultLookAndFeelDecorated(true);
Object[] selectionValues = { "Continue with more transactions", "Exit"};
String initialSelection = "Deposit";
Object selection = JOptionPane.showInputDialog(null, "Would you like to "
+ "do today?",
"Home Banking Selection Screen", JOptionPane.PLAIN_MESSAGE, null, selectionValues, initialSelection);
// If statements used to call the method selected
if (selection == "Continue witl more transactions")
Menu();
if (selection == "Exit")
Exit();
}
public void Withdrawl()
{
JOptionPane.showMessageDialog(null,
" Will be Withdrawl!", //Message to tell the user the program has ended
"2",
JOptionPane.PLAIN_MESSAGE);
}
public void Exit()
{
JOptionPane.showMessageDialog(null,
" Thank you and have a great day!", //Message to tell the user the program has ended
"The End",
JOptionPane.PLAIN_MESSAGE);
}
}