mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'use-config-file-to-load-boats' into 'master'
Added method to create the race with names from the config file - # implement See merge request !5
This commit is contained in:
@@ -1,19 +1,56 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
|
public static Race createRace(int numberOfBoats) throws Exception{
|
||||||
|
Race race = new Race();
|
||||||
|
|
||||||
|
// Read team names from file
|
||||||
|
FileParser fp = new FileParser("src/test/java/seng302/valid.json");
|
||||||
|
ArrayList<String> boatNames = fp.getTeams();
|
||||||
|
|
||||||
|
// Shuffle team names
|
||||||
|
long seed = System.nanoTime();
|
||||||
|
Collections.shuffle(boatNames, new Random(seed));
|
||||||
|
|
||||||
|
if (numberOfBoats > Array.getLength(boatNames.toArray())){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < numberOfBoats; i++) {
|
||||||
|
race.addBoat(new Boat(boatNames.get(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return race;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
Race race = new Race();
|
Race race = null;
|
||||||
race.addBoat(new Boat("Team 1"));
|
|
||||||
race.addBoat(new Boat("Team 2"));
|
|
||||||
|
|
||||||
|
try{
|
||||||
|
race = createRace(2);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (race != null){
|
||||||
race.displayStartingBoats();
|
race.displayStartingBoats();
|
||||||
|
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
|
|
||||||
race.displayFinishingOrder();
|
race.displayFinishingOrder();
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
System.out.println("e");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user