File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes simple programming trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple programming trouble" Watch "simple programming trouble" New topic
Author

simple programming trouble

nick sutton
Greenhorn

Joined: Oct 03, 2009
Posts: 12
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

Joined: Jan 28, 2003
Posts: 3932
    
  17

Can you tell us the error you get and on what lines you get them?


Steve
nick sutton
Greenhorn

Joined: Oct 03, 2009
Posts: 12
invalid method declaration. return type required
nick sutton
Greenhorn

Joined: Oct 03, 2009
Posts: 12
line 17
nick sutton
Greenhorn

Joined: Oct 03, 2009
Posts: 12
hold on. in place of count it really is convert. sorry typo
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3932
    
  17

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

Joined: Oct 03, 2009
Posts: 12
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
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3932
    
  17

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

Joined: Oct 03, 2009
Posts: 12
cool thanks. got it going
 
 
subject: simple programming trouble
 
Similar Threads
need help please?
Help setting up an array and other issues
While Loop Not Reading First Integer
What is he saying?
Getting the average to display