Results 1 to 17 of 17
- 04-13-2012, 11:14 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
- 04-13-2012, 11:17 PM #2
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
looks like homework to me ;-p
you probably wont fine anyone here willing to do this for you.
if you start working on this and post what code you have already, i'm sure lots of people would be willing to help you learn.
just my 2 cents... ;-P
- 04-13-2012, 11:19 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
import java.util.Scanner;
public class P1
{
public static void main( String args[] )
{
final int HI = 40;
final int A = 37;
final int B = 27;
final int C = 17;
final int D = 10;
final int F = 00;
char choice;
int letter;
int symbol;
double num;
int grade;
Scanner scan = new Scanner(System.in);
String inputStr = null;
System.out.print( "Enter GPA (3.3): ");
num = scan.nextDouble();
while (num < 0)
{
System.out.print("ERROR: Enter a positive number);
}
while (num > 0)
{
System.out.printf
("Using if else, letter grade of GPA: %.1f is ", grade/10.0);
int letter = console.nextInt();
if (letter >= A) System.out.print("A");
else if (letter >= B) System.out.print("B");
else if (letter >= C) System.out.print("C");
else if (letter >= D) System.out.print("D");
else if (letter >= F) System.out.print("F");
switch(grade/10.0)
{
case choice '40':
System.out.println("++A");
break;
case choice '37 - 39':
System.out.println("A-");
break;
case choice '33 - 36':
System.out.println("B+");
break;
case choice '30 - 32':
System.out.println("B");
break;
case choice '27 - 29':
System.out.println("B-");
break;
case choice '23 - 28':
System.out.println("C-");
break;
case choice '20 - 22':
System.out.println("C");
break;
case choice '17 - 19':
System.out.println("C-");
break;
case choice '10 - 16':
System.out.println("D");
break;
case choice '00 - 09':
System.out.println("F");
break;
}
System.out.print("Want to calculate grades (y/n)? " );
inputStr = scan.next();
}
while(choice ! = 'n' && choice != 'N');
scan.close();
System.exit(0);
}
- 04-13-2012, 11:20 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
won't work at all and still working on it
- 04-13-2012, 11:21 PM #5
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
and the problem your having? you must give some back story with whats going on and what you wish to accomplish... i'll just repeat... someone will not do this project for you to turn in. (trust me, i've asked before!!!!! lol)
are you getting errors in compilation? will it not run? a logic problem? stuck someplace? whats going on?
Thanks!
EDIT: sorry, didn't see ur above post: ignore this one.
- 04-13-2012, 11:24 PM #6
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
i am completely new do java and the error i have is basically the whole programming and i cannot even compile i started working on little chunks but still there will be errors
- 04-14-2012, 12:30 AM #7
Senior Member
- Join Date
- Apr 2012
- Posts
- 127
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
well... i'm pretty new too... so welcome to the club! :)
For starters... when i attempt to compile ur program, i get a lot of errors related to ur
most of the errors state that java is expecting a ";" instead of a ":" at the end of ur "case choice" lines. dont knwo if that is what you intended or not... but may be a start.Java Code:case choice '40': System.out.println("++A"); break; case choice '37 - 39': System.out.println("A-"); break; case choice '33 - 36': System.out.println("B+"); break; case choice '30 - 32': System.out.println("B"); break; case choice '27 - 29': System.out.println("B-"); break; case choice '23 - 28': System.out.println("C-"); break; case choice '20 - 22': System.out.println("C"); break; case choice '17 - 19': System.out.println("C-"); break; case choice '10 - 16': System.out.println("D"); break; case choice '00 - 09': System.out.println("F"); break;
also, I do belive that java interprets a single ' differently than a double " ... so make sure u are using this correctly. I'm getting a lot of errors stating "error: unclosed character literal" which seems to me that java is attempting to read ur case choice line numnbers literly... isntead of into a string. (someone please correct me if i'm wrong).
So maybe do this:
insted ofJava Code:case choice "17 - 19";
for example. mgiht be worth a try.Java Code:case choice '17 - 19':
- 04-14-2012, 01:44 AM #8
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
I tried doing it but it still gives the same error. I don't i have the template on the question so i am trying to follow the same all it want's is "if else" statement and then followed by "switch" statement to assign + and - sign to the grades. I completely created my own codes that doesn't even make sense and it's complete train wreck.
I am still trying to solve the few chunks of it like first inserting the while loop and then moving on to if else statement.
I am pretty sure the problem is in if else and switch commands.
I really need someone who can guide my to connect the program correctly.
My codes are completely wrong and I am working on complete new one again.
- 04-14-2012, 03:07 AM #9
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
I'm new to java also.
Your switch case construct is incorrect. See The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics).
You should be using an if/if else/else construct instead of the switch/case construct:
Also, change the while loop as follows:Java Code:computedGrade = grade/100.0 if (computedGrade == 40.0) { System.out.println("++A"); } else if (computedGrade >= 37 && computedGrade <= 39) { System.out.println("A-"); } ...
from
toJava Code:num = scan.nextDouble(); while (num < 0) { System.out.print("ERROR: Enter a positive number); }
Do the same type of thing for the other while loopJava Code:do { num = scan.nextDouble(); System.out.print("ERROR: Enter a positive number); } while (num < 0);
Also, should the variable letter be grade?
You'll want to divide grade by 100.0 and not 10.0
- 04-14-2012, 03:09 AM #10
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
Sorry I made a mistake on do while loop.
use instead:
Java Code:num = scan.nextDouble(); while (num < 0) { System.out.print("ERROR: Enter a positive number); num = scan.nextDouble(); }
- 04-14-2012, 03:45 AM #11
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
The reason i am dividing by 10 is because we trying to grade gpa for 0.0 to 4.0 and then assign '+' and '-' sign through "switch" statement
Thank you shall, the grading assignment can be done by just if else but you also have to use switch statement which makes it harder.
grading assignment can be done that way but you have to use switch statement in order to assign + and - sign to your grade
she has one of the template given the template is pretty good only thing it is missing is if else and switch and i'm trying to figure out i tried couple of cases but i couldn't link it and you run into infinite loop all the time.
Thank you again for your help
- 04-14-2012, 06:17 AM #12
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
public class P1Test
{
public static void main( String args[] )
{
final int HI = 40;
final int A = 37;
final int B = 27;
final int C = 17;
final int D = 10;
final int F = 00;
char choice;
int letter;
int symbol;
double num;
int grade;
Scanner scan = new Scanner(System.in);
String inputStr = null;
System.out.print( "Enter GPA (3.3): ");
num = scan.nextDouble();
while (num < 0)
{
System.out.print("ERROR: Enter a positive number");
num = scan.nextDouble();
}
while (num > 0)
{
System.out.printf
("Using if else, letter grade of GPA: %.1f is ", grade/10.0);
grade = (int)(num*10);
if (letter >= HI) System.out.print("++A");
else if (letter >= A) System.out.print("A");
else if (letter >= B) System.out.print("B");
else if (letter >= C) System.out.print("C");
else if (letter >= D) System.out.print("D");
else if (letter >= F) System.out.print("F");
String letterString;
switch(letter)
{
case '1':
System.out.println("++A");
break;
case '7':
case '8':
case '9':
System.out.println("-");
break;
case '3':
case '4':
case '5':
case '6':
System.out.println("+");
break;
}
System.out.print("Want to calculate grades (y/n)? " );
inputStr = scan.next();
}
while(choice != 'n' && choice != 'N');
scan.close();
System.exit(0);
}
}
- 04-14-2012, 06:18 AM #13
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
the better version but i still have this 3 error
P1Test.java:39: variable grade might not have been initialized
("Using if else, letter grade of GPA: %.1f is ", grade/10.0);
^
P1Test.java:41: variable letter might not have been initialized
if (letter >= HI) System.out.print("++A");
^
P1Test.java:69: variable choice might not have been initialized
while(choice != 'n' && choice != 'N');
^
3 errors
- 04-14-2012, 07:05 AM #14
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
Just Initialize the variables:
You might want to install and start using NetBeans (http://netbeans.org/downloads/). On that webpage, just select download from the all column. it can automatically correct some of these errors for you.Java Code:char choice = 0; int letter = 0; int symbol; double num; int grade = 0;
- 04-14-2012, 07:33 AM #15
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
I just did the same thing the program run but do not give you the desire output.
Thank you very much thoughLast edited by 4uAngelique; 04-14-2012 at 07:36 AM.
- 04-14-2012, 07:54 AM #16
Senior Member
- Join Date
- Apr 2012
- Posts
- 199
- Rep Power
- 0
Re: to print a letter grade for a numerical GPA
Does your program have to follow the teacher's template?
change your while loop and add a for loop as follows:
Java Code:while (num < 0) { System.out.println("ERROR: Enter a positive number!"); System.out.println(""); System.out.println("Enter GPA (3.3): "); num = scan.nextDouble(); } for (;;) { num /= 10; if (num <= 4.0) { break; } }
- 04-14-2012, 08:01 AM #17
Member
- Join Date
- Apr 2012
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Allow only numerical input on JTextField
By patriotsfan in forum AWT / SwingReplies: 3Last Post: 05-31-2011, 12:39 PM -
Defining numerical set in java
By veronique in forum New To JavaReplies: 8Last Post: 05-04-2011, 08:08 AM -
How to define custom numerical similarity scores in Lucene ?
By aneuryzma in forum LuceneReplies: 0Last Post: 03-05-2011, 08:06 AM -
Creating Jtable and reading a txt file of numerical data
By techwiz in forum NetBeansReplies: 1Last Post: 02-22-2011, 01:40 PM -
Reading Numerical Data
By tyang in forum New To JavaReplies: 1Last Post: 02-05-2010, 03:19 AM


1Likes
LinkBack URL
About LinkBacks


Reply With Quote
Bookmarks