Cant find method? and i cant figure out how to round a decimal....

when i compile this it says "getAverage not found in class AverageGradeUser" - look at actionPeformed() to find where its used at....how do i fix this, i had it working but somehow messed it up and when the new average is figured and put in the results textfield, how can u round it off to the nearest tenth (0.1)..ive tried using NumberFormat and related things but couldnt get it to work
please help me
thanks
p.s. keep in mind i am a rookie-rookie-rookie in java programming
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AverageGradeUser extends Applet implements ActionListener
/****InstanceVariables****/
public TextField input;
/*****InitMethod****/
public void init()
Label directions = new Label("Enter a grade percent: ");
input = new TextField(10);
Label results = new Label("Your new average is: ");
TextField output = new TextField(10);
add(directions);
add(input);
add(results);
add(output);
output.setEditable(false);
input.addActionListener(this);
} // init()
public void actionPerformed(ActionEvent e)
double grade = Double.parseDouble(input.getText());
if (e.getSource() == input)
getAverage(grade);
} // actionPerformed()
} // AverageGradeUser class
============================================================
(the classes are in separate files but both are in the project)
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AverageGrade
/****InstanceVariables****/
private double total = 0;
private double counter = 0;
private double average = 0;
private TextField input;
private TextField output;
/****ConstructorMethod****/
public AverageGrade()
/****AccessMethod****/
public void getAverage(double g)
total += g;
counter ++;
average = total / counter;
output.setText(average + " " + getLetterGrade(average));
input.setText("");
} // getAverage()
private String getLetterGrade(double avg)
if (avg >= 90)
return "A";
else if (avg >= 80)
return "B";
else if (avg >= 70)
return "C";
else if (avg >= 60)
return "D";
else if (avg < 60)
return "F";
else
return "error";
} // getLetterGrade()
} // AverageGrade class

According to the code you have posted, method "getAverage()" is defined in class "AverageGrade" -- and not in class "AverageGradeUser". Therefore, you have two choices (in my opinion):
1. Add the definition of method "getAverage()" to class "AverageGradeUser"
2. Change the "actionPerformed()" method:
Replace the line:
getAverage(grade)with
new AverageGrade().getAverage(grade)Hope this helps you.
Good Luck,
Avi.

Similar Messages

Maybe you are looking for

  • Multiple Domains/Website On Single Hosting Plan

    I currently host my website with a shared hosting company that uses the latest version of ColdFusion MX. I recently registered a second domain and pointed it to the same IP address. I found some code on another ColdFusion forum that allows you to dir

  • How to send a photo by email

    I want to send a photo to Geico Insurance company, Geico. How do I do it?

  • JTable, column names not appearing!

    I am using the following code: Vector columnNames = new Vector();         Vector data = new Vector();         try             //  Connect to the Database             Common.Data.DataAccesser da = new Common.Data.DataAccesser();             Connection

  • FBRA performace problem

    Dear GURUs While running TCODE FBRA it is taking long time due to lots off record is available in table BKORM, The solution is delete all records from BKORM through F.63, is there any effect if we delete all record from Table BKORM. By which T. code

  • MacBook Screen Flashes and Refreshes every 2 seconds after autoupdate

    My daughter installed updates last nite (she thinks itunes, safari, quicktime?) and now her computer will turn on but the display keeps refreshing and will not completely display all her usual icons. I tried resetting the PRAM (Control Command P R) a