Mã:
import java.util.ArrayList;
import java.util.Collections;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Le Thanh Tung
*/
class Human {
private String name;
private int height;
Human(String _name, int _height) {
name = _name;
height = _height;
}
String getName() {
return name;
}
int getHeight() {
return height;
}
}
class FootBallPlayer extends Human {
private String position;
FootBallPlayer(String _name, int _height, String _position) {
super(_name, _height);
position = _position;
}
String getPosition() {
return position;
}
@Override
public String toString() {
return super.getName() + " plays as " + getPosition();
}
}
class FootBallClub {
ArrayList<FootBallPlayer> list;
public FootBallClub() {
list = new ArrayList<FootBallPlayer>();
}
void addPlayer(String name, int height, String position) {
list.add(new FootBallPlayer(name, height, position));
}
FootBallPlayer getPlayer(String name) {
for (FootBallPlayer it : list) {
if (it.getName().equals(name)) {
return it;
}
}
return null;
}
}
public class Main {
static FootBallClub club = new FootBallClub();
static void arrangeForMatch(FootBallClub club, int number) {
Collections.shuffle(club.list);
if (club.list.size() < number) {
System.out.println("Not enough player");
return;
}
System.out.println("Team for the next match:");
for (int i = 0; i < number; ++i) {
System.out.println(club.list.get(i));
}
}
public static void main(String[] args) {
club.addPlayer("Johnny Evan", 186, "CB");
club.addPlayer("Ferdinand", 183, "CB");
club.addPlayer("Luis Nani", 176, "RMF");
club.addPlayer("Cristiano Ronaldo", 186, "LWF");
club.addPlayer("David Degea", 193, "GK");
club.addPlayer("Robin Van Persie", 181, "CF");
club.addPlayer("Xavi Hernandez", 169, "CMF");
club.addPlayer("Xabi Alonso", 187, "DMF");
club.addPlayer("John Thomson", 189, "CB");
club.addPlayer("Theo Walcott", 172, "RWF");
club.addPlayer("Mesut Ozil", 178, "AMF");
System.out.print("Position of player with name John Thomson: ");
FootBallPlayer player = club.getPlayer("John Thomson");
if (player == null) {
System.out.println("Player not found");
} else {
System.out.println(player.getPosition());
}
arrangeForMatch(club, 11);
}
}
Mình chỉ mới biết cách sắp xếp theo chiều cao , mong mọi người giúp đỡ .
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...