3 Replies - 677 Views - Last Post: 18 September 2009 - 02:13 PM Rate Topic: -----

#1 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

No clue where I went wrong on this program

Post icon  Posted 18 September 2009 - 01:34 PM

This is suppose to display an Accept message if:
A grade point average of 3.0 or above and an admission test score of atleast 60
or
A grade point average below 3.0 and an admission test score of at least 80

The program compiles but no matter what i enter its not displaying what i enter for gpa or score and so in turn the accept reject message does not work properly. I am not sure why its converting numbers to something I am not entering. Thanks for the help.
public class Admission	
{
	public static void main (String[] args) throws Exception 
	 {
		double gpa = 0.0;
		int score = 0;
		  System.out.println("Enter your High School GPA: ");
		  gpa = (double)System.in.read();
		  System.in.read();
		  System.in.read();
		  System.out.println("Enter admission test scrore: ");
		  score = (int)System.in.read();
		  System.in.read();
		  System.in.read();
		  System.out.println("The Grade Point Average is " + gpa);
		System.out.println("The Score is " + score);
		if ((gpa <= 3.0 && score >= 80) || (gpa >= 3.0 && score >= 60))
			System.out.println("Accept");
		else
			System.out.println("Reject");
	}



Is This A Good Question/Topic? 0
  • +

Replies To: No clue where I went wrong on this program

#2 thezboe  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 18-September 09

Re: No clue where I went wrong on this program

Posted 18 September 2009 - 01:43 PM

You need to use Scanner.

double gpa;

Scanner input = new Scanner(System.in);
System.out.println("Enter your High School GPA: ");
gpa = input.nextDouble();
//etc...


This post has been edited by thezboe: 18 September 2009 - 01:45 PM

Was This Post Helpful? 1
  • +
  • -

#3 vwyodapink  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 141
  • Joined: 12-May 09

Re: No clue where I went wrong on this program

Posted 18 September 2009 - 02:13 PM

Thanks a bunch I got it all figured out..
import java.util.Scanner;

public class Admission	
{
	public static void main (String[] args) throws Exception 
	 {
		double gpa = 0.0;
		int score = 0;
		  Scanner input = new Scanner(System.in);
		  System.out.println("Enter your High School GPA: ");
		  gpa = input.nextDouble();
		  System.out.println("Enter admission test scrore: ");
		  score = input.nextInt();
		  System.out.println("The Grade Point Average is " + gpa);
		System.out.println("The Score is " + score);
		if ((gpa <= 3.0 && score >= 80) || (gpa >= 3.0 && score >= 60))
			System.out.println("Accept");
		else
			System.out.println("Reject");
	}
}


Was This Post Helpful? 0
  • +
  • -

#4 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: No clue where I went wrong on this program

Posted 18 September 2009 - 02:13 PM

Try this...
public static void main (String[] args) throws Exception 
	 {
		double gpa = 0.0;
		int score = 0;
		Scanner scanner = new Scanner(System.in);
		  System.out.println("Enter your High School GPA: ");
		  gpa = scanner.nextDouble();
		  
		  System.out.println("Enter admission test scrore: ");
		  score = scanner.nextInt();
		  
		  
		  System.out.println("The Grade Point Average is " + gpa);
		System.out.println("The Score is " + score);
		if ((gpa <= 3.0 && score >= 80) || (gpa >= 3.0 && score >= 60))
			System.out.println("Accept");
		else
			System.out.println("Reject");
	}



EDIT: Opps..too late. >.< ignore my post please.

This post has been edited by AntonWebsters: 18 September 2009 - 02:14 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1