Results 1 to 9 of 9
  1. #1
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default Questions on my code!

    1. Write a program that accepts the letter grades for a student, calculates the student's gpa, and prints it out, along with one of the following five messages:

    Eligible
    Ineligible, taking less than 4 classes
    Ineligible, gpa below 2.0
    Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
    Ineligible, gpa below 2.0 and has F grade

    2. Your program must use an appropriate sequence of nested if-else statements to print out the appropriate message.

    3. The message "Ineligible, taking less than 4 classes" has priority over the other 3 ineligible cases.

    4. The class will not ask the user for how many grades are in a student's report card. The program will continue to read grades until a non-grade character is input. At this point, some type of loop will cease and the program prints the GPA value and the eligibility message.

    5. Example of run output: GPA = 3.75 Eligible

    6. You do not have to print out any of the individual grades.

    7. Your program should allow input of grades in either upper or lower case.



    Java Code:
     import java.util.Scanner;
    public class Grades {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		// TODO Auto-generated method stub
    		Scanner grade= new Scanner(System.in);
    		for (int count = 0; count < 30; count++)
    		System.out.println("Enter letter grade: A, B, C, D, F");
    		String GradeValue = grade.nextLine();
    		{
    			if (GradeValue.equals("A"));
    				GPA = 4.0;
    		}
    		{
    			if (GradeValue.equals("B"));
    				GPA = 3.0;
    		}
    		{
    			if (GradeValue.equals("C"));
    				GPA = 2.0;
    		}
    		{
    			if (GradeValue.equals("D"));
    				GPA = 1.0;
    		}
    		{
    			if (GradeValue.equals("F"));
    				GPA = 0.0;
    		}
    	}
    
    }
    this is the code i have for my program so far, i am just stuck for the user input. I have to keep on entering grades until i reach an exception like with an f grade shown above. How do i have the scanner keep prompting me for grades. I am just stuck here and in a few more spots and my code will work, that i will enter the following letter grade equilvalent to a numeric gpa, and the code will terminate when it approaches one of the problems. how would i put the grade f to take precedence over everything and once when i run a grade f the code will terminate?!?!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Does that code compile?

    There's little point in moving forward if it has syntax errors. (If you can't understand the compiler's message copy and post the entire thing.)

    Use standard Java naming conventions: gradeValue and it might pay to review your textbook for the syntax of basic structures. An if statement looks like this:

    Java Code:
    String gradeValue = grade.nextLine();
    if (gradeValue.equals("A")) 
    {
        GPA = 4.0;
    }

  3. #3
    tashimoto is offline Member
    Join Date
    Sep 2010
    Location
    Oregon, usa
    Posts
    69
    Rep Power
    0

    Default

    How do i have the scanner keep prompting me for grades.
    Here's an example of a while loop that will allow user to continue:
    Java Code:
    String another = "y";
    while (another.equalsIgnoreCase("y"))
    {
       // code to do stuff 
    
       System.out.println ("Enter y to Continue: ");
       another = scan.nextLine();
    
    }

  4. #4
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    the code wont compile because of the GPA isnt declared as anythingg. should i put it as a double?>

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Yes - it has a decimal point, it's a double.

  6. #6
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    Why when i run this code
    Java Code:
    import java.util.Scanner;
    public class Grades {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		
    		// TODO Auto-generated method stub
    		Scanner grade= new Scanner(System.in);
    		for (int count = 0; count < 30; count++)
    		System.out.println("Enter letter grade: A, B, C, D, F");
    		String GradeValue = grade.nextLine();
    		
    		if (GradeValue.equals("A"));
    				double GPA;
    				{
    					GPA = 4.0;
    				}
    		
    		
    			if (GradeValue.equals("B"));
    				{
    					GPA = 3.0;
    				}
    		
    		
    			if (GradeValue.equals("C"));
    				{
    					GPA = 2.0;
    				}
    		
    		
    			if (GradeValue.equals("D"));
    				{
    					GPA = 1.0;
    				}
    		
    		
    			if (GradeValue.equals("F"));
    				{
    					GPA = 0.0;
    				}
    		
    	}
    
    }
    it outputs the scanner like 30 times. i think because of the count? please help

  7. #7
    maknib is offline Member
    Join Date
    Nov 2010
    Posts
    90
    Rep Power
    0

    Default

    Can i just Ask, what degree is this assignment from?

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    it outputs the scanner like 30 times. i think because of the count?

    You have a for loop that does something 30 times. But what is it supposed to do 30 times? Whatever it is, it should go between braces.

    Java Code:
    for (int count = 0; count < 30; count++)
      {
        // all the code that has to be
        // done 30 times goes
        // here
      }

    (A good practice, many find, is to always use braces even for one line blocks like your if statement. That way you can see at a glance being repeated.)

    -----

    @maknib: Sometimes it seems as if every Java course assigns this...

  9. #9
    maknib is offline Member
    Join Date
    Nov 2010
    Posts
    90
    Rep Power
    0

    Default

    Quote Originally Posted by socboy6579 View Post

    1. Write a program that accepts the letter grades for a student, calculates the student's gpa, and prints it out, along with one of the following five messages:

    Eligible
    Ineligible, taking less than 4 classes
    Ineligible, gpa below 2.0
    Ineligible, gpa above 2.0 but has F grade (note: gpa >= 2.0)
    Ineligible, gpa below 2.0 and has F grade

    2. Your program must use an appropriate sequence of nested if-else statements to print out the appropriate message.

    3. The message "Ineligible, taking less than 4 classes" has priority over the other 3 ineligible cases.

    4. The class will not ask the user for how many grades are in a student's report card. The program will continue to read grades until a non-grade character is input. At this point, some type of loop will cease and the program prints the GPA value and the eligibility message.

    5. Example of run output: GPA = 3.75 Eligible

    6. You do not have to print out any of the individual grades.

    7. Your program should allow input of grades in either upper or lower case.

    1. Seeing as you have this. "Ineligible, taking less than 4 classes" i would assume you need a counter to check if there was less than 4 entered.

    2. im guessing you need if{} else if{}... else{} and else is then its not a Grade letter

    3. this will need to be the first check in a sequence.

    4. sounds like you need to run this while it's equal to a Grade

    5. this is pretty straight foward. shows that you need a double var

    6. good so we store them instead?

    7. havn't seen this function myself but im guessing its something like string.toLower();


    This is how i would look at this and tackle it but again i'm normally wrong :)


    Quote Originally Posted by pbrockway2 View Post
    @maknib: Sometimes it seems as if every Java course assigns this...
    Cool! I just started a bachelor of technology in Computer studies and the first language is Java (also c, c++ c# php and others)

    so i figured why not start early and learn some JAVA :) i already know Actionscript (bits of it) and php so i'm loving JAVA so far. quickly ecoming my fav language AND i've always wondered what my assignments might look like.. heads up in here :)
    Last edited by maknib; 11-03-2010 at 03:39 AM.

Similar Threads

  1. Memory Leak questions, code review
    By mensaFool in forum Advanced Java
    Replies: 9
    Last Post: 03-08-2010, 05:27 PM
  2. UML, robust code, structure questions
    By mac in forum New To Java
    Replies: 2
    Last Post: 12-23-2009, 12:06 AM
  3. Some Questions
    By MuslimCoder in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 05:01 PM
  4. questions for 1yr exp
    By rahaman.athiq in forum Java Servlet
    Replies: 2
    Last Post: 11-26-2008, 02:13 AM
  5. Questions About JSP?
    By mtz1406 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-19-2008, 08:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •