Page 1 of 2 12 LastLast
Results 1 to 20 of 37
  1. #1
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default scanner questions

    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.



    showing this would i need to import a scanner for gpa?
    and if i do could it be

    Scanner scan = new Scanner ?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by socboy6579 View Post
    showing this would i need to import a scanner for gpa?
    and if i do could it be

    Scanner scan = new Scanner ?
    That's not how to construct a class -- you may need to review your notes on the way to call a constructor, but you will need parenthesis and in the case of Scanner, you will need to pass in a parameter. The tutorial will show you how: Scanning (The Java™ Tutorials > Essential Classes > Basic I/O)

    On an unrelated note, you appear to be fragmenting this discussion amongst several threads and have ignored responses to your questions in previous threads. If you want to encourage folks to help you, you should consider replying to the help they give.
    Last edited by Fubarable; 10-24-2010 at 10:56 PM.

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

    Default

    showing this would i need to import a scanner for gpa?

    One way of obtaining the input would be to use an instance of Scanner.

    and if i do could it be

    Scanner scan = new Scanner ?

    No, that is not correct Java syntax. Read your textbook to find out the correct usage of the "new" keyword. And look at the Scanner API docs for the valid constructors you might use. And an example of creating a scanner to read input from the console.

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

    Default

    so basically from the information given above i need to give the letter grades a value from the 1.0 - 4.0 GPA scale .. so far for scanner i have this

    Java Code:
    import java.util.Scanner;
    public class grades {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner in = new Scanner(System.in);
            double gpa;
        }
    }

  5. #5
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    That looks right, now all you need to do is get the gpa from the user using your new scanner.
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    caould i use if statements to assign the letter values to a numerical value

  7. #7
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    Quote Originally Posted by socboy6579 View Post
    caould i use if statements to assign the letter values to a numerical value

    Yeah, that or use a switch statement. Depends on what you are familiar with using already.
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    thank you so farr for your help

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

    Default

    Java Code:
    Scanner in = new Scanner(System.in);

    Yes, that looks a lot better.

    so basically from the information given above i need to give the letter grades a value from the 1.0 - 4.0 GPA scale ..

    You are not at that point yet. You are still working on the part of the assignment that says "that accepts the letter grades for a student". At this point you should decide how the user is going to input the letter grades: all on one line? On multiple lines? Both?

    Extend what you have written to:

    * prompt the user (tell them what to enter)
    * use the scanner methods to obtain the grade letters one by one

    --------

    For each grade letter you obtain your program will have to keep track of the information you will need to produce the output. This may be to keep track of the gpa. But a common tactic when you are calculating an average to actually keep track of two things: the total grade points so far and the number of grades entered. Using this information you can calulate the gpa once all the grades are in. In your case you also need a variable to keep track of whether you have seen an 'F' grade as this also has a bearing on the message that will be output.

    (The simplest way converting from grade letters to grade points is to write a separate method for this. It can be as straightforward as a bunch of if-elseif-... or a switch statement. The method's argument is the char or String and its return value is the number of grade points.)

    Perhaps before you go a lot further with the coding you should stop and figure out a battle plan. You need a plain English (but *very* precise) recipe for how you are going to output the appropriate message: what information you are going to keep track of, how it will be updated for each grade letter, and how it will be used to determine the message.
    Last edited by pbrockway2; 10-24-2010 at 11:16 PM. Reason: ... very slow ;(

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

    Default

    Java Code:
    import java.util.Scanner;
    public class grades {
    
        /**
         * @param args
         */
        public static  main(String[] args); boolean t double b {
            // TODO Auto-generated method stub
            Scanner in = new Scanner(System.in);
            double GPA;
            System.out.println("GPA = ");
            if (3.0 <= GPA <= 4.0){
                System.out.println("A");
            }
        }
    }
    with this code, im trying to get it to print a letter grade given from the if statement of the GPA.. im basically trying to gett when i enter a GPA number from 1.0 to 4.0 it would give me a letter from F,D,C,B,A. Am i on the right track?

  11. #11
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    The syntax is wrong on your if statement. What you need to write is a compound if statement combining two logical calculations. Using the OR operator '||'. Also refer to the following link to get an idea of how to use the scanner class to receive a double from the user: JAVA Scanner Class
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    im having an error. i think i am not using the else if statements correctly this is the code
    Java Code:
    import java.util.Scanner;
    public class grades {
    
    	/**
    	 * @param args
    	 * @return 
    	 */
    	public static  void main(String[] args);
    		
    		// TODO Auto-generated method stub
    		Scanner in = new Scanner(System.in);
    		double GPA=in.nextDouble();
    		System.out.println("GPA = ");
    		if ( GPA == 4.0){
    			System.out.println("A");
    		
    		}else{
    				if (GPA >=3.0 || < 4.0)
    					System.out.println("B");
    				
    		}else{
    				if (GPA >=2.0 || < 3.0)
    					System.out.println("C");
    						
    		}else{ 
    				if (GPA >=1.0 || < 2.0)
    					System.out.println("D");}
    	else {
    		if (GPA == 0){
    			System.out.println("F");
    	}

  13. #13
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    The syntax on your "else if" statements is wrong. Instead of writing:

    Java Code:
    }else{
    				if (GPA >=3.0 || < 4.0)
    					System.out.println("B");

    It should look more like:

    Java Code:
    else if( GPA >= 3.0 || (this is wrong, fix syntax here as well) )
    {
         System.out.println("B");
    }
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    i changed the format of my else if statments thank you. but when i run this code
    Java Code:
    mport java.util.Scanner;
    public class grades {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		Scanner in = new Scanner(System.in);
    		double GPA=in.nextDouble();
    		System.out.println("GPA = ");
    		if ( GPA == 4.0)
    		{
    			System.out.println("A");
    		}
    			else if (GPA >=3.0 || GPA < 4.0)
    			{
    					System.out.println("B");
    			}	
    			else if (GPA >=2.0 || GPA < 3.0)
    			{
    					System.out.println("C");
    			}			
    			else if (GPA >=1.0 ||GPA < 2.0)
    			{	
    					System.out.println("D");
    			}
    	else if (GPA == 0)
    	{
    			System.out.println("F");
    	}	
    	}
    	}
    the code does not print anytihng.. not even the scanner saying "GPA ="? im stuck :/

  15. #15
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    The code works fine for me. You have to type in your GPA and hit enter before it will print anything. Maybe you should add a prompt for the user to enter the GPA.
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    when i run the code, there is no prompt that comes up saying "GPA ="

  17. #17
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    Look at these lines:

    Java Code:
    double GPA=in.nextDouble();
    System.out.println("GPA = ");

    Which line do you get the GPA on?
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    im a beginner in an AP Computer Science class, the prompt is the print method, and im guessing you get the GPA on the first line?

  19. #19
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    Quote Originally Posted by socboy6579 View Post
    im a beginner in an AP Computer Science class, the prompt is the print method, and im guessing you get the GPA on the first line?

    Exactly, so you are trying to get the GPA before you even prompt for it.
    Sincerely, Joshua Green
    Please REP if I help :)

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

    Default

    ok thank you very much. and now i realized how aggravting coding can get. It wants to output a value :/ then saying eligible or not depending on the circumstances above for my assignment.

    it says
    "Example of run output: GPA = 3.75 Eligible" I did the complete opposite and read the entire assignment wrong :O

Page 1 of 2 12 LastLast

Similar Threads

  1. Using scanner for CSV
    By getName() in forum Advanced Java
    Replies: 7
    Last Post: 06-20-2010, 04:33 PM
  2. Help With Scanner
    By jtmoney0511 in forum New To Java
    Replies: 10
    Last Post: 10-12-2009, 11:24 PM
  3. Need help with scanner.
    By mainy in forum New To Java
    Replies: 3
    Last Post: 07-28-2009, 02:11 PM
  4. Scanner questions
    By Suzanne1187 in forum New To Java
    Replies: 12
    Last Post: 03-12-2009, 02:31 AM
  5. need help with scanner
    By whiterex in forum New To Java
    Replies: 1
    Last Post: 04-22-2008, 01:41 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
  •