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: java scanner programming help

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java scanner programming help

    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.

     
    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");
    	}

    iwas just wondering from my piece of code so far if this is correct and the syntax of my else if statements are also correct. i seem to have been getting stuck a very good amount of times so help is appreciated thank you


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: java scanner programming help

    Cross posted, with several responses before this was posted here
    scanner questions - Java Forums
    Also on
    Java Grades Programming Help!!? - Yahoo! Answers


    db

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: java scanner programming help

    Hello socboy6579,

    Welcome to the forums.

    There are lot's of problems with your code.

    You should be doing something like this:

    import java.util.Scanner;
     
    public class grades {
     
    	public static void main(String[] args){
     
        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");
        }
    }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Basic Java File I/O with Scanner Class Problem
    By miss confused in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 26th, 2010, 08:04 AM
  2. new to java programming GUI help
    By eg6_kaydoo in forum AWT / Java Swing
    Replies: 4
    Last Post: July 14th, 2010, 09:55 PM
  3. Java 3d Programming
    By Nickthecoder in forum Java Theory & Questions
    Replies: 1
    Last Post: May 5th, 2010, 10:48 PM
  4. Towards java programming...
    By emigrant in forum Member Introductions
    Replies: 1
    Last Post: February 15th, 2010, 03:17 AM
  5. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 14th, 2010, 06:42 AM