I have finally gotten my GUI to look like I want it to, but I am having trouble getting the calculations right. No matter what I put in there, it seems to calculate a large payment, and a very wrong amortization schedule... Here is what I have so far... - package guiweek3;
-
-
//imports necessary tools
-
import java.io.*;
-
import java.awt.*;
-
import javax.swing.*;
-
import java.awt.event.*;
-
import javax.swing.border.*;
-
import javax.swing.text.*;
-
import java.text.*;
-
import java.util.*;
-
-
//creates the different fields, labels for the fields, and the panel and buttons
-
public class guiweek3 extends JFrame implements ActionListener
-
{
-
//creates gui panel and compnents including text fields and labels
-
private JPanel panelTop = new JPanel(new GridLayout (3,3));
-
private JPanel panelMid = new JPanel(new FlowLayout());
-
private JPanel panelBottom = new JPanel();
-
private JTextField amountField = new JTextField();
-
private JTextField paymentField = new JTextField();
-
private JLabel paymentLabel = new JLabel("Monthly Payment:");
-
private JLabel amountLabel = new JLabel("Enter Your Loan Amount: $");
-
private JLabel loanLabel = new JLabel("Choose Your Loan Terms:");
-
private JComboBox loanMenu = new JComboBox();
-
private JTextArea amortizationSchedule = new JTextArea(25,50);
-
private JButton calculateButton = new JButton("Calculate Payment");
-
private JButton clearButton = new JButton("Clear Fields");
-
private JButton quitButton = new JButton("Quit");
-
static DecimalFormat usDollar = new DecimalFormat("$###,##0.00");
-
-
//create arrays for the three loans
-
int[] yearsArray = {7, 15, 30};
-
double[] interestArray = {5.35, 5.50, 5.75};
-
-
//exit action
-
public guiweek3()
-
{
-
initComponents();
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
setVisible(true);
-
pack();
-
-
//adds the listen action to the calculate, clear, and quit buttons
-
calculateButton.addActionListener(this);
-
quitButton.addActionListener(this);
-
clearButton.addActionListener(this);
-
}
-
-
//adds the individual components (panel, fields, labels, buttons)to the
-
//panel, sets column sizes for the text fields. Makes payment field static.
-
public void initComponents()
-
{
-
//creates the object attributes
-
amountField.setColumns(8);
-
paymentField.setColumns(8);
-
paymentField.setEditable(false);
-
-
Container pane = getContentPane();
-
pane.setLayout(new FlowLayout());
-
JScrollPane amortizationPanel = new JScrollPane(amortizationSchedule);
-
amortizationSchedule.setEditable(false);
-
-
//creates the components and adds them to the panel
-
panelTop.add(amountLabel);
-
panelTop.add(amountField);
-
panelTop.add(loanLabel);
-
panelTop.add(loanMenu);
-
panelTop.add(paymentLabel);
-
panelTop.add(paymentField);
-
panelMid.add(calculateButton);
-
panelMid.add(clearButton);
-
panelMid.add(quitButton);
-
panelBottom.add(amortizationPanel);
-
pane.add(panelTop);
-
pane.add(panelMid);
-
pane.add(panelBottom);
-
-
for(int i=0; i<3; i++)
-
{
-
loanMenu.addItem(interestArray[i] + "% interest for " + yearsArray[i] + " years");
-
} //end for
-
}//end initComponents
-
-
//creates frame called guiweek2
-
public static void main(String[] args) throws IOException
-
{
-
guiweek3 frame = new guiweek3();
-
frame.setTitle("Calculator Your New Mortgage Payment");
-
frame.setBounds(200, 200, 600, 600);
-
}//end main
-
-
//if the calculate button is pressed, set the amount
-
public void actionPerformed(ActionEvent event)
-
{
-
if (event.getSource() == calculateButton)
-
{
-
//error handling try/catch, and cases for the different loans avaialble
-
try
-
{
-
double term;
-
double rate;
-
-
switch (loanMenu.getSelectedIndex())
-
{
-
case 0:
-
rate = interestArray[0];
-
term = yearsArray[0];
-
break;
-
-
case 1:
-
rate = interestArray[1];
-
term = yearsArray[1];
-
break;
-
-
case 2:
-
rate = interestArray[2];
-
term = yearsArray[2];
-
break;
-
}//end switch
-
-
double amount = Double.parseDouble (amountField.getText());
-
-
//formatting for currencies and percentages
-
NumberFormat usFormat = NumberFormat.getCurrencyInstance(Locale.US);
-
-
for (int i = 0; i<3; ++i)
-
{
-
double monthlyInterest = interestArray[i] / 12;
-
double months = yearsArray[i] * 12;
-
double payment = (amount * monthlyInterest) / (1 - Math.pow((1 + monthlyInterest), months * -1));
-
double remainingPrincipal = (amount - payment);
-
-
paymentField.setText(usDollar.format(payment));
-
-
//calculations for amortization results
-
while (remainingPrincipal > 0)
-
{
-
double interestPayment = (remainingPrincipal * (interestArray[i] / 1200) * 1);
-
-
//Display loan balance and interest paid
-
amortizationSchedule.append ("Balance:" + usDollar.format(remainingPrincipal)
-
+ "\tInterest Paid:" + usFormat.format(interestPayment) +"\n");
-
-
// Subtract amount paid to principal from loan balance
-
remainingPrincipal = remainingPrincipal - payment;
-
}//end while
-
}//end for
-
}//end try
-
-
//error message to user if loan is not entered as a number
-
catch(NumberFormatException i)
-
{
-
JOptionPane.showMessageDialog(null, "You must enter the loan " +
-
"amount as a number.", "Invalid Entry", JOptionPane.INFORMATION_MESSAGE);
-
}//end catch
-
}//end if calculate
-
-
//if the clear button is pressed, clear the fields
-
if (event.getSource() == clearButton)
-
{
-
amountField.setText("");
-
paymentField.setText("");
-
amortizationSchedule.setText("");
-
}//end if clear statement
-
-
//if the quit button is pressed, exit the application
-
if (event.getSource() == quitButton)
-
{
-
System.exit(0);
-
}//end if quit statement
-
}//end actionPerformed
-
}//end class guiweek3
3 3618
Please assume an input and also the expected output,
Sukatoa,
Please assume an input and also the expected output,
Sukatoa,
The user could put in 200000 as the loan amount. The program should display the monthly payment amount based on the loan they chose from the drop down, and then display the amortization schedule in nthe larger text area; showing the remaining balance and payment to interest for each payment through the life of the loan. I am able to do what I need without the gui, but when I try to move over my code and calculations, I cannot seem to get it right....
Please help!!
Thanks!!
The user could put in 200000 as the loan amount. The program should display the monthly payment amount based on the loan they chose from the drop down, and then display the amortization schedule in nthe larger text area; showing the remaining balance and payment to interest for each payment through the life of the loan. I am able to do what I need without the gui, but when I try to move over my code and calculations, I cannot seem to get it right....
Please help!!
Thanks!!
I would like to help you... but it needs time to analyze if you just show the input and without the expected output... And also without the formula...
I have no experience in accounting...
If you assume that the loan amount is 200000,
and the loan terms is 5.35% interest for 7 years ( if i am right, total interests for 7 years to pay...)
And im going to pay it in installment for 7 years,
5.35% of 200000 is 10700 right?
The total payment i must pay before or in 7 years is 210700? am i right?
84 months in 7 years right?
210700 divide by 84 months is 2508.33 right?
That is the monthly payment i should pay...
If the assumptions above is correct, then maybe there is something you must fix in the calculations...
At your program,
i assume 200000 in loan amount,
Monthly payments is 93.8 thousand dollars...
It should be 2508.33 dollars per month...
At the textArea, it is confusing,
Why you put the balance first before the interest paid?
Is that mean that when i pay 494.13, my new balance is 110833.33?
Can you tell me what is the correct output of your calculations?
if 200000,
and assume 5.35%
What is the monthly payment? if my assumptions above is incorrect....
What is my new balance if i pay that amount?
What's the next?
Sorry for asking you that way,
Because i need a specific question and answer...
In calculation, if A and B = C and all other variables is dependent on C, and if C got the wrong answer, then all computation will also lead to a wrong answer.
Correct me if im wrong,
Sukatoa
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rhino |
last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within
Eclipse.
I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method
in the UDF. I know that the UnsatisfiedLinkError has something to do with a
DLL that is not visible but I'm not sure why I'm having the problem given
that both db2java.zip and db2jcc.jar are visible on my classpath and each of
them contain the COM.ibm.db2.app.UDF class with a...
|
by: promiscuoustx |
last post by:
The problem is that my code below used to run wonderfully, until the instructor decided that he wants to use characters instead of integers, and wants my code to trap the bad and have the program state that the user did not imput the correct values. Can someone help me figure out how to make my code work that way??? I have the majority of the code done.....but....I still need that last step!! Thanks!!
#include <iostream>
#include...
|
by: promiscuoustx |
last post by:
I am trying to get my program to compile, but it will not complete. At line 79 it states, cannot convert 'float()()' to 'float' in assignment. Here is my code.
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <stdlib.h>
#include <sstream>
using namespace std;
|
by: ibtc209 |
last post by:
I just started programming in C, and I need some help with this problem.
Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s
first card, and the rank and suit of its second card. Note that the two cards in a hand may be entered in
any order; it’s not necessarily the case that the highest card will appear first, for example. Your program will
then determine whether the hand is valid, and...
|
by: cameron |
last post by:
Hi I am new here in this forum: I am writing a C++ program to calculate a Montly Mortgage Payment where the loan amount is 200,000.00 with a 5.75% interest rate with a term of 30 years. My program compiles fine with no errors but my calculation is not working correctly, any suggestions would be great as this assignment is due on Monday:
//*******************************************************
//Program: Calculations Payments
//Purpose: To...
| |
by: phjones |
last post by:
Need help programming mortagage calculator for 3 different loans 7 year, 15 year and 30 year. using java array I am a beginner with Java, This is what I have so far. Need to know if I am off the path,
import java.math.*;//*loan calculator
import java.text.*;//*formats numbers
public class 3 Mortgage loans {
// declare class variable array
int mortgage calculator
|
by: pnolan |
last post by:
Hello there,
I'm brand new to Java and have. I'm taking my 2nd Java class at school and I'm pretty lost at this point.
The main problem I'm having right now is I cannot get my code to execute. My code will compile, but when I try to execute it, either just using the "java" command or executing from TextPad, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: MortgagePayment1
Press any key to continue ....
|
by: poojagupta1984 |
last post by:
What i know is:
In java, all byte and short data types are automatically promoted to int during a calculation. And, if you are casting a large data type like int to a byte then the int is reduced modulo the range of the short data type i.e byte (the range of byte is 256).
The program below has no compilation error. The output is incorrect for the first print statement..please explain why?
class TestByte
{
public static void...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |