• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

test4.java:35: error: method in class cannot be applied to given types; method without parameters

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a method for recording the Gender, the height and waist, and I need to move my if / else statement into a method. You will see I tried to create a method for gender, but I get test4.java:35: error: method getGender in class test4 cannot be applied to given types;. I have read that it is becuase I am passing it without parameters but my Professor wants it without parameters. I also am struggling to get the total mins excercised a week, it will ask 7 times for amount of minutes exercised but how do I call the results. I know this is a alot but any help, and I would be grateful.






 
Bartender
Posts: 7436
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are passing in a parameter called "gender". Why do you think you need this or any parameter? Many methods have no parameters. If you wanted a variable called "gender" to use you could create it as a local variable.
Or not use a variable at all.
Now at this point I wonder what the purpose of this seeing as how this is so trivial. Often in methods that gather user input there is means to display a prompt to the user first, perhaps that can be done in your code.

This line for Scanner
is good in that it is a static class member, meaning there is only one. There should only be one Scanner built from System.in for an entire project. And you should never close such a Scanner. You can take your code one step further though and that is to create a constant out of it. Remember that constant names should be in all upper case characters. So then you have...
 
Carey Brown
Bartender
Posts: 7436
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Marshal
Posts: 71097
292
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Afraid your code is almost illegible. Part of that is because of the inconsistent indentation; for example lines 12 13 16 17 18 should be farther to the right. And don't print sloping code. Also, the long lines often in comments make it fall off the edge fo a small screen.
Why are you using a diifferent indentation convention for your last method?
Don't use // comments for a whole line; use /* comments */. Use /** documentation comments */ before your class and methods.
This is what I think your code should look like.Nobody indents multiple if‑elses else‑ifs with a slope. Your else‑ifs are not correct because they don't take the potential value 52.005 into consideration. Your WTH method doesn't use double arithmetic, so you won't get 52.005 anyway.
Suggested improvements:-
  • 1: Don't use <= or >= if you can use < and > only.
  • 2: Don't use && or || in else-if if you an avoid it.
  • Example of a series of else‑ifs following those recommendations here. If the boundary value (52) is included in the lower category, rather like how the cost of posting a parcel doesn't change when you reach 10lb, so you would write something like:-Note no weight >= 50.01 or anything like that is necessary.
  • 4: Your main method is much much too long. That method should be divided up; you can easily extract ten separate methods from it. It also has too many variables in, but dividing the method may cure that problem.


  • I am afraid there is lots more I could talk about in your code if I had more time.
     
    Elaina Brown
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I appreciate all of the time and effort everyone on my post has put in to help me. This is the first code I have ever written so I know it is messy, and needs a load of work so your patience is beyond appreciated. I know it is not the best, but I did try to make some improvements. ( My professor wants use to use && and || as it is part of a operand lesson so I did not correct that part). I am still struggling a great deal getting my nested if / else statement into a method outside of main. When I do I get an error that is an illegal start of an expression, I think this is because something is wrong with my formatted, but I am determine to figure it out. I hope it looks a little better and I again can thank everyone enough for all of the help!

     
    Carey Brown
    Bartender
    Posts: 7436
    66
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
     
    Sheriff
    Posts: 7108
    184
    Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Elaina Brown wrote:When I do I get an error that is an illegal start of an expression, I think this is because something is wrong with my formatted, but I am determine to figure it out.  


    Well, I'd say, Figure it out by formatting correctly.  Format as you code, and you're let likely to make these kind of mistakes.  If you're using an IDE, it's as simple as a keyboard shortcut, like Ctrl-Shift-F in Eclipse.  Without an IDE, you can make it easier to format by adding the ending brace right after typing the first line of a block, then indent the first line in the middle.  Many text editors (like Notepad++ or vi) will keep your indentation for you as you write.

    So, do this:
    Then do this:
    and so on.
     
    Campbell Ritchie
    Marshal
    Posts: 71097
    292
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Elaina Brown wrote:I appreciate all of the time and effort everyone on my post has put in to help me.

    That's a pleasure

    This is the first code I have ever written . . .

    Didn't you start off with one‑method classes?

    My professor wants use to use && and || as it is part of a operand lesson . . .

    tt is annoying, but having to write such expressions trains you in the use of operators, but your code doesn't look as good. You are stuck with it for the moment, I am afraid.

    nested if / else statement into a method outside of main. When I do I get an error that is an illegal start of an expression, I think this is because something is wrong with my formatted, but I am determine to figure it out. . . .

    Whenever I have had that error it is because I have tried to put two methods inside each other. Again, formatting will help you find that error. Get a decent text editor (NotePad++ being my favourite if I ever use Windows®) and set up bracket matching. Hover your mouse over a ( or [ or { and its pair wlll change colour.

    I call Knute's suggestion writing backwards.
     
    All that thinking. Doesn't it hurt? What do you think about this tiny ad?
    the value of filler advertising in 2020
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic