Hello everyone. I'm new here. I'm taking an online course about coding but the teacher is really bad and isn't doing a good job in teaching the class. I'm trying to read up on beginner's guides everywhere but I still need some help.
I need to write a program to compute the ideal weight for both males and females, where the ideal weight for a female who is 5'3" would be 100 + 15 = 115 pounds and for a male the ideal weight is 106 pounds plus 6 pounds for each inch in height over 5 feet.
I've tried making my own code but I've gotten 6 identifier errors. The teacher told me to use previous codes as an example to what I should do so I used my Circles program (which found the area of a circle with any given radius).
Here's what I came up with for the Ideal Weight program.
Again, I have no idea what anything really means (only some very basic stuff. I have yet to learn how to put it all together), so I tried replacing things that seemed fit.
In Java, all code must be inside a method (OK, there are a few exceptions, but since you are a beginner, we'll ignore those), and all methods must be inside a class.
You have the class defined, but no methods, and a bunch of executable statements. That won't work. The first thing you should do is create a main method.
But let's back up even further. You should never have gotten this far. I've been writing java code for about 10 years, and I never NEVER write more than 2-3 lines before I recompile, debug, and test.
That way, you know exactly where the problem is going to be, and you don't get 100+ errors and get discouraged.
I took your code, wrapped it in a main method, and re-compiled.
You're missing a semi-colon on one line, so i fixed that...and got 11 errors, because you are missing some import statements.
My point is, you would probably do better to almost start over. EVERY SINGLE TIME I start a new project, my code looks something like this the first time I compile:
Even just now, when I attempted to compile your code, I did this first, and discovered I had typed "statis" instead of "static" on my main method, giving me an error. But since I had only a few lines of code, it was easy to find and correct. Then I pasted your code inside my main method (taking out my println), and recompiled.
If I really wanted to do it, right, I would only and 1-2 lines of your code at a time and recompile after each, fixing errors as I go.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
There must be something wrong with my brain because no matter what, this stuff just isn't clicking for me. I've never had any problems like this. I may have to actually talk to someone to understand this because I read both those links you gave me and "Beginner's Programming of Java Guide for Dummies" and even though it did help, I'm still all kinds of confused when it comes to actually writing by myself.
I understand (mostly) what each "word" does, but I still have no clue how to put it all together.