|
-
January 11th, 2018, 01:23 PM
#1
array split newbie help needed
Hi, I need some help. I have removed seperate add.member sections into one but want to be able to choose between whether student or teacher gets added and not have to input both. I assume I have to use a List Array but I have done a lot of reading and don't know where to start. Any help would be great, am very new to Java. Thanks.
Code:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Committee
{
private String name;
private List<Object> members;
public Committee (String name)
{
this.name = name;
members = new ArrayList<Object>();
}
public void addMember(Student student, Teacher teacher)
{
members.add(student);
members.add(teacher);
}
public void printMembership()
{
System.out.println("Membership of the "+name+" Committee ");
Iterator<Object> it = members.iterator();
while (it.hasNext()) {
Object member = it.next();
System.out.println(member);
}
}
}
Last edited by 2kaud; January 11th, 2018 at 02:43 PM.
Reason: Added code tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|