10 Replies - 12811 Views - Last Post: 28 October 2010 - 10:12 PM Rate Topic: -----

#1 Ace1stCav  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-July 10

Compute Grade

Posted 28 October 2010 - 11:02 AM

Hey guys,
I'm stuck on this project. I think I'm heading in the right direction, but could use some critical feedback. Thanks!

Input: Name of student, number of points
Output: Student name, points, and grade

import java.util.Scanner;

public class PP1 {
	public static void main(String args[]){
	}{
	
	Scanner input = new Scanner(System.in);

int Student_Points;
int Student_Name;
int Student_Points;



System.out.print("Enter students name");//Prompt user to enter students name
System.out.print("Enter students points");//Prompt user to enter students points
{
	if (Student_Points >= 90)
    {
		System.out.print("Grade is A");}
else if(Student_Points >= 80)
{ System.out.println("Grade is B");}
else if(Student_Points >=70){
	System.out.print("Grade is C");}
else if(Student_Points >=60){
	System.out.print("Grade is D");}
   else {
	   System.out.print("Grade is F");}

System.out.println(Student_Points);
System.out.println(Student_Name);
System.out.println(Student_Grade);

}





Is This A Good Question/Topic? 0
  • +

Replies To: Compute Grade

#2 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 72
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Compute Grade

Posted 28 October 2010 - 11:14 AM

Where exactly are you stuck at? Error messsages? What are you attempting to do?
Was This Post Helpful? 0
  • +
  • -

#3 Ace1stCav  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-July 10

Re: Compute Grade

Posted 28 October 2010 - 11:16 AM

View PostSarumanTheWhite, on 28 October 2010 - 10:14 AM, said:

Where exactly are you stuck at? Error messsages? What are you attempting to do?


I'm stuck on the syntax to link the user input with the output of the program. Along with the "return" value
Was This Post Helpful? 0
  • +
  • -

#4 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 72
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Compute Grade

Posted 28 October 2010 - 11:21 AM

Oh, so you're not sure how to store user input into variables?

Try:

Student_Points = input.nextInt();



Take a look at the Scanner class.

This post has been edited by SarumanTheWhite: 28 October 2010 - 11:23 AM

Was This Post Helpful? 1
  • +
  • -

#5 Ace1stCav  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-July 10

Re: Compute Grade

Posted 28 October 2010 - 02:37 PM

Ok...I have the scanner half way worked out..Still a bit confused.For some reason I'm getting an error on "import java.util.Scanner too. Here is the code I have written so far... Can anyone identify syntax/computing errors please?

import java.util.Scanner;

public class PP1 {
	public static void main(String args[]){
	}{
	
	Scanner input = new Scanner(System.in);
	System.out.println();

	Student_Points = input.nextInt();
	Student_Name = input.nextInt();
	Student_Grade = input.nextInt();



System.out.println("Enter students name");//Prompt user to enter students name
System.out.println("Enter students points");//Prompt user to enter students points
{
	if (Student_Points >= 90)
    {
		System.out.print("Grade is A");}
else if(Student_Points >= 80)
{ System.out.println("Grade is B");}
else if(Student_Points >=70){
	System.out.print("Grade is C");}
else if(Student_Points >=60){
	System.out.print("Grade is D");}
   else {
	   System.out.print("Grade is F");}

System.out.println(Student_Points);
System.out.println(Student_Name);
System.out.println(Student_Grade);

}

Was This Post Helpful? 0
  • +
  • -

#6 SarumanTheWhite  Icon User is offline

  • D.I.C Regular

Reputation: 72
  • View blog
  • Posts: 352
  • Joined: 04-November 08

Re: Compute Grade

Posted 28 October 2010 - 02:45 PM

I notice you seem to have a lot of brackets all over the place. Some of which are there for no real beneficial reason. Remove some of them and that might fix some of your problems. Just make sure they all match each other.
Was This Post Helpful? 0
  • +
  • -

#7 Ace1stCav  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-July 10

Re: Compute Grade

Posted 28 October 2010 - 04:13 PM

View PostSarumanTheWhite, on 28 October 2010 - 01:45 PM, said:

I notice you seem to have a lot of brackets all over the place. Some of which are there for no real beneficial reason. Remove some of them and that might fix some of your problems. Just make sure they all match each other.


I fixed some of the bracket issues, however it didn't resolve the(syntax error on toke"import" throw expected)issue.Additionally, can u comment on my output/strings. I'm confusing the hell out of myself at this point.By the way,I really appreciate the feedback you've given so far!
import java.util.Scanner;

public class PP1 
{
	{public static void main(String args[])
		
	
	Scanner input = new Scanner(System.in);
	

	Student_Points = input.nextInt();
	Student_Name = input.nextInt();
	Student_Grade = input.nextInt();



System.out.println("Enter students name");//Prompt user to enter students name
System.out.println("Enter students points 0-100");//Prompt user to enter students points

	if (Student_Points >= 90)
    
		System.out.print("Grade is A");
else if(Student_Points >= 80)
 System.out.println("Grade is B");
else if(Student_Points >=70)
	System.out.print("Grade is C");
else if(Student_Points >=60)
	System.out.print("Grade is D");
   else 
	   System.out.print("Grade is F");

System.out.println(Student_Points);
System.out.println(Student_Name);
System.out.println(Student_Grade);

	


}
	


Was This Post Helpful? 0
  • +
  • -

#8 slixtrix  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 24-April 10

Re: Compute Grade

Posted 28 October 2010 - 04:24 PM

im confused to the way you have your code, why are you asking for the user to input things after you take in the lines?

im not sure if this will work, but try this:

System.out.println("Enter students name");//Prompt user to enter students name
Student_Name = input.nextLine();

System.out.println("Enter students points 0-100");//Prompt user to enter students points
Student_Points = input.nextInt();



and take out
Student_Grade = input.nextInt();

because with your code, your not needing to take in an input for the Grade, you already have the if statement that finds out the grade for them....


Edit: now that i look at it, you need to declare your variables Student_name as a String, and Student_Points as an int....try and solve this with this information, and if you can't figure it out, repost on here and i'll try to help you further.

Edit2: and also when your asking an input from the console such as a name, your going to be using the command yourScannerVariable.nextLine() because nextInt() takes in a number as opposed to a string.

This post has been edited by slixtrix: 28 October 2010 - 04:31 PM

Was This Post Helpful? 1
  • +
  • -

#9 Ace1stCav  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-July 10

Re: Compute Grade

Posted 28 October 2010 - 04:31 PM

Ohhhhh I see...Good point..You have to store the values following each input..Starting to make sense now...Oh, and I'm not sure why I was asking the user to input things after taking in the lines...It wasn't intentional, I can tell you that much! :surrender::) Thanks!
Was This Post Helpful? 0
  • +
  • -

#10 Ace1stCav  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 06-July 10

Re: Compute Grade

Posted 28 October 2010 - 06:35 PM

Okay..Here I am again. I think I've got some of the syntax worked out..I have another question too. How I have it written, isn't the system going to output the Student_Score as soon as the user inputs 1-100? How do I make it hold the value until the final output statement? Will something like this work ?
if (Student_Points >= 90)
    
		Student_Points =("A");
       else if(Student_Points >= 80)
      Student_Points = ("B");
else if(Student_Points >=70)
	Student_Points = ("C");
else if(Student_Points >=60)
	Student_Points = ("D");
   else 
	   Student_Points = ("F");

System.out.println("Hello"+ Student_Name + "Your points for the test are"+Student_Points);






Here is what I have so far, minus the possible changes I posted above. Thanks!
import java.util.Scanner;// initialize Scanner 

public class PP1 
{
	{public static void main(String args[])
		

	//Declare variables
	String Student_Name;
	int Student_Points;
		
	Scanner input = new Scanner(System.in);//Scanner object

System.out.println("Enter students name");//Prompt user to enter students name
Student_Name = input.nextLine();

System.out.println("Enter students points 0-100");//Prompt user to enter students points
Student_Points = input.nextInt();
	
if (Student_Points >= 90)
    
		System.out.print("Grade is A");
else if(Student_Points >= 80)
 System.out.println("Grade is B");
else if(Student_Points >=70)
	System.out.print("Grade is C");
else if(Student_Points >=60)
	System.out.print("Grade is D");
   else 
	   System.out.print("Grade is F");


System.out.println("Hello"+ Student_Name + "Your points for the test are"+Student_Points);


System.out.println("Hello"+ Student_Name + "Your points for the test are"+Student_Points); is suposed to be:
System.out.println("Hello"+ Student_Name + "Your grade for the test is"+Student_Points);
Was This Post Helpful? 0
  • +
  • -

#11 slixtrix  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 24-April 10

Re: Compute Grade

Posted 28 October 2010 - 10:12 PM

for what your trying to do, i would declare a class variable such as

char student_Grade;


and i would do:

if (Student_Points >= 90)
   student_Grade = 'A';
else if(Student_Points >= 80)
   student_Grade = 'B';
else if(Student_Points >=70)
   student_Grade = 'C';
else if(Student_Points >=60)
   student_Grade = 'D';
   else 
   student_Grade = 'F';



and then just incorporate each variable you have into a System.out.print() statement for your ending..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1