How do I display attributes of an object stored in an array?

Asked

Viewed 45 times

-2

I’m doing a job that consists of fictitious real estate. In this program there is a class called principal where it receives Immovel (Class) and stores the immovables in a vector, a class Immobiliary that has ways of registering the immovables, a superclass Immovel and other 4 classes that are the types of Immovel (Land, Salacomercial, House and Apartment) each of these 4 classes has a @override of Imovel to display its attributes. it follows how I realized the storage of the immovables:

Imovel[] imoveis; // cria vetor de imoveis do tipo Imovel (SuperClasse)

//Pega o imovel e coloca no dito array
public void setImovelArray(Imovel imv) {
        imoveis[b] = imv;
        b++;
        System.out.println("Imóvel guardado sob ID:"+b);
    }

Logic party where the Real Estate class has the immovable registration function and the Main class the function of storing in the array. Where and how I call a function to search in the array a specific immovable (ex by the existing owner attribute in all immobles) and call its respective function displaDetails(); existing in each immovable instance?

Any additional information may be requested ;)

1 answer

0


I don’t know much about java. But all kinds of buildings where you want to find the data inherit from the immovable class.

You can make a method in it by passing the attributes you might want to search for and if you don’t have by default your null arrow.

In the implementation of this class you go through the array looking for the value that was passed in the parameter.

And finally in the main you call this implementation for all kinds of immovables that you need.

I hope I’ve helped in some way :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.