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

Thread: letterGrade not print out on my code

  1. #1
    Banned
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy letterGrade not print out on my code

    import java.util.Scanner;
    public class { // BEGIN CLASS
    public ()
    {
    }//END Constructor
    public static void main(String[]args)
    {//BEGIN main()

    Scanner input = new Scanner (System.in);


    String letterGrade = "";

    String studentName = "";
    String bannerID = "";
    String course = "";
    int grades;
    String password = "";
    double average = 0.0;
    int attempt = 2;
    int gradesAttempt;
    int counterGradeAttempt = 1;
    int gradesTotal = 0;


    for (int counter =1; counter <=3; counter += 1)
    {
    System.out.printf("\nPlease enter the password: ");
    password = input.nextLine();

    if (!(password.equals("LipSmacker")))
    {

    if ( counter == 3)
    {


    System.out.printf("Sorry, invalid password! No more attempts left. Exiting program.");
    counter = 5;

    }

    else
    {

    System.out.printf("\n\nInvalid password you have %d attempts left", attempt);
    attempt = attempt - 1;
    }



    }

    else
    {
    counter = 4;

    System.out.printf("Enter your Banner ID: ");
    bannerID = input.nextLine();

    System.out.printf("Enter your Name: ");
    studentName = input.nextLine();

    System.out.printf("Enter your course: ");
    course = input.nextLine();

    System.out.printf("How many grades will be entered? ");
    gradesAttempt = input.nextInt();

    do


    {


    System.out.printf("\nPlease enter grade no %d: " ,counterGradeAttempt);
    grades = input.nextInt();
    gradesTotal += grades;

    counterGradeAttempt = counterGradeAttempt + 1;


    average = gradesTotal / gradesAttempt;



    switch ((int)average )
    {
    case 10: letterGrade = "A";
    break;
    case 9: letterGrade = "A";
    break;
    case 8: letterGrade = "B";
    break;
    case 7: letterGrade = "C";
    break;
    case 6: letterGrade = "D";
    break;


    }


    } while ( counterGradeAttempt <= gradesAttempt);


    System.out.printf("STUDENTS CURRENT GRADE FOR %s" ,course);

    System.out.printf("\n\nBanner ID: %s" ,bannerID);

    System.out.printf("\nStudent Name: %s" ,studentName);

    System.out.printf("\nAverage of grades: %.2f" ,average);

    System.out.printf("\nLetter grade: %s " ,letterGrade);













    }






    }



    System.exit(0);
    }
    } //END MAIN()
    I cant get the letterGrade to print out


  2. #2
    Banned
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: letterGrade not print out on my code

    figured it out, the switch need to be / 10.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,106
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: letterGrade not print out on my code

    letterGrade not print out on my code
    A problem would be that you have no default: case in the switch statement to print out a message about the value of average. Your code should try to handle ALL the legal possibilities.

  4. The Following User Says Thank You to Norm For This Useful Post:

    troj4nk1ng (July 8th, 2011)

  5. #4
    Banned
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: letterGrade not print out on my code

    True, but still that was not the case, the average was apparently to high for the switch cases, so I had to take them down a notch.

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,106
    Thanks
    65
    Thanked 2,717 Times in 2,667 Posts

    Default Re: letterGrade not print out on my code

    average was apparently to high for the switch cases
    It would NOT be too high for the default. The message that would print there would tell you the problem the first time you ran the code.

Similar Threads

  1. how can i print the out put !
    By Faha in forum Java IDEs
    Replies: 5
    Last Post: December 30th, 2010, 04:41 AM
  2. to print pattern
    By Charanleen in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 3rd, 2010, 07:54 AM
  3. print code to browser
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: April 21st, 2010, 01:09 AM
  4. [SOLVED] why does this code print 0.0 for the value and "F" as the letter grade?
    By etidd in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 12th, 2010, 10:38 PM
  5. Can someone please tell me why my code doesn't print out anything?
    By deeerek in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 6th, 2010, 08:35 AM