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 3 of 3

Thread: gradebook

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default gradebook

    Hey guys new to the forum and im a beginner with java and I need to write a basic gradebook program. Part of our assignment is to
    "Add the following method header outside your main method, but still inside your GradeBook class:
    public static char calculateGrade(double score) { }
    The body of this method will perform the task of translating a numeric value into a letter grade. To accomplish this task, the method accepts a double value, representing a single score, and returns a char value of either ‘A’, ‘B’, ‘C’, ‘D’ or ‘F’. Within the method body, you will need to use a nested selection statement, like the one shown on page 82 of the 10th Edition textbook.
    The calculateGrade() method should be invoked AFTER the user inputs a score. Following the invocation of calculateGrade(), the program should output a message like “The score 72.0 is a C” for every score that is entered. Because calculateGrade() returns a char value, a switch can be used to print this output message."

    I dont know how to incorporate that into the program i have so far.

    import java.util.Scanner; // program uses class Scanner

    public class Gradebook {

    public static void main (String[] args) {

    Scanner keyboard= new Scanner(System.in);

    int numberofgrades= 0;
    double grade= 0;
    double avg= 0;
    double sum= 0;
    int A,B,C,D,F;

    A=0;
    B=0;
    C=0;
    D=0;
    F=0;

    System.out.println ("Enter a grade between 0 and 100 and type -1 when you are finished.");

    do{

    grade=keyboard.nextInt();

    if(grade !=-1){


    sum= sum + grade;

    }

    if(grade >= 0.0){
    numberofgrades++;


    if(grade>=90.0 && grade <= 100.0){

    A++;

    }
    if(grade>=80.0 && grade <= 89.9){



    B++;

    }

    if(grade>=70.0 && grade <= 79.9){



    C++;

    }

    if(grade>=60.0 && grade <= 69.9){



    D++;

    }

    else if(grade>=0.0 && grade <= 59.9){




    F++;
    }

    }

    }

    while (grade >= 0.0);

    avg= sum/ numberofgrades;
    System.out.println("Total number of grades is "+ numberofgrades);
    System.out.println("Total number of A's is "+A);
    System.out.println("Total number of B's is "+B);
    System.out.println("Total number of C's is "+C);
    System.out.println("Total number of D's is "+D);
    System.out.println("Total number of F's is "+F);
    System.out.println("Average score is "+ avg);

    }


    }



    Let me know. Thanks.


  2. #2
    Junior Member
    Join Date
    Mar 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: gradebook

    Looks like you need to make a class called GradeBook and inside that class make the calculateGrade() method. it should take in a double as a parameter. Like calculateGrade(double grade){} then you want your grade selection code that you have in your main method in that method, but instead of increment the amount of people who received that grade, instead System.out.println("The score " + grade + " is a C"); But instead of just C, put whatever grade falls under the proper selection. It can also increment the amount of grades recieved like you already have. Then in your main method you could set grade = 0, then

    System.out.println("Enter grade or -1 to exit: ");
    grade = keyboard.nextInt();
    while (grade != -1)
    System.out.println("Enter grade or -1 to exit: ");
    grade = keyboard.nextInt();
    gradeCalc.calculateGrade(grade);
    }

    The calculateGrade(grade) will then print out a message saying what grade that score is and increment the grade counter. You should also put a check in calculateGrade to make it exit if grade == -1 in order for the while loop i said to work. If they entered -1 calculateGrade() would exit, then it would go to beginning of while loop and be like "oop! we are done!" then carry on with the rest of your main method.

    I hope that helps and answers your question.

  3. #3
    Member
    Join Date
    Feb 2014
    Posts
    38
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Default Re: gradebook

    Hello. I don't understand what all this is for:
    avg= sum/ numberofgrades;
    System.out.println("Total number of grades is "+ numberofgrades);
    System.out.println("Total number of A's is "+A);
    System.out.println("Total number of B's is "+B);
    System.out.println("Total number of C's is "+C);
    System.out.println("Total number of D's is "+D);
    System.out.println("Total number of F's is "+F);
    System.out.println("Average score is "+ avg);

    The assignment did not ask for you to do that. From my understanding of your assignment, all it asked you to do was to check if the score you inputted is a A or B or C or D or F. The method that is used to check the score has to be called from the main method, so it would make sense for you to do something like Bawnawgwa said.

    This part of the code should go into the static method (calculateGrade).
     if(grade>=90.0 && grade <= 100.0){
     
    A++;
     
    }
    if(grade>=80.0 && grade <= 89.9){
     
     
     
    B++;
     
    }
     
    if(grade>=70.0 && grade <= 79.9){
     
     
     
    C++;
     
    }
     
    if(grade>=60.0 && grade <= 69.9){
     
     
     
    D++;
     
    }
     
    else if(grade>=0.0 && grade <= 59.9){
     
     
     
     
    F++;
    }

    Hope that helps.


    EDIT (If someone don't mind answering): Now, I wonder...How would I make the code so it would only run the The score...blah blah... is a <letter>
    AFTER all the points are inputted?

    Example:
    Enter grade or -1 to exit:
    90
    Enter grade or -1 to exit:
    100
    Enter grade or -1 to exit:
    -1

    The score 90 is an A.
    The score 100 is an A.
    Last edited by hkfrenchtoast; March 10th, 2014 at 01:31 AM.

Similar Threads

  1. Gradebook error?
    By KRUKUSA in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 27th, 2012, 07:31 AM
  2. java gradebook
    By gibson.nathan in forum Collections and Generics
    Replies: 1
    Last Post: December 24th, 2009, 09:23 PM

Tags for this Thread