Created
September 6, 2014 04:38
-
-
Save FagnerMartinsBrack/69da19f8bb9c67828770 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.lang.*; | |
public class PersonExecutor { | |
public static void main( String[] arguments ){ | |
Person john = new Person(); | |
Person mike = new Person(); | |
john.setName( "John" ); | |
mike.setName( "Mike" ); | |
Location location = new Location(); | |
location.addPerson( john ); | |
location.addPerson( mike ); | |
System.out.print( location.toString() ); | |
} | |
} | |
class Person { | |
private String name; | |
public void setName( String name ) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
} | |
class Location { | |
private List<Person> persons = new ArrayList<Person>(); | |
public void addPerson( Person person ) { | |
persons.add( person ); | |
} | |
@Override | |
public String toString() { | |
String result = ""; | |
for ( Person person : persons ) { | |
result += person.getName() + " is here\n"; | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment