LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 359 users online 167904 members 447 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Video | Dictionary | News | FAQ
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
4 online / 16 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Java Help!
I need it.
Replies: 8Last Post Sep. 23, 2005 1:13pm by Plastik
Single page for this topic Email Print Favorite
( knotsotypikal )


Connoisseur

Patron
Reply
I have a nice little program written that's a test. It calculates the score and presents you with a letter grade and all. The program seems to be fine, but the stupid curly bracket things are messed up. How do you know where to put them? I keep getting errors that I need one here or there, and when I put one here or there, the newest one has the same error.

Any help is appreciated. Thanks.

-------
Cinnamon and sugary, and softly spoken lies
You never know just how you look through other people's eyes.


12:47 pm on Sep. 23, 2005 | Joined Dec. 2004 | 386 Days Active
Join to learn more about knotsotypikal South Carolina, United States | Straight Female | 1819 Posts | 7961 Points
anti christ

Connoisseur

Patron
Reply
lol I just started the Intro to Programming in my freshman college course, so I cant help you! lol

12:48 pm on Sep. 23, 2005 | Joined July 2005 | 242 Days Active
Join to learn more about anti christ United States | 9187 Posts | 7149 Points
( knotsotypikal )


Connoisseur

Patron
Reply
Oops.

(Edited by knotsotypikal at 4:18 pm on Sep. 23, 2005)

-------
Cinnamon and sugary, and softly spoken lies
You never know just how you look through other people's eyes.


12:52 pm on Sep. 23, 2005 | Joined Dec. 2004 | 386 Days Active
Join to learn more about knotsotypikal South Carolina, United States | Straight Female | 1819 Posts | 7961 Points
Plastik

Dairy Product Addict

Patron
Reply
Curly braces are sort of like parantheses for blocks of code. For instance, if you're designing a class, such as main, you want { after "public class main" which indicates main contains all of the following. Then a } to close off the class when you're all done.

You'll also need them for blocks such as:
When there is more than 1 line to do after an "IF" statement

When there is more than 1 line to do after a "WHILE" statement

etc.

...if there's still a problem, send me the code in question and I can almost definetly show you exactly where the problem(s) are.

(Edited by Plastik at 3:53 pm on Sep. 23, 2005)

-------
And then his mind exploded.


12:53 pm on Sep. 23, 2005 | Joined Sep. 2003 | 263 Days Active
Join to learn more about Plastik Massachusetts, United States | Straight Male | 2365 Posts | 5007 Points
philippastar


Technician
Reply
haven't got a clue, sorry

-------
life is like a box of chocolates, You never know which one you are going to take

12:56 pm on Sep. 23, 2005 | Joined Sep. 2005 | 24 Days Active
Join to learn more about philippastar United Kingdom | Metrosexual Female | 157 Posts | 330 Points
( knotsotypikal )


Connoisseur

Patron
Reply
I think my problem is I'm putting too many. You don't need them before and after declaring variables, right? When I move some brackets around, I get x's on the whole thing, and then they go away.

-------
Cinnamon and sugary, and softly spoken lies
You never know just how you look through other people's eyes.

12:58 pm on Sep. 23, 2005 | Joined Dec. 2004 | 386 Days Active
Join to learn more about knotsotypikal South Carolina, United States | Straight Female | 1819 Posts | 7961 Points
Plastik

Dairy Product Addict

Patron
Reply
Well the following is a small class example just from what I currently have open at this very moment... It contains a field, a constructor, and a few short methods. ... basically everything you might see:

package CardGame.Gameplay;
import CardGame.Helpers.*;
import CardGame.Cards.*;

// Player's 'Hand' ... Just a list of cards.
public class Hand
{
private List cards = new Empty();

public Hand()
{
}

public void addCard(Card toAdd)
{
this.cards.add(toAdd);
}

public void removeCard(Card toRemove)
{
this.cards.removeCard(toRemove);
}

}




p.s.: ALWAYS initialize your variables...
Don't write int x;
Write int x = 0;

Otherwise you're opening the door for null pointer exceptions which are stressful and hard to track down.

(Edited by Plastik at 4:05 pm on Sep. 23, 2005)

-------
And then his mind exploded.


1:04 pm on Sep. 23, 2005 | Joined Sep. 2003 | 263 Days Active
Join to learn more about Plastik Massachusetts, United States | Straight Male | 2365 Posts | 5007 Points
( knotsotypikal )


Connoisseur

Patron
Reply
Aha! I had a char variable and I didn't set it to 0. I didn't know you had to set everything to 0, especially letters...and it said it wasn't initialized. It's fixed now, thanks.

-------
Cinnamon and sugary, and softly spoken lies
You never know just how you look through other people's eyes.

1:10 pm on Sep. 23, 2005 | Joined Dec. 2004 | 386 Days Active
Join to learn more about knotsotypikal South Carolina, United States | Straight Female | 1819 Posts | 7961 Points
Plastik

Dairy Product Addict

Patron
Reply
Quote: from knotsotypikal at 4:10 pm on Sep. 23, 2005

Aha! I had a char variable and I didn't set it to 0. I didn't know you had to set everything to 0, especially letters...and it said it wasn't initialized. It's fixed now, thanks.

You can set it to anything.

As for the char... a char is actually a number, so setting it to 0 is alright. If it was a string, you'd want something like ... String x = "";

But it can be anything  -- The problem is when anything looks at that variable before anything is put IN the variable...you get errors. Sometimes you might be looking at that variable without even realizing it, which just causes infinitely more confusion. So always remember to initialize it to SOMETHING.

-------
And then his mind exploded.


1:13 pm on Sep. 23, 2005 | Joined Sep. 2003 | 263 Days Active
Join to learn more about Plastik Massachusetts, United States | Straight Male | 2365 Posts | 5007 Points
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic