Advertisement
Guest User

1

a guest
Nov 28th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3.  
  4. public class FantasySolarSystem {
  5.  
  6.     static final String msg1 = "Enter name: ";  // Constants used for the strings that prompt the user
  7.     static final String msg2 = "Enter the name of the solar system: ";
  8.     static final String msg3 = "Now enter planet names - type 'done' to finish";
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         Scanner input = new Scanner(System.in); // Creates a new scanner
  13.         Random rnd = new Random(); // Creates a new randon
  14.  
  15.         System.out.println(msg2);
  16.         String systemName = input.nextLine();
  17.         SolarSystem fantasySystem = new SolarSystem(systemName); // Creates a new SolarSystem object
  18.         System.out.println(msg3);
  19.         System.out.println(msg1);
  20.         String planetName = input.next(); // Reads in input
  21.  
  22.         while (!(planetName.equals("done"))) { // Checks if next input equals "done" and terminates loop when it does
  23.             double mass = rnd.nextDouble() * 300; // Creates random values for mass and distance in the range 40 and 50 respectively
  24.             double distance = rnd.nextDouble() * 40;
  25.             fantasySystem.addPlanet(planetName, mass, distance); // Adds planet to fantasySystem object
  26.             System.out.println(msg1);
  27.             planetName = input.next();
  28.         }
  29.         System.out.println(fantasySystem.toTable()); // Prints the table of planet information 
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement