5 Replies - 1167 Views - Last Post: 13 October 2012 - 04:19 PM Rate Topic: -----

#1 asianhulk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Question regarding a grading program

Posted 09 October 2012 - 10:56 PM

Java noob here and I have been having some issues with my code and was wondering if anyone could assist with me with a logic (I think) error. At the end, it won't run my overallS and letterG methods, thanks again!

class:
import java.util.Scanner;
public class Grade
{
    private double quiz1, quiz2;
    private double midterm, finalG, overallS;
    private char letterG;
    
    
    public void readInput()
    {
        Scanner keyboard = new Scanner(System.in);
        do
        {
            System.out.println("Please enter the score from Quiz 1, from 0 to "
                    + "10: ");
            quiz1 = keyboard. nextDouble();
            if (quiz1 < 0 || quiz1 > 10) 
            {
                System.out.println("Invalid Entry!  Enter a score from 0 to "
                        + "10: ");
            }
         }while (quiz1 < 0 || quiz1 > 10);
        do
        {
            System.out.println("Please enter the score from Quiz 2, from 0 to "
                    + "10: ");
            quiz2 = keyboard. nextDouble();
            if (quiz2 < 0 || quiz2 > 10)
            {
                System.out.println("Invalid entry!  Enter a score from 0 to "
                        + "10: ");
            }
         }while (quiz2 < 0 || quiz2 > 10);
         do
        {
            System.out.println("Please enter the score from the midterm, from"
                    + " 0 to 100: ");
            midterm = keyboard. nextDouble();
            if (midterm < 0 || midterm > 100)
            {
                System.out.println("Invalid entry!  Enter a score from 0 to "
                        + "100: ");
            }
         }while (midterm < 0 || midterm > 100);
         do
        {
            System.out.println("Please enter the score from the final exam, "
                    + "from 0 to 100: ");
            finalG = keyboard. nextDouble();
            if (finalG < 0 || finalG > 100)
            {
                System.out.println("Invalid entry!  Enter a score from 0 to "
                        + "100: ");
            }
         }while (finalG < 0 || finalG > 100);
    }
    
     public final void overallS() //Calculation of Overall Score
    {
        overallS = (finalG * .50 + midterm * .25 + quiz1 + quiz2 * 1.25);
    }
    
   public final void letterG()    //Assigning letter grade
   {if (overallS >= 90) 
       {
           letterG = 'A';
       }
   else if (overallS >= 80)
       {
           letterG = 'B';
       }
   else if (overallS >= 70)
       {
           letterG = 'C';
       }
   else if (overallS >= 60)
       {
           letterG = 'D';
       }
   else{
           letterG = 'F';
       }
   }         
    
    public void setGrade (double newQuiz1, double newQuiz2, double newMidterm, 
           double newFinalG, double newOverallS, char newLetterG)    //Mutators
         {
             if (newQuiz1 >= 0)
             
                 quiz1 = newQuiz1;
             
             else
             
                 System.out.println("Invalid score!");
                 System.exit(0);
                
                 
             if (newQuiz2 >= 0)
             
                 quiz2 = newQuiz2;
             
             else
             
                 System.out.println("Invalid score!");
                 System.exit(0);
                  
             if (newMidterm >= 0)
             
                 midterm = newMidterm;
             
             else
             
                 System.out.println("Invalid score!");
                 System.exit(0);
                 
         if (newFinalG >= 0)
             
                 finalG = newFinalG;
             
             else
             {
                 System.out.println("Invalid score!");
                 System.exit(0);
             }
        
         if (newOverallS >= 0)
             
                 overallS = newOverallS;
             
             else
             {
                 System.out.println("Invalid score!");
                 System.exit(0);
             }
               
    }   
       
        public double getQuiz1()   //Accessors
         {
             return quiz1;
         }
        public double getQuiz2()
         {
             return quiz2;
         }
        public double getMidterm()
         {
             return midterm;
         }
        public double getFinalG()
         {
             return finalG;
         }
         public double getOverallS()
         {
             return  (finalG * .50 + midterm * .25 + quiz1 + quiz2 * 1.25);
         }
         public char getLetterG()
         {
             return letterG;
         }
         

    public void writeOutput()
         {
             System.out.println("Quiz 1 score is: " + quiz1 + "%");
             System.out.println("Quiz 2 score is: " + quiz2 + "%");
             System.out.println("Midterm score is: " + midterm + "%");
             System.out.println("Final Exam score is: " + finalG + "%");
             System.out.println("Course overall score is " + overallS + "%");
             System.out.println("Grade for the class is " + letterG);
         }
    }



and my main method
   
    public static void main(String[] args)
    {
        Grade grader = new Grade();
        grader.readInput();
        grader.writeOutput();

    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Question regarding a grading program

#2 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1376
  • View blog
  • Posts: 3,027
  • Joined: 05-April 11

Re: Question regarding a grading program

Posted 10 October 2012 - 12:08 AM

You don't call the methods anywhere in your program

Is it just me or does your code look just like this
Link

On two different accounts, great :)

This post has been edited by CasiOo: 10 October 2012 - 12:08 AM

Was This Post Helpful? 1
  • +
  • -

#3 asianhulk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: Question regarding a grading program

Posted 10 October 2012 - 10:31 AM

View PostCasiOo, on 10 October 2012 - 12:08 AM, said:

You don't call the methods anywhere in your program

Is it just me or does your code look just like this
Link

On two different accounts, great :)

Haha, that person is probably in my class... No pun intended. I'll post my updated code when I get home. Thanks for the reply
Was This Post Helpful? 0
  • +
  • -

