mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
764aac4b7c
- # implement
56 lines
1.1 KiB
Java
56 lines
1.1 KiB
Java
package seng302;
|
|
|
|
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 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 )
|
|
{
|
|
Race race = null;
|
|
|
|
try{
|
|
race = createRace(2);
|
|
|
|
}
|
|
catch (Exception e){
|
|
System.out.println(e);
|
|
}
|
|
|
|
if (race != null){
|
|
race.displayStartingBoats();
|
|
|
|
System.out.println("");
|
|
|
|
race.displayFinishingOrder();
|
|
}
|
|
else{
|
|
System.out.println("e");
|
|
}
|
|
}
|
|
} |