Account Interest Calculator: How to Pass Array Value to an Object?
<p>I've reached a brick wall in a Java sample project been working on. My goal with this project is to calculate interest using user input to determine what kind of account is being used, and calculating based on each specific account type.</p>

<p>Right now I have created a factory method "public Account createAccount". I need it to accept the string parameter from the user prompt. To tell me if it is Checking, Savings or CD. Now here is where I run into trouble. I have to pass the user value for the "accttype" to a new object specific for each account type. My problem is I just don't know how to do this. Do I have to implement in the factory method? How can I pass these values? Thanks in advance</p>

<p>Account.java</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Account implements ActionListener {

JButton calculate;
private int period;
private int balance;
private int fbalance;
private int rate;
private int monthlyFee;
private String printstring;


@Override
public String toString() {
    return String.format("Period: " + period + ", Balance: " + balance);
}

public int getPeriod() {
    return period;
}

public void setPeriod(int period) {
    this.period = period;
}

public int getBalance() {
    return balance;
}

public void setBalance(int balance) {
    this.balance = balance;
}

public int getRate() {
    return rate;
}

public void setRate(int rate) {
    this.rate = rate;
}

    public int getFbalance() {
    return fbalance;
}

public void setFbalance(int fbalance) {
    this.fbalance = fbalance;
}

public String getPrintstring() {
    return printstring;
}

public void setPrintString(String printstring) {
    this.printstring = printstring;
}

public void calculate() {
    for ( int i = 0; i&lt;period; i++)
{
    fbalance = balance + balance * rate - monthlyFee;
}

}

public void actionPerformed(ActionEvent e) {
    calculate();
}



}
</code></pre>

<p>Banker.java</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Banker {

// Array for type of bank account

    private static void createAndShowGUI() {

    // Declare strings for period, balance, rate
    String period;
    String balance;
    String rate;

    // Prompt for account type
    String[] accttype = { "Checking", "Savings", "CD" }; // Array of bank acct types
    String input = (String) JOptionPane.showInputDialog(null, "Choose account...",
    "Choose bank account type", JOptionPane.QUESTION_MESSAGE, null,
    accttype, // Array of acct types
    accttype[0]); // First choice

    // Prompt user for input
    period = JOptionPane.showInputDialog(null, "Number of periods (length):");
    balance = JOptionPane.showInputDialog(null, "Beginning balance:");
    rate = JOptionPane.showInputDialog(null, "Interest rate (use decimal, example: .05      = 5%):");

    // Make Calculate button
    JButton calculate = new JButton("Calculate");

    // Make 2 Labels
    JLabel blabel = new JLabel("Period: " + period);
    JLabel plabel = new JLabel("Balance: " + balance);

    // Setup window with flow layout and exit on close
    JFrame frame = new JFrame("Interest Savings Calculator Plus");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Add combo box, calc button and labels
    frame.add(calculate);

    frame.add(plabel);
    frame.add(blabel);
    frame.pack();
    frame.setVisible(true);


    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

public static void main(String[] args) {
            createAndShowGUI();
        }

public Account createAccount(String type){

}


}
</code></pre>
