The problem i am having is that i want to modify that line of code ( CASE 2 , LINE 49) so that i can understand it better, he wrote that single line of code because he's a guru. so i was wondering if i could break up that single line of code into something simpler to understand.
The whole program is 6 classes, if you need me to upload the other classes let me know, i didn't post it because it would lead to a lot of scrolling
Here is the code
import javax.swing.JOptionPane;
import java.util.ArrayList;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
class Client
{
public static void main(String[] arg)
{
boolean done = false;
final String menu;
menu ="1. New Account\n2. Make Deposit\n3. Make Withdrawal\n4. " +
"Close Account\n5. Show Active Accounts\n6. Show Closed Accounts\n7. Exit";
Database db = new Database();
Database close = new Database();
while (!done)
{
int option = GetData.getInt(menu);
switch (option)
{
case 1: // NEW ACCOUNT
String last = GetData.getWord("Enter last name:");
String first = GetData.getWord("Enter first name:");
String street = GetData.getWord("Enter street address:");
String city = GetData.getWord("Enter city:");
String state = GetData.getWord("Enter state:");
String z = GetData.getWord("Enter zip code:");
String acctNum = GetData.getWord("Enter an account number:");
Name n = new Name(last, first);
Address addr = new Address(street, city, state, z);
Customer cust = new Customer(n, addr, acctNum);
Bank b = new Bank(cust, acctNum);
db.add(B)/>;
break;
case 2: // MAKE DEPOSIT
acctNum = GetData.getWord("Enter an account number:");
double amountDeposit = GetData.getDouble("Enter the amount:");
((Bank)(db.getList().get(db.getIndex(acctNum)))).deposit(amountDeposit); // THIS LINE!!
// that line of code looks nice but is too advanced to a beginner like me.
// i would like to break this up into something like:
// db.getIndex(acctNum)
// then storing this into a variable but the problem is that deposit is a void method
// and that is the problem , i dont know how would i link that account number with the
// void deposit method.
// ON CASE 3 it is the same case
//deposit(amountDeposit);
break;
case 3: // MAKE WITHDRAWAL
acctNum = GetData.getWord("Enter an account number:");
double amountWithdrawl = GetData.getDouble("Enter the amount:");
((Bank)(db.getList().get(db.getIndex(acctNum)))).withdraw(amountWithdrawl);
break;
case 4: // CLOSE ACCOUNT
if (!db.empty())
{
acctNum = GetData.getWord("Enter account number:");
db.search(acctNum);
if (!db.inList(acctNum))
{
acctNum = "Account number " + acctNum;
display("Account number not valid", "Message",
JOptionPane.ERROR_MESSAGE);
} else
{
Bank removed = (Bank)db.remove(acctNum);
close.add(removed);
}
} else
{
display("there exists no accounts", "Message",
JOptionPane.ERROR_MESSAGE);
}
break;
case 5: // SHOW ACTIVE ACCOUNTS
ArrayList list = db.getList();
String str = "Active accounts:\n" +
report(list);
JTextArea text = new JTextArea(str, 10, 30);
JScrollPane pane = new JScrollPane(text);
display(pane, "Report", JOptionPane.INFORMATION_MESSAGE);
break;
case 6: // SHOW CLOSED ACCOUNTS
ArrayList listd = close.getList();
String strd = "Inactive accounts:\n" +
report(listd);
JTextArea textd = new JTextArea(strd, 10, 30);
JScrollPane paned = new JScrollPane(textd);
display(paned, "Report", JOptionPane.INFORMATION_MESSAGE);
break;
case 7: //EXIT
display("Press 'OK' to quit", "Message",
JOptionPane.WARNING_MESSAGE);
done = true;
break;
default:
display("Wrong option.", "Message", JOptionPane.ERROR_MESSAGE);
break;
}
}
}
static String report(ArrayList list)
{
int length = list.size();
String str = "";
for (int i = 0; i < length; i++)
{
Bank b = (Bank)list.get(i);
Customer s = b.cust;
str =
str + s.getName().lastname + ", " + s.getName().firstname + " " +
s.getAddress().street + " " + s.getAddress().city + " " +
s.getAddress().state + " " + s.getAddress().zip + " " + s.getacctNum() +
"\n";
}
return str;
}
static void display(String info, String heading, int type)
{
JOptionPane.showMessageDialog(null, info, heading, type);
}
static void display(JScrollPane pane, String heading, int type)
{
JOptionPane.showMessageDialog(null, pane, heading, type);
}
}
This post has been edited by tor.ment0r: 07 August 2010 - 03:33 AM

New Topic/Question
Reply




MultiQuote





|