Grading Program

Grading Program

Page 1 of 1

5 Replies - 2985 Views - Last Post: 19 September 2008 - 03:19 AM Rate Topic: -----

#1 LMullin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-September 08

Grading Program

Post icon  Posted 16 September 2008 - 08:55 PM

Hello. I could really use some help if anyone has the time.

I am having a few problems. I cannot seem to figure out how to use the math class properly and keep getting errors. I need to round the number given, then change it to an int, then output the number in only 3 decimal places. I do not know how to input to be in the output. And is there a code to use that will allow upper and lower case letters without typing each letter grade upper and lower case? I'm sure there is one and remember reading it, but cannot find it in my 'useful' book.

Thank you for any help you may provide!

Lisa

import static java.lang.Math.*;

import java.util.*;

public class MullinLisaProg4_5
{
	public static void main (String[] args)
	{
	//
	System.out.println("Welcome to Lisa’s Grading Program");

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

	System.out.print("Will you be entering in numbers or letters? (type n for numbers and l for letters");
	grade = stdIn.nextLine().charAT(0);


while (grade == 'n')
		{
		System.out.println("Enter a number with five numbers after decimal: for example 75.22645");
		numbericGrade += stdln.nextLine ();
		double floor(double numericGrade);
		finalNumericGrade = (int) numericGrade;

			if (numericGrade >=90)
			finalLetterGrade ="Great Job you earned an A!";
			else if ((numericGrade >=80) & (finalNumericGrade <90))
			finalLetterGrade ="You earned a B, not too shabby.";
			else if ((numericGrade >=70) & (finalNumericGrade <80))
			finalLetterGrade ="You have earned a C";
			else if ((numericGrade >=60) & (finalNumericGrade <70))
			finalLetterGrade ="D";
			else if ((numericGrade >=0) & (finalNumericGrade <60))
			finalLetterGrade ="F";}

			while (grade == 'l')
					{
					System.out.println("Please enter a letter grade.");
					letterGrade += stdln.nextLine ();}

					switch(letterGrade)
						{
						case A:
								System.out.println("90-100 = A");
								break;
						case B:
								System.out.println("80-89 = B");
								break;
						case C:
								System.out.println("70-79 = C");
								break;
						case D:
								System.out.println("60-69 = D");
								break;
						case F:
					System.out.println("0-59 = F");}

		System.out.println("Your letter grade is as follows:\n" + finalLetterGrade);
	  }
  }


Is This A Good Question/Topic? 0
  • +

Replies To: Grading Program

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Grading Program

Posted 16 September 2008 - 09:18 PM

Lisa,

Nothing to do with problem with the Math class
Your program just don't compile:

	grade = stdIn.nextLine().charAT(0);


you mean
	grade = stdIn.nextLine().charAt(0);



		numbericGrade += stdln.nextLine ();
		double floor(double numericGrade);
		finalNumericGrade = (int) numericGrade;


you cannot add a String coming from nextLine() to a double

					letterGrade += stdln.nextLine ();}


it is not stdln but stdIn

You cannot add to a char a String read by strIn.nextLine()


case statement on a switch on char must be enclosed between ' '

				   switch(letterGrade)
						{
						case 'A':
								System.out.println("90-100 = A");
								break;
						case 'B':
								System.out.println("80-89 = B");
								break;
						case 'C':
								System.out.println("70-79 = C");
								break;
						case 'D':
								System.out.println("60-69 = D");
								break;
						case 'F':
					System.out.println("0-59 = F");}



Hope this helps
Was This Post Helpful? 0
  • +
  • -

#3 LMullin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-September 08

Re: Grading Program

Posted 16 September 2008 - 10:04 PM

View Postpbl, on 16 Sep, 2008 - 09:18 PM, said:

Lisa,

Nothing to do with problem with the Math class
Your program just don't compile:

	grade = stdIn.nextLine().charAT(0);


you mean
	grade = stdIn.nextLine().charAt(0);



		numbericGrade += stdln.nextLine ();
		double floor(double numericGrade);
		finalNumericGrade = (int) numericGrade;


you cannot add a String coming from nextLine() to a double

					letterGrade += stdln.nextLine ();}


it is not stdln but stdIn

You cannot add to a char a String read by strIn.nextLine()


case statement on a switch on char must be enclosed between ' '

				   switch(letterGrade)
						{
						case 'A':
								System.out.println("90-100 = A");
								break;
						case 'B':
								System.out.println("80-89 = B");
								break;
						case 'C':
								System.out.println("70-79 = C");
								break;
						case 'D':
								System.out.println("60-69 = D");
								break;
						case 'F':
					System.out.println("0-59 = F");}



Hope this helps


Thank you for writing back so quickly. I am still extremely confused. I don't understand why this will not run. I have changed what you said to change and re-arranged some things. I have gone from having 2 errors to having 6 errors AHHH! Can you help me?

import static java.lang.Math.*;

import java.util.*;

public class MullinLisaProg4_5
{
	public static void main (String[] args)
	{
	//
	System.out.println("Welcome to Lisa’s Grading Program");

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

	System.out.print("Will you be entering in numbers or letters? (type n for numbers and l for letters");
	grade = stdIn.nextLine().charAt(0);
	public static double floor (double numericGrade);


while (grade == 'n')
		{
		System.out.println("Enter a number with five numbers after decimal: for example 75.22645");
		numericGrade += stdIn.nextLine ();
		finalNumericGrade = (int) numericGrade;}

			{if (numericGrade >=90)
			finalLetterGrade ="Great Job you earned an A!";
			else if ((numericGrade >=80) & (finalNumericGrade <90))
			finalLetterGrade ="You earned a B, not too shabby.";
			else if ((numericGrade >=70) & (finalNumericGrade <80))
			finalLetterGrade ="You have earned a C";
			else if ((numericGrade >=60) & (finalNumericGrade <70))
			finalLetterGrade ="D";
			else if ((numericGrade >=0) & (finalNumericGrade <60))
			finalLetterGrade ="F";}

			while (grade == 'l')
					{
					System.out.println("Please enter a letter grade.");
					letterGrade += stdIn.nextLine ();}

					switch(letterGrade)
						{
						case 'A':
								System.out.println("90-100 = A");
								break;
						case 'B':
								System.out.println("80-89 = B");
								break;
						case 'C':
								System.out.println("70-79 = C");
								break;
						case 'D':
								System.out.println("60-69 = D");
								break;
						case 'F':
					System.out.println("0-59 = F");}

		System.out.println("Your letter grade is as follows:\n" + finalLetterGrade);
	  }
  }
}



This post has been edited by LMullin: 16 September 2008 - 10:33 PM

Was This Post Helpful? 0
  • +
  • -

#4 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: Grading Program

Posted 17 September 2008 - 09:01 AM

I also went through and tried fixing it and basically gave up, there is a tonne of issues with the program... Perhaps think a new approach to this question ? Start from scratch and plan how you are going to write it and what are the most effective ways of utilising the tools available... I found undeclared variables, typo's of variable names and the lot... I might quickly do up an example for you, however there was to much to fix lol. It would seriously be easier starting fresh and take the comments above in good stead, learn and improve :)

Anyway i muddled through your class and fixed it up, it compiles and seems to work now, you might have to check some of your logic in the if and else if statements, however it compiles now... I won't explain in detail all the changes i made, instead have a read on your own and compare it to the previous that you posted here... I commented a few things here and there so have fun

import static java.lang.Math.*;
import java.util.*;

public class MullinLisaProg4_5
{
    public static void main (String[] args)
    {
    //
    System.out.println("Welcome to Lisa’s Grading Program");

    Scanner stdIn = new Scanner (System.in);
    int grade;
    char letterGrade = ' ';	// NOTE :: has to be initialised
    double numericGrade;
	
	//some variables u need to declare 
	String finalLetterGrade = "";

    System.out.print("Will you be entering in numbers or letters?\n(Type 1 for numbers and 2 for letters)");
    grade = stdIn.nextInt();
	
    //public static double floor (double numericGrade); -- errr no idea 

		while (grade == 1)
		{
	        System.out.println("Enter a number with five numbers after decimal: for example 75.22645");
	        numericGrade = stdIn.nextDouble();
	        int finalNumericGrade = (int)numericGrade;

	            if (numericGrade >=90)
	            finalLetterGrade ="Great Job you earned an A!";
	            else if ((numericGrade >=80) & (finalNumericGrade <90))
	            finalLetterGrade ="You earned a B, not too shabby.";
	            else if ((numericGrade >=70) & (finalNumericGrade <80))
	            finalLetterGrade ="You have earned a C";
	            else if ((numericGrade >=60) & (finalNumericGrade <70))
	            finalLetterGrade ="D";
	            else if ((numericGrade >=0) & (finalNumericGrade <60))
	            finalLetterGrade ="F";
				
				System.out.println("Your letter grade is as follows:\n" + finalLetterGrade);
				
				break; 	//need this to break out of loop, otherwise you will be stuck in here forever
		} // break out of while loop

		while (grade == 2)
		{
			System.out.println("Please enter a letter grade.");
			String letterGradeStr = stdIn.next();	
			
			//now we have to get our character from the string entered 
			System.out.println(letterGradeStr.charAt(0));
			letterGrade = letterGradeStr.charAt(0);
			
			switch(letterGrade)
			{
				case 'A':
						System.out.println("90-100 = A");
						break;
				case 'B':
						System.out.println("80-89 = B");
						break;
				case 'C':
						System.out.println("70-79 = C");
						break;
				case 'D':
						System.out.println("60-69 = D");
						break;
				case 'F':
						System.out.println("0-59 = F");
						break;
				default : System.out.println("INVALID INPUT");
			}

					
			
			break;
		} 	// break out of next wile loop	
	
	}	//end of main
}	//end of class




:pirate:

This post has been edited by bbq: 17 September 2008 - 09:32 AM

Was This Post Helpful? 0
  • +
  • -

#5 LMullin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-September 08

Re: Grading Program

Posted 18 September 2008 - 08:54 PM

You're awesome. Thank you. I tried to re-write this program so many times and it never worked. This will be the last computer class I try to take online = way too hard!!

Thank you again,

Lisa
Was This Post Helpful? 0
  • +
  • -

#6 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: Grading Program

Posted 19 September 2008 - 03:19 AM

No worries, once you get the basics sorted you can go on and research and teach yourself many things, the only way to learn is to code... Thats why i don't mind posting code to help where i can, it helps me keep fresh and remember the underpinning foundations :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1