I am having an issue tieing all of my code together there is a discription of what my code is supposed to do, but when I compile I get this error.<identifier>expected Calculate = new JButton ("Calculate");
????wanted to see if someone could help????thank you for looking!!!!!
Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount
from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans:
- 7 years at 5.35%
- 15 years at 5.5%
- 30 years at 5.75%
Use an array for the mortgage data for the different loans.
Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan.
Allow the user to loop back and enter a new amount and make a new selection or quit.
Please insert comments in the program to document the program.
*/
// GUI Components: Text Fields / Labels
final JTextField loanField = new JTextField(15);
JLabel loanLabel = new JLabel();
final JTextField interestField = new JTextField();
JLabel interestLabel = new JLabel();
final JTextField paymentField = new JTextField(10);
JLabel paymentLabel = new JLabel();
// GUI Components: Buttons
JButton Reset = new JButton("Reset");
JButton Calculate = new JButton("Calculate");
JButton Exit = new JButton("Exit");
JButton showItButton = new JButton("Show It");
//Window definition
JFrame aWindow = new JFrame("Amortization Calculator"); // Set the window variable
int windowWidth = 500; // Window width in pixels
int windowHeight = 400; // Window height in pixels
aWindow.setBounds(75, 125, // Set window position
windowWidth, windowHeight); // Set window size
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set close behavior
private JPanel createFeatureDialogBox() {
final int numButtons = 1;
JRadioButton[] radioButtons = new JRadioButton[numButtons];
final ButtonGroup group = new ButtonGroup();
JButton showItButton = null;
final String pickOneCommand = "pickone";
radioButtons[0] = new JRadioButton("Choose a loan term");
radioButtons[0].setActionCommand(pickOneCommand);
for (int i = 0; i < numButtons; i++) {
group.add(radioButtons[i]);
}
radioButtons[0].setSelected(true);
showItButton = new JButton("Show it!");
showItButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String command = group.getSelection().getActionCommand();
//pick one of many
if (command == pickOneCommand) {
Object[] possibilities = {"7", "15", "30"};
int s = (String)JOptionPane.showInputDialog(
frame,
"Choose a loan term:\n"
+"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"");
//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
return;
}
}
}
Calculate = new JButton ("Calculate");
Calculate.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent evt)
{
{
int[]T1= (s); // multiplied the given terms by 12 to break them down into years
P = Double.parseDouble (loanField.getText());
I = Double.parseDouble (interestField.getText());
DecimalFormat D = new DecimalFormat("$#.##");
for (int i = 0; i <T1.length; i++) //for function of the array
{
for(int j = 1;j<=12;j++)
{
double I,P,A,MI,MP,A2,R1,MR,MR1,P2;
int T2= T1[i];
R1=I;
MR=(I/1200); //calculates the monthly interest on the loan
MR1=(Math.pow((1+MR),T2)-1)
/ (MR*Math.pow((1+MR),T2));
P2=(P/MR1);
int yrs =(int)(T2/12);
paymentField.setText(""+D.format(MR1));
}
}
/* MI=(A1*MR); //amount paid towards interest
MP=(P2-MI); //amount paid towards principal
A1=(A1-MP);*/
}
}
});
Exit.addActionListener (new ActionListener() {
public void actionPerformed (ActionEvent event) {
System.exit(1);
}
});
}
}
}
}
}
03-30-2010, 10:40 AM
ajhampson
You'd probably get a little more response if you posted what problems you're having with this code. If you're getting compile errors or runtime exceptions, post the full text of these errors as well.
03-30-2010, 09:38 PM
nspils
You are getting this error because you have not given a datatype to Calculate where you declare it near the end of your code - by the way, do you see that you have declared a JButton by the name Calculate early in method main?