java.util.Formatter and JCreator

  • Thread starter Michael B. Williams
  • Start date
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);
}



}
 
V

VisionSet

Michael B. Williams said:
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
***************************************************************************

You have at least three problems.

1 There is no class java.util.Formatter. The only Formatter class is in
java.util.logging - you don't appear to be doing any logging.

2 String does not have a format method

3 This is Java not C !!
 
T

TechBookReport

VisionSet said:
***************************************************************************

You have at least three problems.

1 There is no class java.util.Formatter. The only Formatter class is in
java.util.logging - you don't appear to be doing any logging.

2 String does not have a format method

3 This is Java not C !!

This is Tiger code not JDK1.4.x, so points 1, 2 and 3 are wrong...

Pan
=====================================
TechBookReport : http://www.techbookreport.com
 
T

TechBookReport

Michael said:
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);
}



}
Are you sure that you've set the right JDK to use? If JCreator's still
pointing to an older JDK then that's your problem

Pan
========================================
TechBookReport : http://www.techbookreport.com/JavaIndex.html
 
M

Michael B. Williams

I'm using:
j2sdk1.4.2_04

what version does java.util.Formatter come in ( the million dollar question)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top