Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class FantasySolarSystem {
- static final String msg1 = "Enter name: "; // Constants used for the strings that prompt the user
- static final String msg2 = "Enter the name of the solar system: ";
- static final String msg3 = "Now enter planet names - type 'done' to finish";
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in); // Creates a new scanner
- Random rnd = new Random(); // Creates a new randon
- System.out.println(msg2);
- String systemName = input.nextLine();
- SolarSystem fantasySystem = new SolarSystem(systemName); // Creates a new SolarSystem object
- System.out.println(msg3);
- System.out.println(msg1);
- String planetName = input.next(); // Reads in input
- while (!(planetName.equals("done"))) { // Checks if next input equals "done" and terminates loop when it does
- double mass = rnd.nextDouble() * 300; // Creates random values for mass and distance in the range 40 and 50 respectively
- double distance = rnd.nextDouble() * 40;
- fantasySystem.addPlanet(planetName, mass, distance); // Adds planet to fantasySystem object
- System.out.println(msg1);
- planetName = input.next();
- }
- System.out.println(fantasySystem.toTable()); // Prints the table of planet information
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement