10 Replies - 1472 Views - Last Post: 19 April 2009 - 10:18 AM Rate Topic: -----

#1 mauribarri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-April 09

Grading Program

Post icon  Posted 12 April 2009 - 08:26 PM

I am working on a grading program

I must Utilize the Math class and round the number to zero decimal places, then use the int cast method to convert to an integer.(ensure you round it before type casting it)
Utilize a switch statement to determine the corresponding letter grade. Use the grading criteria from this course for the numbers. (ensure you accept all allowable numbers i.e. 70-79 and all in between)
Output the corresponding letter grade along with the initial number entered in decimal format utilizing the printf method and format specifiers. Output the number in only 3 decimal places.

in my switch
I must Get input for the grade letter in String format.
Utilize a switch statement to determine the corresponding output for the letter entered. (ensure you accept both upper and lower case letters.
Use the grading criteria from this course for the numbers. (you must use charAt( ) so the string will work with your switch)
Output the corresponding numbers values for the letter entered along with the letter initially entered.

Questions I have:
Is my code in the right direction?
Line 15 is giving me problems what I can I do to correct this but still be able create my rounding to the nearest whole number?
Am I missing anything?


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

		System.out.println("Welcome to Miguel's Grading Program");

		Scanner stdIn = new Scanner (System.in);
		char grade;
		char letterGrade;
		double numericGrade;

		System.out.print("Will you be using numbers or letters?");
		grade = stdIn.nextLine().charAt(0);
		public static RoundingMode valueOf(numericGrade);

		while (grade = 'X')
		{
			System.out.println("Enter a number grade in double format. (Ex. 74.25463)");
			numericGrade = stdIn.nextLine ();


			if (numbericGrade >=90)
			finalLetterGrade ="A";
			else
			if ((numbericGrade >=80) & (finalNumericGrade <90))
			finalLetterGrade ="B";
			else
			if ((numbericGrade >=70) & (finalNumericGrade <80))
			finalLetterGrade ="C";
			else
			if ((numbericGrade >=60) & (finalNumericGrade <70))
			finalLetterGrade ="D";
			else
			if ((numbericGrade >=0) & (finalNumericGrade <60))
			finalLetterGrade ="F";

			System.out.println("\nYour Letter Grade Is:\n" + finalLetterGrade);
			break;
		}

		while (grade == 'Y')

		{
			System.out.print("Enter Yout Letter Grade: ");
			letters = stdIn.nextLine ();

			switch(letterGrade)
			{
				case 'A':
				System.out.println("90-100 = A");
				break;
				case 'B':
				System.out.println("80-89.9 = B");
				break;
				case 'C':
				System.out.println("70-79.9 = C");
				break;
				case 'D':
				System.out.println("60-69.9 = D");
				break;
				case 'F':
				System.out.println("< 60 = F");
				break;
				default:
				System.out.println("Entered An Incorrect Grade:");
				break;
			}
		}
	}
}
 


Is This A Good Question/Topic? 0
  • +

Replies To: Grading Program

#2 krizjaz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 99
  • Joined: 07-October 07

Re: Grading Program

Posted 13 April 2009 - 12:43 AM

View Postmauribarri, on 12 Apr, 2009 - 07:26 PM, said:

I am working on a grading program

I must Utilize the Math class and round the number to zero decimal places, then use the int cast method to convert to an integer.(ensure you round it before type casting it)
Utilize a switch statement to determine the corresponding letter grade. Use the grading criteria from this course for the numbers. (ensure you accept all allowable numbers i.e. 70-79 and all in between)
Output the corresponding letter grade along with the initial number entered in decimal format utilizing the printf method and format specifiers. Output the number in only 3 decimal places.

