When I try to compile my code I get this message. What does this mean about my code?
Note: C:\Users\myname\Desktop\Week3_421.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Tool completed successfully
Thank you for any help.
Here is my code:
import javax.swing.*;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Week3_421 extends JFrame implements ActionListener
{
// Variables
JLabel titleLabel = new JLabel("Mortgage Calculator");
JLabel amntLabel = new JLabel("Mortgage Amount: ");
JLabel selecLabel = new JLabel("Choose your Mortgage: ");
JTextField amntText = new JTextField("");
JComboBox loanType;
JButton buttonCal = new JButton("Calculate");
JButton buttonClr = new JButton("Reset");
JButton buttonExit = new JButton("Exit");
JTextArea displayArea = new JTextArea(40, 20);
java.text.DecimalFormat fmt = new java.text.DecimalFormat("###,###,###.00");
public static void main(String[] args)
{
Week3_421 window = new Week3_421();
window.setSize(490, 490);
window.setVisible(true);
}
public Week3_421()
{
setTitle("Week3_421");
buildGUI();
}
public void buildGUI()
{
Container content = getContentPane();
content.setLayout(null);
// The array of loans
Loan[] loans = new Loan[3];
loans[0] = new Loan(5.35, 7);
loans[1] = new Loan(5.5, 15);
loans[2] = new Loan(5.75, 30);
loanType = new JComboBox(loans);
content.add(titleLabel);
content.add(amntLabel);
content.add(selecLabel);
content.add(amntText);
content.add(loanType);
content.add(buttonCal);
content.add(buttonClr);
content.add(buttonExit);
JScrollPane scroll = new JScrollPane(displayArea);
content.add(scroll);
// Orientation
titleLabel.setBounds(180, 20, 200, 30);
amntLabel.setBounds(50, 60, 150, 30);
amntText.setBounds(260, 60, 180, 30);
selecLabel.setBounds(50, 100, 150, 30);
loanType.setBounds(260, 100, 180, 30);
buttonCal.setBounds(50, 200, 100, 30);
buttonClr.setBounds(200, 200, 100, 30);
buttonExit.setBounds(350, 200, 100, 30);
scroll.setBounds(50, 250, 400, 180);
buttonCal.addActionListener(this);
buttonClr.addActionListener(this);
buttonExit.addActionListener(this);
}
// The course of Action
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==buttonClr)
{
buttonClear();
}
else
if (e.getSource()==buttonCal)
{
buttonCalculate();
}
else if (e.getSource()==buttonExit)
{
buttonExit();
}
}
// The action of Reset
public void buttonClear()
{
amntText.setText("");
displayArea.setText("");
}
// The Action of Exit
public void buttonExit()
{
System.exit(0);
}
// The Action of Calculate
public void buttonCalculate()
{
try
{
Loan loan = (Loan)loanType.getSelectedItem();
double amount = Double.parseDouble(amntText.getText());
int year = loan.getTermYears();
double rate = loan.getInterestYearly();
double payment = calcMonthlyPayment(amount, rate / 100, year);
displayMonthlyPayment(amount, rate / 100, year, payment);
} catch (Exception e)
{
displayArea.setText("Error! Please, ENTER the APPROPRIATE information.");
}
}
// Display
public void displayMonthlyPayment(double principal, double interestYearly, int termYears, double monthlyPayment)
{
double interestMonthly = interestYearly / 12.0;
displayArea.setText("Loan Amount: " + fmt.format(principal) + "\n");
displayArea.append("Years: " + termYears + "\n");
displayArea.append("Interest: " + interestYearly * 100 + "% \n");
displayArea.append("Monthly Payment: " + fmt.format(monthlyPayment) + "\n\n");
displayArea.append("Month\tPrinciple\tBalance Paid\tInterest Paid\n");
for (int count = 1; count <= termYears * 12; count++)
{
double interest = principal * interestMonthly; // Interest Paid
double loan = monthlyPayment - interest; // Load Balanced Paid
principal -= loan; // Amount left
// Display for balance and interest Paid
displayArea.append(String.format("%01d\t%s\t%s\t%s \n", count, fmt.format(principal),fmt.format(loan), fmt.format(interest)));
}
}
// Calculation of Monthly payment
public double calcMonthlyPayment(double principal, double interestYearly, int termYears)
{
double interestMonthly = interestYearly / 12.0;
double numberOfPayments = termYears * 12;
return (principal * interestMonthly) / (1.0 - (Math.pow((1.0 + interestMonthly), -numberOfPayments)));
}
}
class Loan
{
private double yearlyInterest;
private int termYears;
public Loan(double yearlyInterest, int termYears)
{
this.yearlyInterest = yearlyInterest;
this.termYears = termYears;
}
//Get the interestYearly
public double getInterestYearly()
{
return yearlyInterest;
}
//Get the termYears
public int getTermYears()
{
return termYears;
}
//Overriden toString
public String toString()
{
return String.format("%d year term at %.2f%%", termYears, yearlyInterest);
}
}