Program tells me cannot find variable?

publicclass Game{

private String name;

privateint score;

public Game (String Studname,int points)

{

name = Studname;

score = points;

}

public String toString()

{

String result;

result = name +"\n";

result += points;

return result;

}

}

Hi guys, this is part of a aggregation, but when i want to compile it tells me it cannot find the variable points, even though i have defined it.

[970 byte] By [Scottydont2841a] at [2007-11-26 21:22:44]
# 1
You declared points as a parameter to the constructor, so it's local to that c'tor and only exists within the scope of that c'tor. Perhaps you mean score rather than points?
jverda at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 2
Lol how did i miss that, shocking, cheers mate.
Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 3

Right, I had to write two classes for these UMLs

Player

- name : String

- game1 : Game

- game2 : Game

+ Player(String, Game, Game )

+ toString( ) : String

Heres what i did for player

public class Player {

private String name;

private String game1, game2;

public Player (String Studname, String game, String games)

{

name = Studname;

game1 = game;

game2 = games;

}

public String toString()

{

String result;

result = name + "\n";

result += game1 + "\n";

result += game2 + "\n";

return result;

}

}

I also had to do Game.

_

Game

_

- name : String

- score : int

_

+ Player(String, int )

+ toString( ) : String

_

Heres what i wrote for game,

public class Game {

private String name;

private int score;

public Game (String Studname, int points)

{

name = Studname;

score = points;

}

public String toString()

{

String result;

result = name + "\n";

result += score;

return result;

}

}

They are supposed to demonstrate aggregation, have i done it right?

Cheers guys.

Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 4
- game1 : Game- game2 : Gamegame1 and game2 aren't supposed to be Strings.
floundera at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 5
Yea i know but i put them as strings because it wouldnt recognise Game. Any ideas?
Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 6
Anyone?
Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 7
Do you have Player.java and Game.java in the same directory?
floundera at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 8
What do u mean by directory? they are in the same package.Im supposed to test it after (by writing a test program) so i get something likeDetails for player LizzyChess score = 56Hockey score = 80
Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 9
Write your test program and compile that, it should compile Player and Game for you.
floundera at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 10
They do both compile, its just when it comes to that data you said earlier, the variables game1 and 2 are down as Game, is Game a JAVA data type?
Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 11
So anyone know whether Game is actually a Java data type, because thats what the UML wants me to call it right? Sorry to be pushy, I have rougly 4 hours to finish this.
Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 12
Game is one of the classes YOU wrote. Saints preserve us!
floundera at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 13

I know it is, i was referring to this

Player

- name : String

- game1 : Game

- game2 : Game

+ Player(String, Game, Game )

+ toString( ) : String

and your comment

>- game1 : Game

>- game2 : Game

>game1 and game2 aren't supposed to be Strings.

If it isnt string what can i have it as?

Cheers flounder.

Scottydont2841a at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 14
GAME!Are you missing a piece of your brain?
floundera at 2007-7-10 3:02:22 > top of Java-index,Java Essentials,New To Java...
# 15
Those Game objects are instances of YOUR Game class.
jverda at 2007-7-21 18:16:27 > top of Java-index,Java Essentials,New To Java...
# 16
LOL sorry, i know what i did wrong earlier, put a bracket in by mistake which means it wouldnt compile, which is what kept me thinking Game wouldnt be accepted, sorry, Im getting tired, its 4am.
Scottydont2841a at 2007-7-21 18:16:27 > top of Java-index,Java Essentials,New To Java...
# 17
Then go to bed. You are tired and stressed. All you will achieve is to make lots more silly mistakes.
floundera at 2007-7-21 18:16:27 > top of Java-index,Java Essentials,New To Java...
# 18
I think thats good advice, thanks for all the help anyway fellas, I can see I started to stress you too.
Scottydont2841a at 2007-7-21 18:16:27 > top of Java-index,Java Essentials,New To Java...