M
Michael B. Williams
All,
I have tried to compile the below code and it gets 2 errors:
***************************************************************************
C:\Documents and Settings\00\My Documents\M\juf.java:6: cannot resolve
symbol
symbol : class Formatter
location: package util
import java.util.Formatter;
^
C:\Documents and Settings\00\My Documents\M\juf.java:112: cannot
resolve symbol
symbol : method format
(java.lang.String,int,double,double,double,double)
location: class java.lang.String
line = String.format("%3d Ipmt=$%,-8.2f Ppmt=$%,-8.2f
Mpmt=$%,-8.2f Bal=$%,-16.2f",i,ipmt,(Mpay-ipmt),Mpay,prin);
^
2 errors
***************************************************************************
where would these import files anyway? - Thanks in advance!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
import java.util.Formatter;
/**
* juf extends JFrame
* creates and displays form for user input
*/
class juf extends JFrame implements ActionListener {
JPanel Row1 = new JPanel();
JLabel lblPrinc = new JLabel("Principle");
JTextField fldPrinc = new JTextField("450000",8);
JPanel Row3 = new JPanel();
JLabel lblChoices = new JLabel("Loan Choices");
JPanel Row4 = new JPanel();
JButton btnLoan1 = new JButton("7 Years @ 5.35%");
JPanel Row5 = new JPanel();
JButton btnLoan2 = new JButton("15 Years @ 5.50%");
JPanel Row6 = new JPanel();
JButton btnLoan3 = new JButton("30 Years @ 5.75%");
List lstSchedule = new List();
/**
* creates last_task class
*/
public juf() {
super("juf-Mortgage Calc");
/**
* ROW10 - Calculate button
*/
/**
* Row 1 - Principle field
*/
Row1.setLayout(new FlowLayout());
fldPrinc.setToolTipText("Principle of loan in dollars");
Row1.add(lblPrinc);
Row1.add(fldPrinc);
Row3.add(lblChoices);
Row4.add(btnLoan1);
Row5.add(btnLoan2);
Row6.add(btnLoan3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel rootpane=new JPanel();
JPanel paneOne=new JPanel();
JPanel paneTwo=new JPanel();
rootpane.setLayout(new GridLayout(2,1));
setSize(500,600);
paneOne.setLayout(new GridLayout(0,1));
paneOne.add(Row1);
paneOne.add(new JPanel());
paneOne.add(Row3);
paneOne.add(Row4);
paneOne.add(Row5);
paneOne.add(Row6);
paneOne.add(new JPanel());
btnLoan1.addActionListener(this);
btnLoan2.addActionListener(this);
btnLoan3.addActionListener(this);
rootpane.add(paneOne);
lstSchedule.setFont(new Font("monospaced",Font.BOLD,10));
rootpane.add(lstSchedule);
setContentPane(rootpane);
}
/**
* responds to the button pressed event
*/
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
double prin = Double.parseDouble(fldPrinc.getText());
if (s==btnLoan1) createSchedule(prin,5.35,7);
if (s==btnLoan2) createSchedule(prin,5.5,15);
if (s==btnLoan3) createSchedule(prin,5.75,30);
}
/**
* Calculates the monthly payment with the values passed
*/
private double payment(double Amt,double r,double t) {
double p=0;
double rate=r/100;
double nt=12*t;
double tmp=Math.pow((1+(rate/12)),(-1*nt));
p=(rate*Amt)/((1-tmp)*12);
return p;
}
public void createSchedule(double Amt, double r, double t) {
double Mpay = payment(Amt,r,t);
double prin = Amt;
double ipmt = 0;
int nmonths =(int) t *12;
String line="";
lstSchedule.removeAll();
for (int i=0;i<=nmonths;i++) {
ipmt = prin * (r/1200);
line = String.format("%3d Ipmt=$%,-8.2f Ppmt=$%,-8.2f
Mpmt=$%,-8.2f Bal=$%,-16.2f",i,ipmt,(Mpay-ipmt),Mpay,prin);
prin-=Mpay-ipmt;
lstSchedule.add(line);
}
}
/**
* Main method, instantiates the last_task object
*/
public static void main(String[] args) {
// TODO code application logic here
JFrame app = new juf();
app.setVisible(true);
}
}
I have tried to compile the below code and it gets 2 errors:
***************************************************************************
C:\Documents and Settings\00\My Documents\M\juf.java:6: cannot resolve
symbol
symbol : class Formatter
location: package util
import java.util.Formatter;
^
C:\Documents and Settings\00\My Documents\M\juf.java:112: cannot
resolve symbol
symbol : method format
(java.lang.String,int,double,double,double,double)
location: class java.lang.String
line = String.format("%3d Ipmt=$%,-8.2f Ppmt=$%,-8.2f
Mpmt=$%,-8.2f Bal=$%,-16.2f",i,ipmt,(Mpay-ipmt),Mpay,prin);
^
2 errors
***************************************************************************
where would these import files anyway? - Thanks in advance!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
import java.util.Formatter;
/**
* juf extends JFrame
* creates and displays form for user input
*/
class juf extends JFrame implements ActionListener {
JPanel Row1 = new JPanel();
JLabel lblPrinc = new JLabel("Principle");
JTextField fldPrinc = new JTextField("450000",8);
JPanel Row3 = new JPanel();
JLabel lblChoices = new JLabel("Loan Choices");
JPanel Row4 = new JPanel();
JButton btnLoan1 = new JButton("7 Years @ 5.35%");
JPanel Row5 = new JPanel();
JButton btnLoan2 = new JButton("15 Years @ 5.50%");
JPanel Row6 = new JPanel();
JButton btnLoan3 = new JButton("30 Years @ 5.75%");
List lstSchedule = new List();
/**
* creates last_task class
*/
public juf() {
super("juf-Mortgage Calc");
/**
* ROW10 - Calculate button
*/
/**
* Row 1 - Principle field
*/
Row1.setLayout(new FlowLayout());
fldPrinc.setToolTipText("Principle of loan in dollars");
Row1.add(lblPrinc);
Row1.add(fldPrinc);
Row3.add(lblChoices);
Row4.add(btnLoan1);
Row5.add(btnLoan2);
Row6.add(btnLoan3);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel rootpane=new JPanel();
JPanel paneOne=new JPanel();
JPanel paneTwo=new JPanel();
rootpane.setLayout(new GridLayout(2,1));
setSize(500,600);
paneOne.setLayout(new GridLayout(0,1));
paneOne.add(Row1);
paneOne.add(new JPanel());
paneOne.add(Row3);
paneOne.add(Row4);
paneOne.add(Row5);
paneOne.add(Row6);
paneOne.add(new JPanel());
btnLoan1.addActionListener(this);
btnLoan2.addActionListener(this);
btnLoan3.addActionListener(this);
rootpane.add(paneOne);
lstSchedule.setFont(new Font("monospaced",Font.BOLD,10));
rootpane.add(lstSchedule);
setContentPane(rootpane);
}
/**
* responds to the button pressed event
*/
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
double prin = Double.parseDouble(fldPrinc.getText());
if (s==btnLoan1) createSchedule(prin,5.35,7);
if (s==btnLoan2) createSchedule(prin,5.5,15);
if (s==btnLoan3) createSchedule(prin,5.75,30);
}
/**
* Calculates the monthly payment with the values passed
*/
private double payment(double Amt,double r,double t) {
double p=0;
double rate=r/100;
double nt=12*t;
double tmp=Math.pow((1+(rate/12)),(-1*nt));
p=(rate*Amt)/((1-tmp)*12);
return p;
}
public void createSchedule(double Amt, double r, double t) {
double Mpay = payment(Amt,r,t);
double prin = Amt;
double ipmt = 0;
int nmonths =(int) t *12;
String line="";
lstSchedule.removeAll();
for (int i=0;i<=nmonths;i++) {
ipmt = prin * (r/1200);
line = String.format("%3d Ipmt=$%,-8.2f Ppmt=$%,-8.2f
Mpmt=$%,-8.2f Bal=$%,-16.2f",i,ipmt,(Mpay-ipmt),Mpay,prin);
prin-=Mpay-ipmt;
lstSchedule.add(line);
}
}
/**
* Main method, instantiates the last_task object
*/
public static void main(String[] args) {
// TODO code application logic here
JFrame app = new juf();
app.setVisible(true);
}
}