• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple programming trouble

 
nick sutton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so im tryng to finish this program but i cant get it to work. when i compile it it gives me two errors. I'm trying to convert the values of the letter grades into astericks *. i created a method and it says i have declard it wrong. kinda lost. any help would be nice.



[HENRY: Fixed code tag]
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell us the error you get and on what lines you get them?
 
nick sutton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
invalid method declaration. return type required
 
nick sutton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 17
 
nick sutton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hold on. in place of count it really is convert. sorry typo
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick sutton wrote:invalid method declaration. return type required


That is pretty straight forward.

The line in question is:

That is a method declaration. What is the return type for that method? i.e. What type of value do you expect to get from the method's return statement?
 
nick sutton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the letters values are saved. for instance if you typed in 4 sets of 90's the value of A would be 4. at the end of the program it should convert that value into those astericks. the return is an asterick?
 
Henry Wong
author
Marshal
Pie
Posts: 21419
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick sutton wrote:the letters values are saved. for instance if you typed in 4 sets of 90's the value of A would be 4. at the end of the program it should convert that value into those astericks. the return is an asterick?


A java method is required to declare a return type... what is the return type? and where is it declared? Take a look at every method, that you wrote, that compiles, and compare it to this one -- you will see that something is different.


Henry
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nick sutton wrote:the letters values are saved. for instance if you typed in 4 sets of 90's the value of A would be 4. at the end of the program it should convert that value into those astericks. the return is an asterick?


It could be. But not just an asterisk, right? The 4 asterisks in a row.

Let's look at where you call the method:


Here you are looking to add the value of convert(A) to the Strings "\nA'1" and "\n...". This suggests that indeed, you do expect to return those asterisks from the method. But as what?

But let's also look at the method you created:


In this code, you just output the asterisks, you don't return them as a value. This is fine (as long as you define the proper return type) but it isn't really compatible with how you use the method. You need to ask yourself:
"Should I (a)return a value like I expect to in when I call the convert() method, or do I (b)not return a value, and simply display asterisks like the method is currently coded?"

Either way, you need to modify your code to either (a) return something, or (b) return nothing and change how the method is called so the caller doesn't expect something returned.

You should read up on methods a bit - a review of your textbook's coverage of methods might help as well.
 
nick sutton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool thanks. got it going
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic