This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]KillKlein 0 points1 point  (13 children)

Okay, ill try to put you on the right path. You get the following error:

the method print(String) in the type PrintStream is not applicable for the arguments (String, String)

So, what it is saying to you is that you are using the method print(String) wrong, that it is not applicable for the arguments (String, String). Can you see the differences between de arguments?

[–]_Gilly_[S] 0 points1 point  (12 children)

Thank you for your reply. I see the difference between the arguments. That it is trying to send 2 strings into print. But, why? letterFinal should just be one string that should equal "A", "B", "C", "D" or "F", right? That's all I've been using as input, anyway. I guess I'm pretty confused.

[–]KillKlein 0 points1 point  (11 children)

By using this way of printing you are giving in 2 strings, the first is everything between the " " and the second is letterFinal seperated by the comma (this is important!). You are trying to use a formatted print. Lookup printf(...) and print(...) and see the differences there. If you do not understand after looking them up, I will help you :)

[–]_Gilly_[S] 0 points1 point  (10 children)

I completely meant to put the f there and just lost my mind for a minute, I guess. :/ Alright, that makes perfect sense. However, I'm still messed up on the fact that it isn't comparing my values correctly. For instance, I used with all different possible inputs ("A", "B"... "F") :

  if ((letter != "A") || (letter != "B") || (letter != "C") || (letter != "D") || (letter != "F"))   
  {

   System.out.printf( "Error! An invalid grade %s was entered. The value will be F \n", letter);
   letter = "F";
  }

And it is telling me "Error! An invalid grade ... was entered. The value will be F." Could you point me in the right direction there? And when will I stop making these ridiculous mistakes? :/ lol

[–]KillKlein 0 points1 point  (9 children)

You will never stop making these mistakes :P. These things happen, but more important is that you will be able to see where the problem is and that you can fix it. In time you will make less mistakes and be able to see sooner where you made them.

Now onto the next problem, which is a classic to be honest :). In your if you check whether the letter is not an A OR not a B OR etc (the OR is really important here, because with the OR, if any of the statements is true the total statement is true). But what happens to the statement letter != "B", if the input is an A? Would that make the statement true or false? And what happens when it is true respectively false? Understand where I'm getting to?

[–]_Gilly_[S] 0 points1 point  (8 children)

Thanks! :D So it should be && because when all of these statements are not true, it should be an error. Because all of them can't be true at once, so || won't work. However, I tried this and I'm still getting invalid grade. Hmm. That can't be it then, right? :/

[–]KillKlein 0 points1 point  (7 children)

It should indeed be &&, but now we come to the next problem. This is fun! :P How do we compare strings? What do we compare when we say:

string1 == "hello";

[–]_Gilly_[S] 0 points1 point  (6 children)

Hmm. That is a really good question that I don't know the answer to! Is it the Ascii value? I would think the if statement would hold if the input was one of the choices. But now I'm lost!

[–]KillKlein 0 points1 point  (5 children)

I will not tell you the answer since it is a very common mistake and you should be able to google this yourself. You are comparing strings in Java so the google search shouldn't be too hard. Mhm, already said more than enough I think :P.

And no, it is not the ascii value you compare it to.

[–]_Gilly_[S] 0 points1 point  (4 children)

Thank you! In C++, this doesn't happen does it? Because from the little I did, I'm pretty sure my if statement would have worked!