System Specification
A local football club wishes to store information on its current squad of players:
Each Player’s personal information (first name, last name, age, height and weight) should be recorded in a class Person.
Each Player’s record for the season should be stored in a class Player.
The information stored for each player consists of the number of games played and goals scored.
Write a class Goalkeeper which in addition records the number of penalties that the goalkeeper has saved.
Provide appropriate methods for accessing this information.
You should make appropriate use of inheritance in your solution.

Information on all Players should be stored in a class Club.
Club stores the name of the club and maintains information about all of it's players.
Club has methods to add and remove Players addPlayer(Player p) and removePlayer(Player p).
It should also contain a method to retrieve a Player’s details given her/his first and last names.
(You may assume that no two Players have identical first and last names).
This part here doesnt work when I try to retrive the players details, i can retireve the name but not his age,weight,height etc- my method to retreive the information looks like this and i dunno what is wrong,say the player's name is Ryan Dun and blue j display this instead "Player's details: Ryan Dun2118789"
.

public void retrievePlayersInfo(String fName,String lName)
    {
        //while(fName&&lName)
        String playerName = fName +" "+ lName;
       
        for(int i=0;i<clubPlayers.size();i++)
        {
            Player p = clubPlayers.get(i);
            if(p.getName().equals(playerName))
            {
                System.out.println("Player's details: " + p.getName() + p.getAge() + 
p.getHeight() + p.getWeight());
            }
        }
    }

Write classes Person, Player, Goalkeeper and Club that satisfy the above specification.
Write a class Test that contains a main method that tests your implementations and prints out the information held about each player in the club.
When a new player is signed, she/he should be inserted into the Club class in alphabetical order of last name (and first name if last names are the same).
To do this make your Person and Player class implement the appropriate Comparable interface.

Write a class ComparePlayers that implements the Comparator<Player> interface.
It should compare players by number of games played (and then by alphabetical order of surname if the number of games played is the same).
Implement a new Constructor for the Club class that takes a Comparator<Player> parameter.
Hence write a main program that will print information about each player in the club where players are listed by decreasing order of games played.
This should allow ordering to be dictated by the main program without modifying the code in any of your other classes.


Please could someone tell me what is it that i'm not getting right? Cheers:)

Recommended Answers

All 18 Replies

you may want to be a bit more specific, looks a bit like you just copy-pasted your assignment here. I don't see anything wrong with that print, btw, except that it's missing some spaces for formatting and that that information (weight ... ) should be stored in the class Person, not Player

Sorry about posting the whole thing cause it's easier to get te picture. I dont see anything wrong with my print method either except the ones u pointed out but it is just not printing out the valued stored. And I have nonidea why... Been stuck on that for a week now.

Not knowing anything else about the code, could it be a capitalization problem between p.getName() and playerName? Try

if(p.getName().equalsIgnoreCase(playerName))

and see if that helps.

2118789 - the obvious question is, is this actually working as expected? could Ryan be 21 years old, 187 cm tall, and 89 pounds(?) in weight?

Java doesn't insert any formatting when you concatenate strings, so if you concatenate three methods returning "Ryan Dun"+21+187+89, you'll end up with the string you cited. You'd have to insert spaces if you want them:

System.out.println("Ryan Dun"+" "+21+" "+187+" "+89)

will look a little better.

2118789 - the obvious question is, is this actually working as expected? could Ryan be 21 years old, 187 cm tall, and 89 pounds(?) in weight?

Java doesn't insert any formatting when you concatenate strings, so if you concatenate three methods returning "Ryan Dun"+21+187+89, you'll end up with the string you cited. You'd have to insert spaces if you want them:

System.out.println("Ryan Dun"+" "+21+" "+187+" "+89)

will look a little better.

I think 2118789 is the object. as I was suppose to store the player's info such as age,weight,height,games played and goals scored. and using the club class I was suppose to fetch a player's info using his name. the thing is, it only fetches the name and 2118789 instead of the supposing objects. Player stored are the objects.

Not knowing anything else about the code, could it be a capitalization problem between p.getName() and playerName? Try

if(p.getName().equalsIgnoreCase(playerName))

and see if that helps.

tried the if statement you suggested. but it doesn't work. still thanks :)

I think 2118789 is the object. as I was suppose to store the player's info such as age,weight,height,games played and goals scored. and using the club class I was suppose to fetch a player's info using his name. the thing is, it only fetches the name and 2118789 instead of the supposing objects. Player stored are the objects.

Read jon kiparsky's post again. He's almost certainly right.

commented: Gee, that's nice to see first thing in the morning. :) +2

Read jon kiparsky's post again. He's almost certainly right.

yeah,but am not suppose to hardwire the player's age, height, weight into the system.out.println . Am suppose to fetch all the details from another class just by entering the player's first and last name. Or am i just not getting it? :|

No, you're not getting it. His post is about formatting. It's quite likely that your program is OK, it's just the way you format (or fail to format) the output.

Try putting +" "+ between each of your method calls in the affected line.

ie p.getName()+" "+p.getAge()+" "+p.getStuffed()... or even (this may be a little radical) identifying what it is you're printing:


ie "name = "+ p.getName() +" age = "+p.getAge()+"stuffed = "+p.getStuffed()...

Try putting +" "+ between each of your method calls in the affected line.

ie p.getName()+" "+p.getAge()+" "+p.getStuffed()... or even (this may be a little radical) identifying what it is you're printing:


ie "name = "+ p.getName() +" age = "+p.getAge()+"stuffed = "+p.getStuffed()...

I get what you mean. Tried what you suggested but it is still not printing. its only printing the object i think.

"its only printing the object" doesn't make sense unless you are executing
System.out.println("Player's details: " + p);

Please copy your latest version of the print statement and paste it here.

Along with the output that you're getting.

"its only printing the object" doesn't make sense unless you are executing
System.out.println("Player's details: " + p);

Please copy your latest version of the print statement and paste it here.

System.out.println("Player's details: " + p.getName()+ "" + p.getAge()+ "" + p.getHeight()+"" + p.getWeight());

those methods are related to the player class and player class is inherited from the person class.

BlueJ terminal keeps printing
Player's details: cathy Dun1917667

regardless if I use +""+ or not.

You seem unaware that " " is not the same as "".
The fact you coded this seems to indicate that you still haven't understood Jon's point. Take a break. Take a deep breath. Read Jon's posts again. Repeat until you understand.

System.out.println("Player's details: NameIs > " + p.getName()+ " AgeIs > " + p.getAge()+ " HeightIs > " + p.getHeight()+" WeightIs > " + p.getWeight());

You seem unaware that " " is not the same as "".
The fact you coded this seems to indicate that you still haven't understood Jon's point. Take a break. Take a deep breath. Read Jon's posts again. Repeat until you understand.

Aite. Cheers. That really helped. I get it now :D

System.out.println("Player's details: NameIs > " + p.getName()+ " AgeIs > " + p.getAge()+ " HeightIs > " + p.getHeight()+" WeightIs > " + p.getWeight());

Thanks. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.