in my switch
I must Get input for the grade letter in String format.
Utilize a switch statement to determine the corresponding output for the letter entered. (ensure you accept both upper and lower case letters.
Use the grading criteria from this course for the numbers. (you must use charAt( ) so the string will work with your switch)
Output the corresponding numbers values for the letter entered along with the letter initially entered.

Questions I have:
Is my code in the right direction?
Line 15 is giving me problems what I can I do to correct this but still be able create my rounding to the nearest whole number?
Am I missing anything?


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

		System.out.println("Welcome to Miguel's Grading Program");

		Scanner stdIn = new Scanner (System.in);
		char grade;
		char letterGrade;
		double numericGrade;

		System.out.print("Will you be using numbers or letters?");
		grade = stdIn.nextLine().charAt(0);
		public static RoundingMode valueOf(numericGrade);

		while (grade = 'X')
		{
			System.out.println("Enter a number grade in double format. (Ex. 74.25463)");
			numericGrade = stdIn.nextLine ();


			if (numbericGrade >=90)
			finalLetterGrade ="A";
			else
			if ((numbericGrade >=80) & (finalNumericGrade <90))
			finalLetterGrade ="B";
			else
			if ((numbericGrade >=70) & (finalNumericGrade <80))
			finalLetterGrade ="C";
			else
			if ((numbericGrade >=60) & (finalNumericGrade <70))
			finalLetterGrade ="D";
			else
			if ((numbericGrade >=0) & (finalNumericGrade <60))
			finalLetterGrade ="F";

			System.out.println("\nYour Letter Grade Is:\n" + finalLetterGrade);
			break;
		}

		while (grade == 'Y')

		{
			System.out.print("Enter Yout Letter Grade: ");
			letters = stdIn.nextLine ();

			switch(letterGrade)
			{
				case 'A':
				System.out.println("90-100 = A");
				break;
				case 'B':
				System.out.println("80-89.9 = B");
				break;
				case 'C':
				System.out.println("70-79.9 = C");
				break;
				case 'D':
				System.out.println("60-69.9 = D");
				break;
				case 'F':
				System.out.println("< 60 = F");
				break;
				default:
				System.out.println("Entered An Incorrect Grade:");
				break;
			}
		}
	}
}
 


What does finalNumericGrade variable do?

This post has been edited by krizjaz: 13 April 2009 - 12:56 AM

Was This Post Helpful? 0
  • +
  • -

#3 krizjaz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 99
  • Joined: 07-October 07

Re: Grading Program

Posted 13 April 2009 - 12:54 AM

import java.util.*;

public class UribarriMiguelProg4
{
	public static void main(String[] args)
	{
		double numericGrade;
		int numericFinalGrade;
		System.out.println("Welcome to Miguel's Grading Program");
		Scanner stdIn = new Scanner (System.in);
		char grade;
		char letterGrade;

		System.out.print("Will you be using numbers or letters?");
		grade = stdIn.nextLine().charAt(0);

		while (grade == 'X')
		{
			System.out.println("Enter a number grade in double format. (Ex. 74.25463)");
			numericGrade = Double.parseDouble(stdIn.next());//original double (with decimal).
			numericFinalGrade = Integer.parseInt("" + Math.round(numericGrade));// the round method is used from the math class.
			String finalLetterGrade = "";// the final letter grade is initialized.

			if (numericGrade >=90)
			finalLetterGrade ="A";
			else
			if ((numericGrade >=80) && (numericFinalGrade <90))
			finalLetterGrade ="B";
			else
			if ((numericGrade >=70) && (numericFinalGrade <80))
			finalLetterGrade ="C";
			else
			if ((numericGrade >=60) && (numericFinalGrade <70))
			finalLetterGrade ="D";
			else
			if ((numericGrade >=0) && (numericFinalGrade <60))
			finalLetterGrade ="F";

			System.out.printf("\nYour Letter Grade Is: " + finalLetterGrade + " and your grade is: %.3f", numericGrade);
			break;
		}

		while (grade == 'Y')

		{
			System.out.print("Enter Yout Letter Grade: ");
			letterGrade = stdIn.next().charAt(0);// letterGrade is initialized.

			switch(letterGrade)//letter is changed to letterGrade.
			{
				case 'A':
				System.out.println("90-100 = A");
				break;
				case 'B':
				System.out.println("80-89.9 = B");
				break;
				case 'C':
				System.out.println("70-79.9 = C");
				break;
				case 'D':
				System.out.println("60-69.9 = D");
				break;
				case 'F':
				System.out.println("< 60 = F");
				break;
				default:
				System.out.println("Entered An Incorrect Grade:");
				break;
			}
		}
	}
	//public static RoundingMode valueOf(numericGrade); i think. we won't be needing this.
}



