Story 1 completion, Added Boat and Event classes. The program displays two boats New Zealand and America.
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package seng302;
|
||||
|
||||
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Welcome to SENG302" );
|
||||
Boat boat1 = new Boat("New Zealand");
|
||||
Boat boat2 = new Boat("America");
|
||||
Boat[] boats = {boat1, boat2};
|
||||
Event event = new Event(boats);
|
||||
System.out.println(event.getParticipants());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package seng302;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public class Boat {
|
||||
private String name;
|
||||
|
||||
public Boat(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package seng302;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public class Event {
|
||||
private ArrayList<Boat> boats;
|
||||
|
||||
public Event(Boat boats[]){
|
||||
this.boats = new ArrayList<>(Arrays.asList(boats));
|
||||
}
|
||||
|
||||
public String getParticipants(){
|
||||
String participants = "";
|
||||
for (int i = 0; i < boats.size(); i++){
|
||||
participants += boats.get(i).getName()+"\n";
|
||||
}
|
||||
return participants;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user