Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

You are to write a Java program that will take a grade as a String. This grade has the form of a letter followed by an optional sign (e.g. +, -). The letter values are worth 4.0 grade points for an A, 3.0 for a B, 2.0 for a C, 1.0 for a D, and 0 for an F. The + sign add 0.3 to the grade points and the - sign subtracts 0.3. Note that an "A+" is still 4.0 points and an "F+" or "F-" is still 0 grade points. This object will have a constructor that takes no arguments and the following two methods: public Grade(String grade) public String getLetterGrade() public double getNumericGrade()

OpenStudy (harsha19111999):

If you enter the points, it should display the grade?

OpenStudy (anonymous):

Yes, I've been trying if/if else conditions but I'm completely befuddled by the constructor that he wants me to use.

OpenStudy (mandre):

From my experience so far with "blank" constructors (I use C++, not Java, but I think they're fairly similar), it is normally used to clear whatever construct the class is building, like linked lists and so on. So I would assume if you use (a) "global" variable(s) the constructor might clear that/those variable(s). If public Grade(String grade) is your constructor shouldn't you remove "String grade" as you say your constructor should not take arguments.

OpenStudy (harsha19111999):

Hey, your question is a bit complicated for me, because it deals with Strings in detail. So, once try googleing for "Morse code JAVA" and it displays many results. It will help you

OpenStudy (lyrae):

All Java classes needs a constructor to be instantiated, therefore a default empty constructrutor is automaticly generated if none is povided. ``` class Grade { public double value = 0.0; } ``` is the same as ``` class Grade { public double value = 0.0; Grade() {} } ``` @Mandre You can actually have both methods. This is something called ´method overloading´ or in this case ´constructor overloading´. It basicly allows you to have several definitions of the same method but with different arguments. ``` class Grade { Grade() { System.out.println("No grade provided in constructor!"); } Grade(String grade) { System.out.println(grade); } public static void main (String[] args) { new Grade(); new Grade("Hello world :)"); } } ``` prints ``` No grade provided in constructor! Hello world :) ``` Runnable example: http://ideone.com/ggtMCJ In @DasVickerMann's case there's a constructor specified in the assignment (public Grade(String grade)). When this constructor is implemented the default constructor isn't be generated. The creator of the assignment probably want the class to be instantiable without argument as well, and a empty constructor must therefore be added explicitly. More on overloading in Java: http://en.wikibooks.org/wiki/Java_Programming/Overloading_Methods_and_Constructors

OpenStudy (mandre):

@Lyrae, I understand the overloading part, but he specifically says it must not have arguments and as he says constructor + 2 methods and lists 3 methods, I assume his constructor should not have arguments. Thanks for the Java info though. I need to make time to learn it.

OpenStudy (woodrow73):

simple switch statement is all it takes.. and input validation can be used with the switch statement's default section. Message me if you want help to learn.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!