I think this would be the code. The "letter input" side (while(grade == 'Y')), the loop does'nt end. Edit it if you wish. This is still your code.

This post has been edited by krizjaz: 13 April 2009 - 01:20 AM

Was This Post Helpful? 0
  • +
  • -

#4 mauribarri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-April 09

Re: Grading Program

Posted 14 April 2009 - 06:43 PM

View Postkrizjaz, on 12 Apr, 2009 - 11:54 PM, said:

import java.util.*;

public class UribarriMiguelProg4
{
	public static void main(String[] args)
	{
		double numericGrade;
		int numericFinalGrade;
		System.out.println("Welcome to Miguel's Grading Program");
		Scanner stdIn = new Scanner (System.in);
		char grade;
		char letterGrade;

		System.out.print("Will you be using numbers or letters?");
		grade = stdIn.nextLine().charAt(0);

		while (grade == 'X')
		{
			System.out.println("Enter a number grade in double format. (Ex. 74.25463)");
			numericGrade = Double.parseDouble(stdIn.next());//original double (with decimal).
			numericFinalGrade = Integer.parseInt("" + Math.round(numericGrade));// the round method is used from the math class.
			String finalLetterGrade = "";// the final letter grade is initialized.

			if (numericGrade >=90)
			finalLetterGrade ="A";
			else
			if ((numericGrade >=80) && (numericFinalGrade <90))
			finalLetterGrade ="B";
			else
			if ((numericGrade >=70) && (numericFinalGrade <80))
			finalLetterGrade ="C";
			else
			if ((numericGrade >=60) && (numericFinalGrade <70))
			finalLetterGrade ="D";
			else
			if ((numericGrade >=0) && (numericFinalGrade <60))
			finalLetterGrade ="F";

			System.out.printf("\nYour Letter Grade Is: " + finalLetterGrade + " and your grade is: %.3f", numericGrade);
			break;
		}

		while (grade == 'Y')

		{
			System.out.print("Enter Yout Letter Grade: ");
			letterGrade = stdIn.next().charAt(0);// letterGrade is initialized.

			switch(letterGrade)//letter is changed to letterGrade.
			{
				case 'A':
				System.out.println("90-100 = A");
				break;
				case 'B':
				System.out.println("80-89.9 = B");
				break;
				case 'C':
				System.out.println("70-79.9 = C");
				break;
				case 'D':
				System.out.println("60-69.9 = D");
				break;
				case 'F':
				System.out.println("< 60 = F");
				break;
				default:
				System.out.println("Entered An Incorrect Grade:");
				break;
			}
		}
	}
	//public static RoundingMode valueOf(numericGrade); i think. we won't be needing this.
}



I think this would be the code. The "letter input" side (while(grade == 'Y')), the loop does'nt end. Edit it if you wish. This is still your code.



krizjaz,
Thanks for the help. on the while 'y' statement doesn't the break at the end stop the loop?
Was This Post Helpful? 0
  • +
  • -

#5 krizjaz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 99
  • Joined: 07-October 07

Re: Grading Program

Posted 16 April 2009 - 12:00 AM

