getting to read a String out of a class in an object ?
Hi everyone ..
I'm stuck in this, and i've tried many possible solutions ..
but here is my actual question :
i've got a class "Model" which holds : names (String), address (String), sizes (int, int ,int) .... and has the following methods: getName(), getSizes(), getAdress()
then i created a class "Models" wich holds an ArrayList of all the models
here i can : addModel(), removeModel(), showName()
everything works fine , except when i try to get the name from the models ... This is do way i tried to do this
publicvoid showNames(){
int i;
for (i=0 ; i<modellen.size() ; i++)
{
System.out.println(model.get(i));
}
}
The output is then instead of names, the references to the objescts (eg. : "Model@5b0668" )
What should i do to get the actual names (String) ?>
Thank you very much for your replies already !
the thing is, i've tried both those ways :
-getName() way : the compiler sais that there is not such method.
-toString way : returns the same value as without it : " Model@10772 " which refeers to the allacation of the method.
i also tried an iteration... the same...
i'm still kind of out of solutions here
maybe if i show you guys the code, you will be able to see a stupid mistake i'm looking over :
public class Adres {
private String straat;
private int postNummer;
private String gemeente;
public Adres()
{
straat ="";
gemeente="";
}
public Adres(String eenStraat, String eenGemeente, int eenPostNummer)
{
straat = eenStraat;
gemeente = eenGemeente;
postNummer = eenPostNummer;
}
public void setAdres(String eenStraat, String eenGemeente, int eenPostNummer)
{
straat = eenStraat;
gemeente = eenGemeente;
postNummer = eenPostNummer;
}
public boolean printAdres()
{
if(straat=="")
{
System.out.println("Adres: Geen adres");
} else {
System.out.println("Adres: " + straat + " " + postNummer + " " + gemeente);
}
return true;
}
public class Maten {
private int borstOmtrek;
private int taille;
private int heupOmtrek;
public Maten ()
{
borstOmtrek = 90;
taille = 60;
heupOmtrek = 90;
}
public Maten(int bOmtrek, int taille, int hOmtrek)
{
borstOmtrek = bOmtrek;
taille = taille;
heupOmtrek = hOmtrek;
}
public String printMaten()
{
return ("borst omtrek: " + borstOmtrek +"\n"+ "Taille: " + taille +"\n" +"Heup omtrek: " + heupOmtrek);
}
}
}
-
public class Model {
private String naam;
private Adres adres;
private Maten maten;
public Model(String nm)
{
naam = nm;
adres = new Adres();
maten = new Maten();
}
public Model(String nm, int bomtrek,int tnaille,int homtrek)
{
naam = nm;
maten = new Maten(bomtrek, tnaille, homtrek);
adres = new Adres();
}
public String getNaam()
{
return naam;
}
public void setAdres(String straat, int postcode, String gemeente)
{
adres.setAdres(straat, gemeente, postcode);
}
public void printInfo()
{
System.out.println( naam );
System.out.println(adres.printAdres());
System.out.println(maten.printMaten());
}
}
--import java.util.ArrayList;
public class Modellen {
private ArrayList modellen;
private Model model;
public Modellen() {
modellen = new ArrayList();
}
public void voegToe(Model model) {
modellen.add(model);
toonNamen();
}
public void verwijder(Model model) {
modellen.remove(model);
toonNamen();
}
/**
*
* Here is the actual problem !!!!
* if i try to get the names thruogh the getNaam() method,
* the compiler will simply say there isn't such a method !
**/
private void toonNamen() {
int i;
for (i=0 ; i<modellen.size() ; i++)
{
System.out.println(modellen.get(i));
}
}
public void toonGegevens() {
}
}
Maybe there is a very simple solution to it, but i just cant see it.>