2) An astronomy application displays information about the eight planets in our
ID: 3602120 • Letter: 2
Question
2) An astronomy application displays information about the eight planets in our solar system. Write the logic for this application in pseudocode:
a. Visit this web page: https://sciencing.com/order-planets-distance-sun- 8371065.html
b. Note down each planet’s name, distance from the sun, and diameter
c. Write the program such that it:
i. Displays a numbered list of the planets that includes
1. Planet number (1 is the planet closest to the sun and 8 is the one farthest from it)
2. Planet’s name
3. Distance from the sun
4. Diameter
Here is a sample of the required format of output: Planet #1: Mercury is 36 million miles from the sun and has a diameter of 3031 miles
ii. Allows the user to enter the number of any planet, and displays output similar to that shown above, for that planet, e.g., if the user entered 1, the output would be the sentence shown above. If the user enters an invalid planet number, such as zero or 9, the program must display an error message
iii. Allows the user to enter the numbers of any two planets, and outputs both their names as well as their distance from each other. If the user enters an invalid planet number, such as zero or 9, the program must display an error message
Note: (ii) and (iii) above must be accomplished without any search being performed
Explanation / Answer
Hi,
As programming language was not mentioned, I have coded the solution in Java.
Below is the code in Java-
import java.util.Scanner;
public class HelloWorld{
public static void main(String []args){
int pnum;
Scanner in =new Scanner(System.in);
System.out.println("Enter the planet number");
pnum=in.nextInt();
if(pnum>=1 &&pnum<=8) {
if(pnum==1)
{
System.out.println("Planet #1: Mercury is 36 million miles from the sun and has a diameter of 3031 miles");
}
if(pnum==2)
{
System.out.println("Planet #2: Venus is 67.2 million miles from the sun and has a diameter of 7521 miles");
}
if(pnum==3)
{
System.out.println("Planet #3: Earth is 93 million miles from the sun and has a diameter of 7926 miles");
}
if(pnum==4)
{
System.out.println("Planet #4: Mars is 483.6 million miles from the sun and has a diameter of 4,222 miles");
}
if(pnum==5)
{
System.out.println("Planet #5: Jupiter is 483.6 million miles from the sun and has a diameter of 88,729 miles");
}
if(pnum==6)
{
System.out.println("Planet #6: Saturn is 886.7 million miles from the sun and has a diameter of 74,600 miles");
}if(pnum==7)
{
System.out.println("Planet #7: Uranus is 1784 million miles from the sun and has a diameter of 32,600 miles");
}if(pnum==8)
{
System.out.println("Planet #8: Neptune is 2,794.4 million miles from the sun and has a diameter of 30,200 miles");
}
}
else
{
System.out.println("The input number is invalid");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.