0

The following displays a player along with a stat line(Points, Assists, etc.). For the sake of having to create this for several players, is there any way I simplify this or am I approaching this completely wrong?

public static void main(String[] args) {
    LinkedHashMap<String, LinkedList<Double>> chart = new LinkedHashMap<String, LinkedList<Double>>();
    LinkedList<Double> stats = new LinkedList<Double>();


    stats.add(6.8);
    stats.add(11.6);
    stats.add(11.6);

    chart.put("Micheal Jordan", stats);


    for(Map.Entry<String,LinkedList<Double>> entry: chart.entrySet()){
        String name = entry.getKey();
        LinkedList<Double> number = entry.getValue();

        System.out.println(name + " " + number);
    }
zencoder24
  • 1
  • 1
  • 4
  • write a function that accepts the 'stats' and return 'chart' – Sanjay Rabari Mar 03 '15 at 05:49
  • a) You could and probably should create a constructor for a "Player" object with those stats as attributes, rather than having some linked list where you don't know what's what. b) It's Mich*ae*l Jordan. c) He scores _way_ more than 6.8 points per game! ;-) – Amos M. Carpenter Mar 03 '15 at 05:53
  • I know haha. I was just thinking of better alternatives than having a constuctor with 8 or 9 different arguments. – zencoder24 Mar 03 '15 at 06:01
  • If some object tend to have more and more optional attributes you should consider builder pattern. – vrudkovsk Mar 03 '15 at 06:39

0 Answers0