//GRUPO 2 public class Artist { private static final int GROWTH_FACTOR = 2; private static final int DEFAULT_SIZE = 1000; private static final int OEUVRE_EXISTS = 1; private static final int SUCCESS = -1; private String name; private Oeuvre[] oeuvres; private int count; /* Cria um artista com o nome dado e uma coleccao vazia de obras da sua autoria, * e coloca o contador de obras a zero. * * @pre name != null */ public Artist(String name) { ... } public String getName() { ... } // @return true, se o artista ja’ produziu alguma obra; // false, no caso contrario. public boolean hasOeuvres() { ... } /* Insere uma nova obra (no estado por vender) na coleccao de obras do artista, * se nao existir uma obra com o nome e o ano especificados. * * A operacao deve manter a coleccao de obras do artista por ordem crescente * de ano; em caso de empate no ano, por ordem alfabetica de nome da obra. * * @return OEUVRE_EXISTS, se ja’ existir uma obra com o nome e o ano dados; * SUCCESS, no caso contrario. * * @pre nameOvr != null && price > 0 */ public int addOeuvre(String nameOvr, int year, double price) { if(exists(nameOvr,year)) { return OEUVRE_EXISTS; } else { if(isFull()) resize(); int index = findIndexToAdd(nameOvr, year); if(index != count) { for(int i = count - 1; i >= index; i++ ) oeuvres[i+1] = oeuvres[i]; } oeuvres[index] = new Oeuvre(name, nameOvr, year, price); return SUCCESS; } } // @return true, se existir na coleccao uma obra com o nome e o ano dados; // false, no caso contrario. // @pre nameOvr != null public boolean exists(String nameOvr, int year) { return (findIndex(nameOvr,year)>= 0); } /* Coloca o estado de uma obra, identificada pelo seu nome e ano, como vendida, * assumindo-se que o artista tem uma obra com o nome e o ano dados. * * @pre nameOvr != null && exists(nameOvr, year) */ public void sell(String nameOvr, int year) { oeuvres[findIndex(nameOvr,year)].sell(); } // @return a soma dos precos de todas as obras vendidas. public double valueSales() { double value = 0; for(int i = 0; i= max) { max = count; yearMax = oeuvres[i].getYear(); } count = 0; } } return yearMax; } //Metodos Auxiliares - Obrigatório ter alguns destes para este teste embora não diga isso em lado nenhum public void resize(){ Oeuvre[] aux = new Oeuvre[GROWTH_FACTOR * oeuvres.length]; for(int i = 0; i year) high = mid - 1; else if(oeuvres[mid].getYear() < year) low = mid + 1; } return -1; } public int findIndexToAdd(String nameOvr, int year) { int pos = -1; int i = 0; while (1