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.
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?
Lol how did i miss that, shocking, cheers mate.
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.
- game1 : Game- game2 : Gamegame1 and game2 aren't supposed to be Strings.
Yea i know but i put them as strings because it wouldnt recognise Game. Any ideas?
Do you have Player.java and Game.java in the same directory?
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
Write your test program and compile that, it should compile Player and Game for you.
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?
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.
Game is one of the classes YOU wrote. Saints preserve us!
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.
GAME!Are you missing a piece of your brain?
Those Game objects are instances of YOUR Game class.
jverda at 2007-7-21 18:16:27 >

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.
Then go to bed. You are tired and stressed. All you will achieve is to make lots more silly mistakes.
I think thats good advice, thanks for all the help anyway fellas, I can see I started to stress you too.