#4 asianhulk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: Question regarding a grading program

Posted 13 October 2012 - 12:46 PM

This is what I have, I think I have the calling method in my main class for overallS and letterG but still can't get it. Any help is appreciated, thanks in advance.


import java.util.Scanner;
public class Grade
{
    private double quiz1, quiz2;
    private double midterm, finalG, overallS;
    private char letterG;
    
    
    public void readInput()
    {
        Scanner keyboard = new Scanner(System.in);
        do
        {
            System.out.println("Please enter the score from Quiz 1, from 0 to "
                    + "10: ");
            quiz1 = keyboard. nextDouble();
            if (quiz1 < 0 || quiz1 > 10) 
            {
                System.out.println("Invalid Entry!  Enter a score from 0 to "
                        + "10: ");
            }
         }while (quiz1 < 0 || quiz1 > 10);
        do
        {
            System.out.println("Please enter the score from Quiz 2, from 0 to "
                    + "10: ");
            quiz2 = keyboard. nextDouble();
            if (quiz2 < 0 || quiz2 > 10)
            {
                System.out.println("Invalid entry!  Enter a score from 0 to "
                        + "10: ");
            }
         }while (quiz2 < 0 || quiz2 > 10);
         do
        {
            System.out.println("Please enter the score from the midterm, from"
                    + " 0 to 100: ");
            midterm = keyboard. nextDouble();
            if (midterm < 0 || midterm > 100)
            {
                System.out.println("Invalid entry!  Enter a score from 0 to "
                        + "100: ");
            }
         }while (midterm < 0 || midterm > 100);
         do
        {
            System.out.println("Please enter the score from the final exam, "
                    + "from 0 to 100: ");
            finalG = keyboard. nextDouble();
            if (finalG < 0 || finalG > 100)
            {
                System.out.println("Invalid entry!  Enter a score from 0 to "
                        + "100: ");
            }
         }while (finalG < 0 || finalG > 100);
    }
    
     public static double overallS(double finalG, double midterm, double quiz1,
             double quiz2) //Calculation of Overall Score
    {
       return (finalG * .50 + midterm * .25 + quiz1 + quiz2 * 1.25);
       //I spent 4 hours trying to declare 'overallS' with the equation with no avail.
       //letterG probably won't work because there is no overallS formulated.
    }
    
   public final void letterG()    //Assigning letter grade
   {if (overallS >= 90) 
       {
           letterG = 'A';
       }
   else if (overallS >= 80)
       {
           letterG = 'B';
       }
   else if (overallS >= 70)
       {
           letterG = 'C';
       }
   else if (overallS >= 60)
       {
           letterG = 'D';
       }
   else{
           letterG = 'F';
       }
   }         
    
    public void setGrade (double newQuiz1, double newQuiz2, double newMidterm, 
           double newFinalG, double newOverallS)    //Mutators
         {
             if (newQuiz1 >= 0)
             
                 quiz1 = newQuiz1;
             
             else
             
                 System.out.println("Invalid score!");
                 System.exit(0);
                
                 
             if (newQuiz2 >= 0)
             
                 quiz2 = newQuiz2;
             
             else
             
                 System.out.println("Invalid score!");
                 System.exit(0);
                  
             if (newMidterm >= 0)
             
                 midterm = newMidterm;
             
             else
             
                 System.out.println("Invalid score!");
                 System.exit(0);
                 
         if (newFinalG >= 0)
             
                 finalG = newFinalG;
             
             else
             {
                 System.out.println("Invalid score!");
                 System.exit(0);
             }
        
         if (newOverallS >= 0)
             
                 overallS = newOverallS;
             
             else
             {
                 System.out.println("Invalid score!");
                 System.exit(0);
             }
               
    }   
       
        public double getQuiz1()   //Accessors
         {
             return quiz1;
         }
        public double getQuiz2()
         {
             return quiz2;
         }
        public double getMidterm()
         {
             return midterm;
         }
        public double getFinalG()
         {
             return finalG;
         }
         public double getOverallS()
         {
             return  overallS;
         }
         public char getLetterG()
         {
             return letterG;
         }
         

    public void writeOutput()
         {
             System.out.println("Quiz 1 score is: " + quiz1 + "%");
             System.out.println("Quiz 2 score is: " + quiz2 + "%");
             System.out.println("Midterm score is: " + midterm + "%");
             System.out.println("Final Exam score is: " + finalG + "%");
             
         }
    }



main class:


public class GradingProgram {

    public static void main(String[] args)
    {
        Grade grader = new Grade();
        grader.readInput();
        grader.writeOutput();
        System.out.println("Course overall score is " + grader.getOverallS() + "%");
        System.out.println("Grade for the class is " + grader.getLetterG());
    }
}


Was This Post Helpful? 0
  • +
  • -

#5 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Question regarding a grading program

Posted 13 October 2012 - 12:58 PM

This took me a while to figure out what was going on. :dontgetit:

Then I realized that there is massive confusion because you named the double overallS the same as your method overallS. You are never setting a value for overallS. It's always 0.
Was This Post Helpful? 0
  • +
  • -

#6 asianhulk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-October 12

Re: Question regarding a grading program

Posted 13 October 2012 - 04:19 PM

View PostKinaces, on 13 October 2012 - 12:58 PM, said:

This took me a while to figure out what was going on. :dontgetit:

Then I realized that there is massive confusion because you named the double overallS the same as your method overallS. You are never setting a value for overallS. It's always 0.

Ouch! I stared at this program for 4 hours, and couldn't see this :( Thanks for the insight! I wish this stuff would come more naturally to me *shrug*
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1