Account Program
Java Applet and HTML
Handles Account, Calculating Summary of Accounts of multiple years.
Connecting program with HTML
Code:
//Import all required Packages
import
javax.swing.*;
import java.awt.*;
import java.text.*;
import java.awt.event.*;
public
class account extends JApplet implements ActionListener {
JPanel
q;
JPanel
w;
JPanel
e;
double
Loan;
double
pRate;
double
number;
int
month = 0;
double
rBalance = 0;
double
iPayment = 0;
double
pPaid = 0;
JLabel
lAmount;
JLabel
lInterest;
JLabel
lTerm;
JTextField
tAmount;
JLabel
lHeader;
JTextField
tTerm;
JTextField
tInterest;
JTextArea
tResults;
JScrollPane
tPane;
JButton
calculate;
public
void init()
{
q
= new JPanel();
e
= new JPanel(new GridLayout(1,3,75,1));
w
= new JPanel(new BorderLayout());
lAmount
= new JLabel("loan amount: $", JLabel.LEFT);
tAmount
= new JTextField(10);
lInterest
= new JLabel("Annual Percentage Rate %", JLabel.LEFT);
tInterest
= new JTextField(6);
lTerm
= new JLabel("Term in Years", JLabel.LEFT);
tTerm
= new JTextField(6);
String
str = "
";
lHeader
= new JLabel("Payment #"+str+"Monthly Amount:"+str+"
Interest:"+str+"Principle"+str+"Balance:");
tResults
= new JTextArea(10, 53);
tPane
= new JScrollPane(tResults);
calculate
= new JButton("Calculate");
setSize(700,
250);
q.add(lAmount);
q.add(tAmount);
q.add(lInterest);
q.add(tInterest);
q.add(lTerm);
q.add(tTerm);
tPane.setPreferredSize(new
Dimension(610,200));
w.add(lHeader,BorderLayout.NORTH);
w.add(tPane,BorderLayout.CENTER);
calculate.addActionListener(this);
e.add(calculate);
getContentPane().add(q,BorderLayout.NORTH);
getContentPane().add(w,BorderLayout.CENTER);
getContentPane().add(e,BorderLayout.SOUTH);
}
public
void actionPerformed(ActionEvent e)
{
if
(e.getSource() == calculate)
{
double
balance = 0;
double
monthPayment=0;
Loan
= Double.parseDouble(tAmount.getText());
pRate
= Double.parseDouble(tInterest.getText());
number
= Double.parseDouble(tTerm.getText());
NumberFormat
fmt = NumberFormat.getCurrencyInstance();
monthPayment
= MonthlyPayment();
balance
= Loan;
month
= (int)number * 12;
for(int
index = 1; index <= month ; index++)
{
iPayment
= balance * (pRate * .01/12);
pPaid
= monthPayment - iPayment;
rBalance
= balance - pPaid;
tResults.append("
" + index + "\t\t "+ fmt.format(monthPayment) + "\t\t"
+
fmt.format(iPayment) + "\t" +fmt.format(pPaid)+"\t\t" +
fmt.format(rBalance) + "\n");
balance
= rBalance;
}
}
}
double
MonthlyPayment()
{
return
(Loan * ((1 + (pRate*.01)/12)-1) /
(1-(Math.pow((1+(pRate*.01)/12),-(number*12)))));
}
public
void paint(Graphics g){
super.paintComponents(g);
}
}
Program Screenshots
Program Screenshots
Program Screenshots
Program Screenshots
No comments:
Post a Comment