Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. package no.hiof.sadaqmd.oblig3;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Star theSun = new Star("Sun", 695700, 1.98892E30, 5777);
  7.  
  8. PlanetSystem solarSystem = new PlanetSystem("Solar System", theSun);
  9.  
  10. // Instansierer og legger planetene direkte til i planetsystemet
  11. solarSystem.addPlanet(new Planet("Mercury", 3.283E23, 2439.7, 0.387, 0.206, 88, theSun));
  12. solarSystem.addPlanet(new Planet("Venus", 4.867E24, 6051.8, 0.723, 0.007, 225, theSun));
  13. solarSystem.addPlanet(new Planet("Earth", 5.972E24, 6371, 1, 0.017, 365, theSun));
  14. solarSystem.addPlanet(new Planet("Mars", 6.39E23, 3389.5, 1.524, 0.093, 687, theSun));
  15. solarSystem.addPlanet(new Planet("Jupiter", 1.898E27, 71492, 5.20440, 0.049, 4380, theSun));
  16. solarSystem.addPlanet(new Planet("Saturn", 5.683E26, 58232, 9.5826, 0.057, 10585, theSun));
  17. solarSystem.addPlanet(new Planet("Uranus", 8.681E25, 25362, 19.2184, 0.046, 30660, theSun));
  18. solarSystem.addPlanet(new Planet("Neptune", 1.024E26, 24622, 30.11, 0.010, 60225, theSun));
  19.  
  20. System.out.println(solarSystem);
  21.  
  22.  
  23. // Henter ut en referanse til hver planet
  24. Planet mercury = solarSystem.getPlanets().get(0);
  25. Planet venus = solarSystem.getPlanets().get(1);
  26. Planet earth = solarSystem.getPlanets().get(2);
  27. Planet mars = solarSystem.getPlanets().get(3);
  28. Planet jupiter = solarSystem.getPlanets().get(4);
  29. Planet saturn = solarSystem.getPlanets().get(5);
  30. Planet uranus = solarSystem.getPlanets().get(5);
  31. Planet neptune = solarSystem.getPlanets().get(7);
  32. System.out.println("-----Oppgave 2.5----");
  33. System.out.println(mars.distanceToCentralBody(180));
  34.  
  35. System.out.println("First planet: " + mercury);
  36. System.out.println("Third planet: " + earth);
  37.  
  38. System.out.println(solarSystem.getPlanetByName("Earth"));
  39. /*
  40. System.out.println(String.format("%s has a Jupiter Mass of %f and a Jupiter Radius of %f", saturn.getName(), saturn.getMassInMjup(), saturn.getRadiusInRjup()));
  41.  
  42. System.out.println(String.format("%s has a Solar Mass of %f and a Solar Radius of %f ", theSun.getName(), theSun.getMassInMsun(), theSun.getReadiusInRsun()));
  43.  
  44. System.out.println(String.format("%s has a Earth Mass of %f and a Earth Radius of %f ", mars.getName(), mars.getMassInMearth(), mars.getRadiusInRearth()));
  45.  
  46. System.out.println("The surface gravity of " + earth.getName() + " is " + earth.getSurfaceGravity());
  47. System.out.println("The surface gravity of " + neptune.getName() + " is " + neptune.getSurfaceGravity());
  48. */
  49. Planet smallestPlanet = solarSystem.getSmallestPlanet();
  50. Planet largestPlanet = solarSystem.getLargestPlanet();
  51.  
  52. System.out.println(smallestPlanet.getName() + " is the smallest planet in the " + solarSystem.getName());
  53. System.out.println(largestPlanet.getName() + " is the largest planet in the " + solarSystem.getName());
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement