Pedro Xavier Posted April 9, 2015 at 06:14 PM Report Share #581005 Posted April 9, 2015 at 06:14 PM (edited) Boas, alguem me podia explicar como fazer este exercicio? é que não estou a ter nenhuma ideia :...... EXERCICIO: Crie uma classe BicycleManagment que armazene um vetor de bicicletas (Bicycle[]). Crie um método para adicionar bicicletas ao vetor até a um máximo de 20. De seguida e utilizando a classe BikeDemo, teste a classe criada, adicionando as bicicletas que criou na alínea 1.1. Crie ainda um método na classe BicycleManagment, que imprima todos os dados das bicicletas contidas no vetor que criou. vou deixar aqui as minhas classes já utilizadas public class Bicycle { private int id; private int numberOfGears; private String mainColor; private float weelSize; private float bikeLength; private boolean adjustableSeatpost; private float price; public Bicycle(int id, int numberOfGears, String mainColor, float weelSize, float bikeLength, boolean adjustableSeatpost, float price){ this.id = id; this.numberOfGears = numberOfGears; this.mainColor = mainColor; this.weelSize = weelSize; this.bikeLength = bikeLength; this.adjustableSeatpost = adjustableSeatpost; this.price = price; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getNumberOfGears() { return numberOfGears; } public void setNumberOfGears(int numberOfGears) { this.numberOfGears = numberOfGears; } public String getMainColor() { return mainColor; } public void setMainColor(String mainColor) { this.mainColor = mainColor; } public float getWeelSize() { return weelSize; } public void setWeelSize(float weelSize) { this.weelSize = weelSize; } public float getBikeLength() { return bikeLength; } public void setBikeLength(float bikeLength) { this.bikeLength = bikeLength; } public boolean isAdjustableSeatpost() { return adjustableSeatpost; } public void setAdjustableSeatpost(boolean adjustableSeatpost) { this.adjustableSeatpost = adjustableSeatpost; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } } public class MountainBike extends Bicycle { private int NumberOfLigths; private MountainBikeSuspension suspension; private BikeTools[] bikeTools; public MountainBike(int id, int numberOfGears, String mainColor, float weelSize, float bikeLength, boolean adjustableSeatpost, float price, int NumberOfLigths, MountainBikeSuspension suspension, BikeTools[] bikeTools) { super(id, numberOfGears, mainColor, weelSize, bikeLength, adjustableSeatpost, price); this.NumberOfLigths = NumberOfLigths; this.suspension = suspension; this.bikeTools = bikeTools; } public void ImprimirFerramentas(){ for(Object m1 : bikeTools){ if(m1 instanceof BikeTools){ BikeTools M = (BikeTools) m1; System.out.println("ID: " + M.getId()); System.out.println("NAME: " + M.getTool()); } } } public int getNumberOfLigths() { return NumberOfLigths; } public void setNumberOfLigths(int NumberOfLigths) { this.NumberOfLigths = NumberOfLigths; } public MountainBikeSuspension getSuspension() { return suspension; } public void setSuspension(MountainBikeSuspension suspension) { this.suspension = suspension; } public BikeTools[] getBikeTools() { return bikeTools; } public void setBikeTools(BikeTools[] bikeTools) { this.bikeTools = bikeTools; } } tenho mais classes, para outro tipo de bicicletas e ferramentas.... Mas o que me aconselham?? Cumprimentos eu já tenho criadas as bicicletas num BikeDemo, só falta manda las para o BicYcleManagment Edited April 9, 2015 at 07:29 PM by apocsantos geshi Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 9, 2015 at 06:14 PM Report Share #581007 Posted April 9, 2015 at 06:14 PM não percebi. estás a dizer que não sabes criar uma classe usada como aplicação de consola usada para testar a classe BicycleManagment ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Pedro Xavier Posted April 9, 2015 at 06:40 PM Author Report Share #581010 Posted April 9, 2015 at 06:40 PM a minha duvida é: se só mandar 2 bicicletas como paro o array??? é que imprime me as 20 posicões Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted April 9, 2015 at 06:51 PM Report Share #581012 Posted April 9, 2015 at 06:51 PM se tens um array de bicicletas (referências para instâncias), terás de inicialiar-las. basta verificar se a referência está inicializada para determinar se a posição do array se encontra a guardar uma bicicleta IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
alexandre1985 Posted April 10, 2015 at 05:22 PM Report Share #581035 Posted April 10, 2015 at 05:22 PM o teu problema deve de estar na inicialização de bikeTools. Que classes de objectos guardas em bikeTools[] ? Mostra-me também inicialização de bikeTools[] http://alexandre1985.github.io Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now