reset password
Author Message
alalas
Posts: 9
Posted 06:55 Sep 23, 2017 |

I understand that we aren't suppose to give a String as an address within the subclasses of Person (Student and Faculty), however after many attempts to create an object that would "deliver" the address to the subclass nothing seems to be working? Is there something I'm doing wrong, or am I reading the lab incorrectly? I really would like to know what I am doing wrong so I can fix my understanding of this concept.

To my understanding, what we're trying to do is substitute the direct pathway of a String to the class by using an Object that would carry over the String of the address instead. Am I incorrect in the way of thinking this way? If so, I would be more than happy to understand the correct way of thinking so that I can progress and be enlightened of my mistake.

mcmalfaro
Posts: 13
Posted 08:53 Sep 23, 2017 |

To print your string, make your student class extend perosn. Then make sure your person class has a toSting method. Finally wherever you want to print the address, call student.get(i).toString().  You can either use the student or faculty object from your array list. And i is and index. Remember that this will return a string so you can use a system.out.println() or use JOptionPane. 

V_agu30
Posts: 8
Posted 08:55 Sep 23, 2017 |

Use getters and setters. 

Private String stuAddress = "1800 fake St ...";

Public string getStuAd(){

Return stuAddress;}

mcmalfaro
Posts: 13
Posted 09:02 Sep 23, 2017 |

No remember that we have to create a address class. Create a toStrind there with all the variables. Then make your person class extend address. No create a toString methond on your person class as follow. 

public String toString()
	{
		return name+" " + personAddress.toString();
	}
ecabre20
Posts: 5
Posted 11:05 Sep 23, 2017 |

Regarding the same topic: 

If I want to personalize the output in the student class, say for instance instead of having the generic order from the super class, can I also list the parameters in the toString?

I want it to actually say: 

Student name: Mike Rivas, Student CIN#: 0000

does that make sense instead of just 

Mike Rivas, 0000. 

 

Thank you for any input in advance. 

mcmalfaro
Posts: 13
Posted 11:16 Sep 23, 2017 |

I just realize a mistake I made. You don't have to extend address on person class. You have to create an object of the address class instead. I am not sure about personalizing the class but I think you can create a toString methond on student an @override it. Try it. It may work