Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: grading program help

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default grading program help

    my code is supposed to calculate quiz 10% pratical 50 %, exam, and midterm 40 % and output overall average and quivalent letter grade.
    import javax.swing.*;
    import java.text.*;
     
    public class c6gradecalculation
    {
    	private double q1;
    	private double pa;
    	private double mid;
    	private double fin;
    	private double q1score;
    	private double pascore;
    	private double midscore;
    	private double finscore;
    	private double overallscore;
     
    public String grade;
    public String myLetterGrade()
    {
    	String grade ="";
    	if (overallscore <60)
    		grade = "F";
    	else if (overallscore >=60 && overallscore < 70)
    		grade = "D";
    	else if (overallscore >=70 && overallscore < 80)
    		grade = "C";
    	else if (overallscore >=80 && overallscore < 90)
    		grade = "B";
    	else if (overallscore >=90 && overallscore <=100)
    		grade = "A";
    	return grade;
    }
     
    public double getScore()
    {
    	q1 = Double.parseDouble(JOptionPane.showInputDialog("Enter Quiz Score (0-100)"));
    	pa = Double.parseDouble(JOptionPane.showInputDialog("Enter Pratical Average Score (0-100)"));
    	mid = Double.parseDouble(JOptionPane.showInputDialog("Enter Midterm Exam Score (0-100)"));
    	fin = Double.parseDouble(JOptionPane.showInputDialog("Enter Finals Exam Score (0-100)"));
     
    	q1score = q1 * 0.10;
    	pascore = pa * 0.50;
    	midscore = mid * 0.20;
    	finscore = fin * 0.20;
     
    	overallscore = (q1score + pascore + midscore + finscore);
    	return overallscore;


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: grading program help

    my code is supposed to calculate quiz 10% pratical 50 %, exam, and midterm 40 % and output overall average and quivalent letter grade.
    And what is the problem? Does it compile? Are there exceptions? Does it misbehave? Providing as much detail as possible will help you get more meaningful suggestions faster.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: grading program help

    i forgot to post my two ending brackets, but it compiles fine but does not run at all also not sure about the main everytime i put it in it does not work at all.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Cool Re: grading program help

    Hmmmm...that's still not very informative.

    I do find that you can do without

    public String grade;

    As for not running, you have neither a println nor a JOptionPane.

    All the return is doing is returning a value from that method.

    As you never do anything with any of your methods, it will terminate as soon as it starts.

    Third, you lack a main method, which is required to run.

    Otherwise you'll get an annoying "NoSuchMethodError "main".

    I'd recommend doing this:

     
    mport javax.swing.*;
    import java.text.*;
     
    public class c6gradecalculation
    {
    	private double q1;
    	private double pa;
    	private double mid;
    	private double fin;
    	private double q1score;
    	private double pascore;
    	private double midscore;
    	private double finscore;
     
     
     
    public String myLetterGrade(int overallscore)
    {
    	String grade ="";
    	if (overallscore <60)
    		grade = "F";
    	else if (overallscore >=60 && overallscore < 70)
    		grade = "D";
    	else if (overallscore >=70 && overallscore < 80)
    		grade = "C";
    	else if (overallscore >=80 && overallscore < 90)
    		grade = "B";
    	else if (overallscore >=90 && overallscore <=100)
    		grade = "A";
    	return grade;
    }
     
    public double getScore()
    {
    	q1 = Double.parseDouble(JOptionPane.showInputDialog("Enter Quiz Score (0-100)"));
    	pa = Double.parseDouble(JOptionPane.showInputDialog("Enter Pratical Average Score (0-100)"));
    	mid = Double.parseDouble(JOptionPane.showInputDialog("Enter Midterm Exam Score (0-100)"));
    	fin = Double.parseDouble(JOptionPane.showInputDialog("Enter Finals Exam Score (0-100)"));
     
    	q1score = q1 * 0.10;
    	pascore = pa * 0.50;
    	midscore = mid * 0.20;
    	finscore = fin * 0.20;
     
    	overallscore = q1score + pascore + midscore + finscore;
    	return overallscore;
    }
     
    public static void main(String[] args)
    {
    double ovScore = getScore();
     
    JOptionPane.showMessageDialog(null, myLetterGrade(ovScore), "Your grade is: " , JOptionPane.INFORMATION_MESSAGE);
     
    // you have set ovScore to the value returned by the getScore() method.  You then pass that value as a 
    //  parameter to myLetterGrade method, which returns a String (the letter grade) which is outputted
    // in the JOptionPane.  The last parameter in that JOptionPane is the message type.  The first is the 
    // parent Component, usually null, and the third is the title.  The second is the message itself.
    // All programs, minus applets, require a main method to actually run.  They can compile without a main
    // (assuming all other code is correct), but they can't run. (Again, applets don't need a main and in fact get // mad if you have one I think.  But that's beside the point.)  
     
     
     
     
     
     
    }
    }
    Last edited by javapenguin; February 14th, 2011 at 01:06 AM. Reason: Forgot code ending bracket

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: grading program help

    k thank you for the help. i feel asleep last night i had alot more java homework than this, it is just my final one so got brain dead and past out in front of pc. but woke up to this code so going though it now i still do not totally understand the last part, but am going over it now

  6. #6
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: grading program help

    These are the errors i am getting now. I am beginning to undestand why the original code was not running. it had no main so it really was just the two seperate problems and nothing connecting them to each other


    C:\Users\Michael\Documents\School stuff\c6gradecalculation1.java:45: cannot find symbol
    symbol : variable overallscore
    location: class c6gradecalculation1
    overallscore = q1score + pascore + midscore + finscore;
    ^
    C:\Users\Michael\Documents\School stuff\c6gradecalculation1.java:46: cannot find symbol
    symbol : variable overallscore
    location: class c6gradecalculation1
    return overallscore;
    ^
    C:\Users\Michael\Documents\School stuff\c6gradecalculation1.java:51: non-static method getScore() cannot be referenced from a static context
    double ovScore = getScore();
    ^
    C:\Users\Michael\Documents\School stuff\c6gradecalculation1.java:53: myLetterGrade(int) in c6gradecalculation1 cannot be applied to (double)
    JOptionPane.showMessageDialog(null, myLetterGrade(ovScore), "Your grade is: " , JOptionPane.INFORMATION_MESSAGE);
    ^
    4 errors

    Tool completed with exit code 1

  7. #7
    Member
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: grading program help

    You didn't pass the overallscore variable into the getScore method, so the compiler can't find it.

Similar Threads

  1. Grading
    By BuhRock in forum Java Theory & Questions
    Replies: 5
    Last Post: April 18th, 2010, 05:05 PM
  2. [SOLVED] Problem with Grading calculator in java program
    By Peetah05 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: March 28th, 2009, 04:25 PM