Public feed #892011

Mine

public java v1 · immutable
Raw Edit
·published 2008-02-05 02:06 UTC
rendered paste body
/* * Assignment #3b *  * Use the code from Chapter 3  *  GameEntry Class *  Scores Class *  add method *  remove method */package org.lurey.cs2b.assignments.gameentry;/** * @author Matan Lurey */public class GameEntry {    public String name;    public int score;        /**     * @param args the command line arguments     */    public static void main(String[] args)     {        GameEntry[] entries = {            new GameEntry("Mike", 1105),             new GameEntry("Rob", 750),            new GameEntry("Paul", 720),            new GameEntry("Anna", 660),            new GameEntry("Rose", 590),            new GameEntry("Jack", 510)        };                Scores list = new Scores(entries);                System.out.println("Score List\n" + list);                GameEntry jill = new GameEntry("Jill", 740);        GameEntry paul = new GameEntry("Paul", 720);                System.out.println("Adding jill and paul...");        list.add(jill);        list.add(paul);                System.out.println("Score List\n" + list);                System.out.println("Removing Jill");                list.remove(jill);                System.out.println("Score List\n" + list);    }        public GameEntry(String name, int score)    {        this.name = name;        this.score = score;    }        @Override    public String toString()    {        return name + "\t-\t" + score;    }}package org.lurey.cs2b.assignments.gameentry;import java.util.ArrayList;public class Scores<GameEntry> extends ArrayList<GameEntry> {    @Override    public String toString()    {        int length = this.size();        String buffer = "";                for (int i = 0; i < length; i++)            buffer += "[" + i + "]: \t" + this.get(i) + "\n";                return buffer;    }        public Scores(GameEntry[] entries)    {        for (int i=0; i<entries.length; i++)            this.add(entries[i]);    }        public Scores()    {        super();    }}