Question:
program still does not compile.. please help me out.. i got school in couple hours.. need to finish this?
Luck
2011-02-20 23:35:00 UTC
Write a program that translates a letter grade into a number grade. Letter grade are A,B,C,D,F possibly followed by a +or-. A+ increases the numeric value by 0.3,a - decreases it by 0.3.However an A+ has the value of 4.0.
enter a letter grade : B-
the numeric value is 2.7






import java.util.Scanner;
import java.io.*;
public class GradePrinter
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a letter grade:");
String input = in.nextLine();
double value = Grade(input);
System.out.println("Numeric value: " + value);

}
}
public static void Grade(String in)
{
double grade;
if (input == "A+")
{
grade = 4.0;
}
else if (input == "A-")
{
grade = 3.7;
}
else if (input == "B+")
{
grade = 3.0;
}
else if (input == "B-")
{
grade = 2.7;
}
else if (input ==" C+")
{
grade = 2.0;
}
else if (input == "C-")
{
grade = 1.7;
}
else if (input == "D+")
{
grade = 2.0;
}
else if (input == "D-")
{
grade = 0.7;
}
else if(input == "F")
{
grade = 0.0;
}
return grade;
}


someone just answered this here:-
http://answers.yahoo.com/question/index;_ylt=AkfYZ3c3xicF56VS86YfN5Hty6IX;_ylv=3?qid=20110220225402AAxudfQ

but its not compiling

please help
thanks
Three answers:
Ben
2011-02-20 23:40:29 UTC
The output of the compilation would have been nice.





GradePrinter.java:15: class, interface, or enum expected

public static void Grade(String in)

^

GradePrinter.java:18: class, interface, or enum expected

if (input == "A+")

^

GradePrinter.java:21: class, interface, or enum expected

}

^

GradePrinter.java:25: class, interface, or enum expected

}

^

GradePrinter.java:29: class, interface, or enum expected

}

^

GradePrinter.java:33: class, interface, or enum expected

}

^

GradePrinter.java:37: class, interface, or enum expected

}

^

GradePrinter.java:41: class, interface, or enum expected

}

^

GradePrinter.java:45: class, interface, or enum expected

}

^

GradePrinter.java:49: class, interface, or enum expected

}

^

GradePrinter.java:53: class, interface, or enum expected

}

^

GradePrinter.java:55: class, interface, or enum expected

}

^

12 errors







So, here's what this tells us: everything is fine up until line 15. After that, we get a whole bunch of errors. Now, the probability that you made 12 separate errors in a 55 line file is pretty low. That means that you probably only have one error, around line 15, that completely messes up Java's parsing.



Quickly opening this up in an editor that does brace matching (I use Vim but that has a really high learning curve) shows that you have 1 too many close braces at line 14. You're accidentally closing the class, not just the method.
?
2011-02-20 23:52:11 UTC
You really need to do a better job of helping us help you. As the other answer said, if it doesn't compile, post the error messages. The first problem with compiling appears to be the position of the second closing brace, as the answer stated.



Also, the answer that the other question linked to told you to fix the return type of your Grade function as well as the string comparison for each "if" and "else if" line. Why re-post the original program rather than making those changes first and posting the revised program? Without fixing the return type, the program still won't compile, and without fixing the string comparisons, it will compile but not run properly.
?
2016-12-01 12:47:57 UTC
nicely i could propose you will pass college and get some sleep. If that's no longer a probability, then espresso is your ultimate pal. start up chugging that first pot of black espresso and Monster, RockStar, and so on... power drinks. college is basically seven hours long, you may make it. Drink lots of caffeine now and at lunch and convey some thing with you to drink at your locker in between instructions. additionally sugar. consume plenty and lots of sugar and await the minute you get domicile once you may crash on your mushy, cool, comfortable mattress.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...