Help student project this is for a Java code to make a loan calculator to pay ba
ID: 3755949 • Letter: H
Question
Help student project this is for a Java code to make a loan calculator to pay back with interest ...
Help student project this is for a Java code to make a loan calculator to pay back with interest rate.
Get: -customers name
-Birth date
-address
-phone number
-press (x) to exit
Create a program that you can choose from either Student loan intrest rate at 2%, Home loan intrest rate at 4%, and Auto loan interest rate at 3%.
Get how much they would like take out for a loan.
Then calculate how long it will take to pay back that loan.
Interest formula: A = P(1 + rt) where P is the Principal amount of money to be invested at an Interest Rate R% per period for t Number of Time Periods. Please do it with GUI with Java thank you. -Make sure code works please
Explanation / Answer
Here We are writing Own class Loan Student
import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoanStudent extends Frame implements ActionListener
{
Label l1,l2,l3;
TextField t1, t2, t3;
Button b1, b2, b3, b4;
public LoanStudent()
{
l1=new Label("Principle");
l2=new Label("Rate");
l3=new Label("Time");
l4=new Label("Interest");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
t4=new TextField(10);
b1=new Button("Principle");
b2=new Button("Rate");
b3=new Button("Time");
b4=new Button("Interest");
add(buttons);
setSize(100,100);
setTitle("Bank Loan");
setLayout(new FlowLayout());
public void actionPerformed(ActionEvent ae)
{
int t=0;
double p=0, r=0, i=0;
try
{
p=Double.parseDouble(t1.getText());
}
catch(NumberFormatException e)
{
t1.setText("Invalid Input");
}
try
{
r=Double.parseDouble(t1.getText());
}
catch(NumberFormatException e)
{
t2.setText("Invalid Input");
}
try
{
t=Integer.parseInt(t1.getText());
}
catch(NumberFormatException e)
{
t3.setText("Invalid Input");
}
if(ae.getSource()==b1)
{
t1.setText(String.valueOf(p));
}
if(ae.getSource()==b2)
{
t2.setText(String.valueOf(r));
}
if(ae.getSource()==b3)
{
t3.setText(String.valueOf(t));
}
if(ae.getSource()==b4)
{
i=(p*r)/t;
t4.setText(String.valueOf(i));
}
t1.setText(String.valueOf(p));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.