Attachment 3551Attachment 3552Attachment 3553
Printable View
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
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);
}
won't work at all and still working on it
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.
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
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.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 ofCode:case choice "17 - 19";
for example. mgiht be worth a try.Code:case choice '17 - 19':
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.
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:Code:computedGrade = grade/100.0
if (computedGrade == 40.0)
{
System.out.println("++A");
}
else if (computedGrade >= 37 && computedGrade <= 39)
{
System.out.println("A-");
}
...
from
toCode:num = scan.nextDouble();
while (num < 0)
{
System.out.print("ERROR: Enter a positive number);
}
Do the same type of thing for the other while loopCode: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
Sorry I made a mistake on do while loop.
use instead:
Code:num = scan.nextDouble();
while (num < 0)
{
System.out.print("ERROR: Enter a positive number);
num = scan.nextDouble();
}
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
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);
}
}
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
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.Code:char choice = 0;
int letter = 0;
int symbol;
double num;
int grade = 0;
I just did the same thing the program run but do not give you the desire output.
Thank you very much though
Does your program have to follow the teacher's template?
change your while loop and add a for loop as follows:
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;
}
}
teachers template is a working template; it's her way of doing it but you can use the same if you want