import java.util.*; public class Game { public static void main(String[] args) { final double TRAVEL_SPEED = 10.0; Vector locations = new Vector(); Random rand = new Random(); // create the five locations -- we'll make them stars locations.add (new Location("Geminorum", "sunny", rand.nextInt(100) + 1, rand.nextInt(100) + 1)); locations.add (new Location("Ursae Majoris", "barren", rand.nextInt(100) + 1, rand.nextInt(100) + 1)); locations.add (new Location("Cygni", "colorful", rand.nextInt(100) + 1, rand.nextInt(100) + 1)); locations.add (new Location("Orionis", "tired", rand.nextInt(100) + 1, rand.nextInt(100) + 1)); locations.add (new Location("Andromedae", "exciting", rand.nextInt(100) + 1, rand.nextInt(100) + 1)); // print introductory banner System.out.println("Welcome to CS101 Space Trader v1!"); System.out.println(); System.out.println("You travel at " + TRAVEL_SPEED + " million kilometers per second."); System.out.println(); // set the initial location Location presentLocation = (Location) locations.remove(0); System.out.println("You are starting at " + presentLocation.getAppearance() + " " + presentLocation); double totalDistanceTraveled = 0.0; // now loop through the remaining locations in a random order while (locations.size() > 0) { // Select a random location int nextLocationToTravelTo = rand.nextInt(locations.size()); Location nextLocation = (Location) locations.remove(nextLocationToTravelTo); double distance = presentLocation.getDistance(nextLocation); // Print out that you are travelling there System.out.println(); System.out.println("You will next travel to " + nextLocation.getAppearance() + " " + nextLocation + "."); System.out.println("This is a distance of " + distance + " million kilometers."); // simulate the actual travel // we travel TRAVEL_SPEED, and our distance is "distance" System.out.print("Traveling..."); System.out.println(" Arrived safely!"); // Update how far we have travelled, and change the location. totalDistanceTraveled += distance; presentLocation = nextLocation; } // trip done! Print out summary. System.out.println(); System.out.println("Congratulations, Space Trader! "); System.out.print("You have successfully visited all 5 "); System.out.println("locations in our game!"); System.out.println("You traveled " + totalDistanceTraveled + " million kilometers."); System.out.print("Take the rest of the day off, "); System.out.println("Space Trader -- you deserve it!"); System.out.println(); } }