No, it doesn't stop the loop. The break there is for ending the Switch statement. So, You should end the while statement if the user wants to end it. Here's the code:
while (grade == 'Y')

		{
			System.out.print("Enter Yout Letter Grade: ");
			letterGrade = stdIn.next().charAt(0);// letterGrade is initialized.

			switch(letterGrade)//letter is changed to letterGrade.
			{
				case 'A':
					System.out.println("90-100 = A\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'B':
					System.out.println("80-89.9 = B\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'C':
					System.out.println("70-79.9 = C\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'D':
					System.out.println("60-69.9 = D\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'F':
					System.out.println("< 60 = F\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				default:
					System.out.println("Entered An Incorrect Grade:\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
			}
		}



I still used the character variable which is grade. So, after every case, the computer will ask the user if he/she wants to try again. So, there will be an input. The value of the grade variable is then changed so that after the switch statement, if the user inputs a 'Y', the condition in the while statement will still be true and the while loop will execute but if the user inputs any key, the condition in the while statement will now be false because it is != 'Y' and the while loop will not execute.

Please ask me if you have any questions. :)

This post has been edited by krizjaz: 16 April 2009 - 12:08 AM

Was This Post Helpful? 0
  • +
  • -

#6 mauribarri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-April 09

Re: Grading Program

Posted 16 April 2009 - 06:37 PM

View Postkrizjaz, on 15 Apr, 2009 - 11:00 PM, said:

No, it doesn't stop the loop. The break there is for ending the Switch statement. So, You should end the while statement if the user wants to end it. Here's the code:
while (grade == 'Y')

		{
			System.out.print("Enter Yout Letter Grade: ");
			letterGrade = stdIn.next().charAt(0);// letterGrade is initialized.

			switch(letterGrade)//letter is changed to letterGrade.
			{
				case 'A':
					System.out.println("90-100 = A\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'B':
					System.out.println("80-89.9 = B\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'C':
					System.out.println("70-79.9 = C\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'D':
					System.out.println("60-69.9 = D\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				case 'F':
					System.out.println("< 60 = F\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
				default:
					System.out.println("Entered An Incorrect Grade:\nWant to try again? Y to start again or any key to end:");
					grade = stdIn.next().charAt(0);
					break;
			}
		}



I still used the character variable which is grade. So, after every case, the computer will ask the user if he/she wants to try again. So, there will be an input. The value of the grade variable is then changed so that after the switch statement, if the user inputs a 'Y', the condition in the while statement will still be true and the while loop will execute but if the user inputs any key, the condition in the while statement will now be false because it is != 'Y' and the while loop will not execute.

Please ask me if you have any questions. :)


Krizjaz,
Thanks for the info. This makes more sense now. so this is where logical operators are used and are crucial right(&& != ||)?
Was This Post Helpful? 0
  • +
  • -

#7 mauribarri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-April 09

Re: Grading Program

Posted 16 April 2009 - 07:12 PM

Krizjaz,
Hey as I made these changes when i compiled the java file I have 1 error. I tried looking to see what was wrong. I couldn't find it. maybe I'm just blind. Thanks for the help
[
double numericGrade;
int numericFinalGrade;
System.out.println("Welcome to Miguel's Grading Program");
Scanner stdIn = new Scanner (System.in);
char grade;
char letterGrade;


System.out.print("Will you be using numbers or letters?");
grade = stdIn.nextLine().charAt(0);

while (numericGrade == 'X')
{
System.out.println("Enter a number grade in double format. (Ex. 74.25463): ");
numericGrade = Double.parseDouble(stdIn.next());//original double (with decimal).
numericFinalGrade = Integer.parseInt("" + Math.round(numericGrade));//the round method is used from the math class
String finalLetterGrade = "";//the final letter grade is intialized


if (numericGrade >=90)
finalLetterGrade ="A";
else
if ((numericGrade >=80) && (numericFinalGrade <90))
finalLetterGrade ="B";
else
if ((numericGrade >=70) && (numericFinalGrade <80))
finalLetterGrade ="C";
else
if ((numericGrade >=60) && (numericFinalGrade <70))
finalLetterGrade ="D";
else
if ((numericGrade >=0) && (numericFinalGrade <60))
finalLetterGrade ="F";

System.out.println("\nYour Letter Grade Is: " + finalLetterGrade + " and your grade is: %.3f", numericGrade);
break;
}
]

this is the error log
[/
^
C:\Documents and Settings\Home\Desktop\programming\UribarriMiguelProg4.java:51: cannot find symbol
symbol : method println(java.lang.String,double)
location: class java.io.PrintStream
System.out.println("\nYour Letter Grade Is: " + finalLetterGrade + " and your grade is: %.3f", numericGrade);
^
errors

Tool completed with exit code 1
]

This post has been edited by mauribarri: 16 April 2009 - 08:43 PM

Was This Post Helpful? 0
  • +
  • -

#8 mauribarri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-April 09

Re: Grading Program

Posted 16 April 2009 - 08:38 PM

Krisjaz,
disregard the last post. it was a typo on my part for the if else if content. Now error 6 is still showing up. if I changed it to printf i then get an error stating that i have not initialized the variable numericGrade in the while statement while (numericGrade == 'X')...kinda lost here because i thought the variable had been initialized.
Was This Post Helpful? 0
  • +
  • -

#9 mauribarri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-April 09

Re: Grading Program

Posted 18 April 2009 - 12:12 PM

I was able to fix my errors and can now compile the java file and run it. It asks me to enter letters or numbers and you can type either of the two, but once you do and hit enter it does not go to either of my while statements. It just goes to press any key to continue and exits. Some guidance is greatly appreciated. Here's the code:


/**********************************************************************
* UribarriMiguelProg4.java
* Miguel Uribarri
*
* This program will convert number grades to letter or
* convert letter grades to numbers
**********************************************************************/

import java.util.Scanner;

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


		double numericGrade;
		int numericFinalGrade;
		Scanner stdIn = new Scanner (System.in);
		char numericGradegrade;
		char letterGrade;

		System.out.println("Welcome to Miguel's Grading Program");
		System.out.print("Will you be using numbers or letters?");
		numericGrade = stdIn.nextLine().charAt(0);

		while (numericGrade == 'X')
		{
			System.out.println("Enter a number grade in double format. (Ex. 74.25463): ");
			numericGrade = Double.parseDouble(stdIn.next());//original double (with decimal).
			numericFinalGrade = Integer.parseInt("" + Math.round(numericGrade));//the round method is used from the math class
			String finalLetterGrade = "";//the final letter grade is intialized


			if (numericGrade >=90)
			finalLetterGrade ="A";
			else
			if ((numericGrade >=80) && (numericFinalGrade <90))
			finalLetterGrade ="B";
			else
			if ((numericGrade >=70) && (numericFinalGrade <80))
			finalLetterGrade ="C";
			else
			if ((numericGrade >=60) && (numericFinalGrade <70))
			finalLetterGrade ="D";
			else
			if ((numericGrade >=0) && (numericFinalGrade <60))
			finalLetterGrade ="F";

			System.out.printf("\nYour Letter Grade Is: " + finalLetterGrade + " and your grade is: %.3f", numericGrade);
			break;
		}

		while (numericGrade == 'Y')

		{
			System.out.print("Enter Your Letter Grade: ");
			letterGrade = stdIn.next().charAt(0);//letterGrade is initialized

			switch(letterGrade)//letter is changed to letterGrade
			{
				case 'A':
				System.out.println("90-100 = A\nWant to try again? Y to start again or any key to end:");
				numericGrade = stdIn.next().charAt(0);
				break;
				case 'B':
				System.out.println("80-89.9 = B\nWant to try again? Y to start again or any key to end:");
				numericGrade = stdIn.next().charAt(0);
				break;
				case 'C':
				System.out.println("70-79.9 = C\nWant to try again? Y to start again or any key to end:");
				numericGrade = stdIn.next().charAt(0);
				break;
				case 'D':
				System.out.println("60-69.9 = D\nWant to try again? Y to start again or any key to end:");
				numericGrade = stdIn.next().charAt(0);
				break;
				case 'F':
				System.out.println("< 60 = F\nWant to try again? Y to start again or any key to end:");
				numericGrade = stdIn.next().charAt(0);
				break;
				default:
				System.out.println("Entered An Incorrect Grade:\nWant to try again? Y to start again or any key to end:");
				numericGrade = stdIn.next().charAt(0);

				break;
			}
		}
	}
}

This post has been edited by mauribarri: 18 April 2009 - 12:14 PM

Was This Post Helpful? 0
  • +
  • -

#10 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Grading Program

Posted 18 April 2009 - 11:00 PM

== for char is case sensitive. If you enter 'x' it will equal it to 'X' and it wil return false. So it will skip it.
change it to
while (numericGrade == 'Y' || numericGrade == 'y')

And breaking to exist a loop is structurally incorrect. yes, it does work, but depending on how your teacher is they may cont off for it. I would simply make it so that the loop wont meet the conditions. I would recommend adding a boolean to our while loops condition.

So at the top make a boolean variable for each of the while loops. then set it to be while it is true. and at the end of the code, set it to false so it doesnt make an ifinite loops.

boolean go1 = true;
boolean go2 = true;
while ((numericGrade == 'Y' || numericGrade == 'y')&& go2) // Use an and so that BOTH qualifications have to be met
{//all your code
 go2= false; // will exist the loop once all of the code is finished
}
while ((numericGrade == 'X' || numericGrade == 'x') && go1) //saying go1 means the same as go1== true
{//all your code
go1 = false;
}


I fixed the while statement problem in that code as well. That is an effecient and Structurally correct way of doing it.
Was This Post Helpful? 0
  • +
  • -

#11 krizjaz  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 99
  • Joined: 07-October 07

Re: Grading Program

Posted 19 April 2009 - 10:18 AM

View PostFuzzyness, on 18 Apr, 2009 - 10:00 PM, said:

== for char is case sensitive. If you enter 'x' it will equal it to 'X' and it wil return false. So it will skip it.
change it to
while (numericGrade == 'Y' || numericGrade == 'y')

And breaking to exist a loop is structurally incorrect. yes, it does work, but depending on how your teacher is they may cont off for it. I would simply make it so that the loop wont meet the conditions. I would recommend adding a boolean to our while loops condition.

So at the top make a boolean variable for each of the while loops. then set it to be while it is true. and at the end of the code, set it to false so it doesnt make an ifinite loops.

boolean go1 = true;
boolean go2 = true;
while ((numericGrade == 'Y' || numericGrade == 'y')&& go2) // Use an and so that BOTH qualifications have to be met
{//all your code
 go2= false; // will exist the loop once all of the code is finished
}
while ((numericGrade == 'X' || numericGrade == 'x') && go1) //saying go1 means the same as go1== true
{//all your code
go1 = false;
}


I fixed the while statement problem in that code as well. That is an effecient and Structurally correct way of doing it.


Yes, it is better to use boolean in while loops than the strings.

And also. mauribarri, why would you enter a number? You have a condition in your while loops which are (numericGrade == 'Y') and (numericGrade == 'X'). So, just input 'X' or 'Y'. I noticed also that the data type of numericGrade is Double! You used numericGrade as inputs for a character. It is wrong. And the numericGradegrade has no use. So, let's make use of that variable you declared there. Instead of using the numericGrade as a character, you should use numericGradegrade so that the variable would be useful. Ok? Looks like the code gets larger. . Hehe! I used the try and catch because there's an exception if you will enter nothing in the inputs. I just put it only in the first input inside the while loop. Still, there will be and exception if you enter nothing immediately at the beginning when running the program. Also, i've noticed something wrong in the code. When the computer asks you to enter a number in double format like 79.764, the letter grade won't display. So, i just used only one variable for all the conditions inside the if-else statements which is the numericFinalGrade because it's value is rounded off to a whole number and to it's nearest.
Take a look at some revisions of the code:
/**********************************************************************
* UribarriMiguelProg4.java
* Miguel Uribarri
*
* This program will convert number grades to letter or
* convert letter grades to numbers
**********************************************************************/

import java.util.Scanner;

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


		double numericGrade;
		int numericFinalGrade;
		Scanner stdIn = new Scanner (System.in);
		char numericGradegrade;
		char letterGrade;

		System.out.println("Welcome to Miguel's Grading Program");
		System.out.print("Will you be using numbers or letters?");
		numericGradegrade = stdIn.nextLine().charAt(0);
		boolean go1 = false;
		boolean go2 = false;

		if(numericGradegrade == 'X' || numericGradegrade == 'x'){
			go1 = true;
		}else if(numericGradegrade == 'Y' || numericGradegrade == 'y'){
			go2 = true;
		}else{
			System.out.println("Please enter only 'X' and 'Y'");
			boolean go3 = true;
			while(go3 == true){
				try{
					numericGradegrade = stdIn.nextLine().charAt(0);
					if(numericGradegrade == 'Y' || numericGradegrade == 'y'){
						go3 = false;
						go1 = true;
					}else if(numericGradegrade == 'X' || numericGradegrade == 'x'){
						go3 = false;
						go1 = true;
					}else{
						System.out.println("Please enter only 'X' and 'Y'");
						go3 = true;
					}
				}catch(Exception ex){
					System.out.println("Please enter only 'X' and 'Y'");
					go3 = true;
				}
			}
		}

		while (go1 == true)
		{
			System.out.println("Enter a number grade in double format. (Ex. 74.25463): ");
			numericGrade = Double.parseDouble(stdIn.next());//original double (with decimal).
			numericFinalGrade = Integer.parseInt("" + Math.round(numericGrade));//the round method is used from the math class
			String finalLetterGrade = "";//the final letter grade is intialized


			if (numericGrade >=90)
			finalLetterGrade ="A";
			else
			if ((numericFinalGrade >=80) && (numericFinalGrade <90))
			finalLetterGrade ="B";
			else
			if ((numericFinalGrade >=70) && (numericFinalGrade <80))
			finalLetterGrade ="C";
			else
			if ((numericFinalGrade >=60) && (numericFinalGrade <70))
			finalLetterGrade ="D";
			else
			if ((numericFinalGrade >=0) && (numericFinalGrade <60))
			finalLetterGrade ="F";

			System.out.printf("\nYour Letter Grade Is: " + finalLetterGrade + " and your grade is: %.3f\n", numericGrade);
			System.out.println("Want to try again? Y to start again or any key to end:");
			numericGradegrade = stdIn.next().charAt(0);
			if(numericGradegrade == 'Y' || numericGradegrade == 'y'){
				go1 = true;
			}else{
				go1 = false;
			}
		}

		while (go2 == true)

		{
			System.out.print("Enter Your Letter Grade: ");
			letterGrade = stdIn.next().charAt(0);//letterGrade is initialized

			switch(letterGrade)//letter is changed to letterGrade
			{
				case 'A':
				System.out.println("90-100 = A");
				break;
				case 'B':
				System.out.println("80-89.9 = B");
				break;
				case 'C':
				System.out.println("70-79.9 = C");
				break;
				case 'D':
				System.out.println("60-69.9 = D");
				break;
				case 'F':
				System.out.println("< 60 = F");
				break;
				default:
				System.out.println("Entered An Incorrect Grade.");
				break;
			}
			System.out.println("Want to try again? Y to start again or any key to end:");
			numericGradegrade = stdIn.next().charAt(0);
			if(numericGradegrade == 'Y' || numericGradegrade == 'y'){
				go2 = true;
			}else{
				go2 = false;
			}
		}
	}
}


Edit it if you want the user not to input nothing so that there would be no exceptions. . =)
If you still have any questions, please ask. .

Sorry, i've been out for a day. The computer i'm using was brought back to its user. But now, me and my father bought a CPU (only a cpu because i have a monitor). Just only a cheap one (sad to say, we're poor. . T_T). But happy coz it's good. Phew! I'm now online again! WeEeEeEe!! :D

This post has been edited by krizjaz: 19 April 2009 - 10:36 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1