Problem 4 Consider the information in the following table (note Pluto is include
ID: 3863988 • Letter: P
Question
Problem 4 Consider the information in the following table (note Pluto is included even though it has been downgraded from planetary status) MERCURY VENUS EARTH MARS JUPITER SATURN URANUS NEPTUNE PLUTO Mass (1024kg) 0.642 1898 0.0146 Diameter (km) 4879 12104 12756 6792 142984 120536 51118 49528 2370 Density (kg/m 3) 5427 5243 5514 3933 1326 687 1271 1638 2095 Gravity (m/sA 2) 3.7 8.9 9.8 3.7 23.1 9 8.7 11 0.7 43 10.4 11.2 5 59.5 35.5 21.3 23.5 1.3 Escape Velocity (km/s) 1407.6 -5832.5 23.9 24.6 9.9 10.7 -17.2 16.1 -153.3 Rotation Period(hours) Length of Day (hours) 4222.6 2802 24 24.7 9.9 10.7 17.2 16.1 153.3 Distance from Sun(106km) 57.9 108.2 149.6 227.9 778.6 1433.5 2872.5 4495.1 5906.4 46 107.5 147.1 206.6 7405 1352.6 2741.3 4444.5 4436.8 Perihelion (106km). Aphelion (106km) 69.8 108.9 152.1 249.2 816.6 1514.5 3003.6 4545.7 7375.9 88 224.7 365.2 687 4331 10747 30589 59800 90560 Orbital Period(days) orbital velocity (km/s) orbital Inclination (degrees) 7 3.4 o 1.9 1.3 2.5 0.8 1.8 17.2 orbital Eccentricity 0.205 0.007 0.017 0.094 0.049 0.057 0.046 0.011 0.244 obliquity to orbit degrees) 0.01 177.4 23.4 25.2 3.1 26.7 97.8 28.3 122.5 464 15 -65 110 -140 -195 -200 -225 167 Mean Temperature(C) o 92 1 0.01 Unknown Unknown Unknown Unknown o Surface Pressure (bars) o 0 1 2 67 62 27 14 5 Number of Moons No No No No Yes Yes Yes Yes No Ring System? Yes No Yes No Yes Yes Yes Yes Unknown Global Magnetic Field? which is taken from http://nssdc.gsfc.nasa.gov/planetary/factsheet/ The symbol A denotes to the power of 24 e.g. 10A24 means 10Explanation / Answer
input:-
---------
planets.txt:-
lable MERCURY VENUS EARTH MARS JUPITER SATURN URANUS NEPTUNE PLUTO
Mass(10^24kg) 0.33 5. 6. 0.642 1898 568 87. 102 0.0146
Diameter(km) 4879 12104 12756 6792 142984 120536 51118 49528 2370
Density(kg/m8) 5427 5243 5514 3933 1326 687 1271 1638 2095
Gravity( m/sA2) 4. 9. 10. 4. 23. 9 9. 11 0.7
Escape Velocity(km/s) 4. 10. 11. 5 60. 36. 21. 24. 1.
Rotation Period(hours) 1408. -5833. 24. 25. 10. 11. -17. 16. -153.
Length of Day(hours) 4223. 2802 24 25. 10. 11. 17. 16. 153.
Distance from Sun(106km) 58. 108. 150. 228. 779. 1434. 2873. 4495. 5906.
Perihelion(106km) 46 108. 147. 207. 741. 1353. 2741. 4445. 4437.
Aphelion(106km) 70. 109. 152. 249. 817. 1515. 3004. 4546. 7376.
Orbital Period(days) 88 225. 365. 687 4331 10747 30589 59800 90560
Orbital Velocity(km/s) 47. 35 30. 24. 13. 10. 7. 5. 5.
Orbital Inclination(degrees) 7 3. 0 2. 1. 3. 0.8 2. 17.
Orbital Eccentricity 0.205 0.007 0.017 0.094 0.049 0.057 0.046 0.011 0.244
Obliquity to Orbit(degrees) 0.01 177. 23. 25. 3. 27. 98. 28. 123.
Mean Temperature(C) 167 464 15 -65 -110 -140 -195 -200 -225
Surface Pressure(bars) 0 92 1 0.01 Unknown Unknown Unknown Unknown 0
Number of Moons 0 0 1 2 67 62 27 14 5
Ring System? No No No No Yes Yes Yes Yes No
Global Magnetic Field? Yes No Yes No Yes Yes Yes Yes Unknown
Program to read the above input and generate sorted planets based on density:-
------------------------------------------------------------------------------------------------------------------
package chegg;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Planets {
public static void main(String[] args) {
String inputFile = "/chegg/planets.txt";
BufferedReader br = null;
String line = "";
String delimiter = " ";
String a[];
try {
br = new BufferedReader(new FileReader(inputFile));
while ((line = br.readLine()) != null) {
// use tab as separator
a[] = line.split(delimiter);
if(a[1]=="Density(kg/m8)")
{
for (int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] < a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;PrintWriter pw = new PrintWriter(new File("sortedPlanets.csv"));
StringBuilder sb = new StringBuilder();
sb.append(a[i]);
}
}
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
output:-
--------
sortedPlanets.csv
lable,MERCURY,VENUS,EARTH,MARS,JUPITER,SATURN,URANUS,NEPTUNE,PLUTO
Mass(10^24kg),0.33,5.,6.,0.642,1898,568,87.,102,0.0146
Diameter(km),4879,12104,12756,6792,142984,120536,51118,49528,2370
Density(kg/m8),5427,5243,5514,3933,1326,687,1271,1638,2095
Gravity( m/sA2),4.,9.,10.,4.,23.,9,9.,11,0.7
Escape Velocity(km/s),4.,10.,11.,5,60.,36.,21.,24.,1.
Rotation Period(hours),1408.,-5833.,24.,25.,10.,11.,-17.,16.,-153.
Length of Day(hours),4223.,2802,24,25.,10.,11.,17.,16.,153.
Distance from Sun(106km),58.,108.,150.,228.,779.,1434.,2873.,4495.,5906.
Perihelion(106km),46,108.,147.,207.,741.,1353.,2741.,4445.,4437.
Aphelion(106km),70.,109.,152.,249.,817.,1515.,3004.,4546.,7376.
Orbital Period(days),88,225.,365.,687,4331,10747,30589,59800,90560
Orbital Velocity(km/s),47.,35,30.,24.,13.,10.,7.,5.,5.
Orbital Inclination(degrees),7,3.,0,2.,1.,3.,0.8,2.,17.
Orbital Eccentricity,0.205,0.007,0.017,0.094,0.049,0.057,0.046,0.011,0.244
Obliquity to Orbit(degrees),0.01,177.,23.,25.,3.,27.,98.,28.,123.
Mean Temperature(C),167,464,15,-65,-110,-140,-195,-200,-225
Surface Pressure(bars),0,92,1,0.01,Unknown ,Unknown ,Unknown ,Unknown ,0
Number of Moons,0,0,1,2,67,62,27,14,5
Ring System?,No,No,No,No,Yes,Yes,Yes,Yes,No
Global Magnetic Field?,Yes,No,Yes,No,Yes,Yes,Yes,Yes,Unknown
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.