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.
*/
}Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import java.text.DecimalFormat; public class MCA extends JPanel { public static void main(String[] args) { // 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 //GUI Layout - Row creation and component population: Box Row1 = Box.createHorizontalBox(); Row1.add (loanLabel); Row1.add (Box.createRigidArea (new Dimension(10,0))); Row1.add (loanField); Box Row2 = Box.createHorizontalBox(); Row2.add (interestLabel); Row2.add (Box.createRigidArea (new Dimension (10,0))); Row2.add (interestField); Box Row3 = Box.createHorizontalBox(); Row3.add (paymentLabel); Row3.add (Box.createRigidArea (new Dimension (10,0))); Row3.add (paymentField); Box bottom = Box.createHorizontalBox(); JPanel bottomPanel = new JPanel(); bottomPanel.add(Reset); bottomPanel.add(Calculate); bottomPanel.add(Exit); bottomPanel.add(ShowIt); Box top = Box.createVerticalBox(); top.add (Box.createRigidArea(new Dimension(0,20))); top.add (Row4); top.add (Box.createVerticalStrut(15)); Container content = aWindow.getContentPane(); content.setLayout (new BorderLayout()); content.add (top, BorderLayout.CENTER); content.add (bottomPanel, BorderLayout.SOUTH); aWindow.setVisible (true); loanLabel.setText ("Loan Amount: $"); loanLabel.setLabelFor (loanField); interestLabel.setText ("Interest rate percentage:"); interestLabel.setLabelFor (interestField); paymentField.setEditable (false); paymentLabel.setText ("Monthly Loan Payment: $"); paymentLabel.setLabelFor (paymentField); //Action Listeners / Button Operation Reset.addActionListener (new ActionListener() { public void actionPerformed (ActionEvent evt) { paymentField.setText (""); } }); } 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); } }); } } }
}


Reply With Quote


Bookmarks