• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

grade program

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I was wondering if someone could tell me how my program looks so far? If im on the right track or if its all hosed up?? This is what the program need to output:
There are two quizzes, each graded on the basis of 10 points.
There is one midterm exam, and one final exam, each graded on the basis of 100 points.
The final exam counts for 50 % of the grade, the midterm counts for 25%, and the two quizzes together count for a total of 25%.
I have to have several Accessor and Mutator methods, I have the Mutator Methods but im not sure how to use the Accessor Methods. All so were would I insert the doe to get the actual input from the keyboard?
Here is my code so far:
import java.io.*;


Please tell me what im doing right and wrong.
thanks
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it compile?

If you calculate the results manually, do you get the correct answers with your application?

Usually class names begin with Capital Letters like GradesProgram rather than gradesProgram.

Java is case sensitive, so midtermExam is not the same as midTermExam.
[ April 01, 2005: Message edited by: Marilyn de Queiroz ]
 
John Swain
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I corrected alot of stupid mistakes, but there is one cant figure out.
It says "illegal start of expression" and point to this line "void getName()" I dont see the problem with it, all my other methods are the same? here is the updates code
I think everything else is ok, but i also have to use the return statement and im completly lost on how that would apply to this.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler is complaining because you defined a method inside another method.
 
John Swain
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still dont understand, I thought i had the problem. I didnt have a { after the getLetterGrade method, so i placed one before the if/else if statment and still get the sane error. Or is it that i cant make the if/else if statment a method? More help please.
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you are missing a '}' at the end of your main method.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Horatio is correct and demonstrates that when the compiler points out an error, if you can't immediately see the problem, look backwards in the file to find the error. Often times a missing semi-colon or unmatched { } pair is the culprit.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may be wrong as im a newbie to this stuff but one thing i noticed was where you had all your If statements, say the final score was a 85, the grade would be a D because it will change the grade everytime the If statement is true. I think they should be if-else loops. Just my 1 cent.
-Clay
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Horatio Westock:
It looks like you are missing a '}' at the end of your main method.



Well, that's half of it. Even if you stuck that brace in there, your compiler would still complain.

The main (so to speak) problem is, as Marilyn mentioned, you're defining all of your other methods inside the main() method.

Really, all of your methods, including main(), should be defined inside your class.

Once you fix that, you'll next run into some trouble with your variables, because they're inside main(), and so your other methods won't know anything about them. And then you'll find a logic error in at least one spot. Those are the most fun to figure out, IHMO.

If I were you, I'd start over, and do things in very small steps. In other words, write a program that gets the name and scores from the keyboard and simply prints them back out. When you've got that working, add the part that figures out what their semester average is, and prints that out. Make sure that works. Then add the part that figures out the letter grade. Make sure that works.

Or, if the input part is giving you trouble, you can just assign some scores to your variables in the code, temporarily. Get everything else working, then figure out the keyboard input last.

If you just punch in the whole big, giant program at once, and it doesn't work, it's probably because a gazillion things are wrong, and those things could be anywhere!

But if you do things in little tiny chunks, and if you compile, run, and test often, then when errors do come up, they will be relatively few, and you'll know that they're most likely in the last thing you added or changed.

Good luck!

- Jeff
[ April 02, 2005: Message edited by: Jeff Jetton ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I totally agree with Jeff that trying to write the whole program at once is typically a bad idea. As you see, you often get a boat load of compiler errors that are difficult to track down. Jeff suggested one way of breaking the program into little steps. Feel free to break it down in a different manner, but the idea is to get a little part working before moving to the next part. This means that you should write a FEW lines of code, compile it, run it, test it, then go back and write a FEW more lines of code. As a rule of thumb, you should probably write less than 10 lines of code at a time before attempting to compile your program.

Also, when I code, I find it best to type in sets of matching braces, parentheses, brackets, etc. FIRST and then go back and fill in the details. For example, I usually start by writing the class like this:

Notice that I'll type BOTH braces, then use the arrow keys to go back and fill in the main() method:

Notice that I again type in BOTH braces before going back to fill in the code inside of main(). I suggest that you get in the habit of ALWAYS doing this. It helps avoid errors due to mismatched braces.

You should also adopt some coding conventions AND STICK TO THEM RELIGIOUSLY. The exact conventions aren't the issue here; these will change over time and eventually will be dictated by a company's policy (if you are heading towards a coding job in your career, that is). However, consistent use of the coding convention is essential, in my opinion, to make your code readable, for yourself more than for others.

Probably the first two things you should decide in your coding convention is where to place the opening brace for a block of code. It looks like you are already consistently placing it on its own line. That's good.

Another coding convention deals with indentation. First you need to decide how large to make your indentation. I think Sun's suggested convention is 4-space indentation. Secondly, you need to figure out WHERE to indent. It's common practice to indent code inside a set of curly braces, but to leave the curly braces at the same level as any leading code (such as a method signature or an if statement). As an example, notice in my code above, the main method (which is inside the curly braces for the class) is indented one level and its curly braces are lined up with the method signature. If I were to insert code inside of main() it would be indented another level.

Adopting such conventions, and religiously sticking to them, will help you avoid many common errors, both at compile-time as well as run-time.

So my suggesting is just as Jeff says: start over and write a little bit of code at a time. As you do, follow some kind of conventions to help keep your code readable.

I apologize if this doesn't answer your questions directly. I hope that this helps you avoid bad programming practices now so you don't have to unlearn them later.

Keep Coding!

Layne
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic