Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Space Age Calculations Assignment Create a program called <yourLastName>SpaceAge

ID: 3724085 • Letter: S

Question

Space Age Calculations Assignment

Create a program called <yourLastName>SpaceAge.java.

All the input from the user should be from the command line (use the Scanner object). You only need to create one Scanner object to handle all the input.

Do not use JOptionPane.

Mars, the red planet, is visible in the night sky. As you gaze upon it, you might wonder how old you would be if you lived on Mars. Knowing that Mars is further away from the sun, you know that you’d be a much younger person there and you consider filling out an application for Mars One. (They are not accepting any more applications – darn!)

Saturn is also visible in the early evening sky. Saturn is far away, as you recall from the sentence that helped you remember the order of the planets in third grade: My Very Educated Mother Just Sent Us Nine Pizzas. (Pluto is not considered a planet any more - it is a dwarf planet - so no more pizza.) You would probably be a mere infant on Saturn. Venus is also visible in the very early evening sky. But you would be older there, and it is very hot, so that doesn’t seem like a good option.

Now, we realize that planetary age is a relative measurement.   If you were able to somehow be born on Neptune, you’d never live to be a Neptunian year. This doesn’t mean that you’d be crawling around and in diapers your entire life, it simply means that you wouldn’t live (if you were a regular human) to see Neptune take an entire trip around the sun.

Create a program that asks the user to enter their age. Then you will calculate and print the user’s age on the other 8 (we’ll include Pluto) planets.   Each of the calculations should be enclosed in a method. Besides the main method, you will have eight methods, one per planet. Since you are obtaining the user’s age in the main method, you will send that numeric value to all eight methods. Each method will use that value to calculate the user’s age on that particular planet and will print it to standard output. I will not restrict your naming of the methods, but you should name them based on their function. For example, mercuryAge() or printMercuryAge() would be good names.

Note: The entire point of a method is to encapsulate a function. Make sure you are encapsulating the processing, printing, and any information pertinent to the particular planet within the method.

have included the orbital period for all the planets below.

Planet

Orbital Period

Mercury

88 days

Venus

224.7 days

Earth

365.25 days

Mars

687 days

Jupiter

11.86 years

Saturn

29.46 years

Uranus

84 years

Neptune

164.8 years

Pluto

248 years

Planet

Orbital Period

Mercury

88 days

Venus

224.7 days

Earth

365.25 days

Mars

687 days

Jupiter

11.86 years

Saturn

29.46 years

Uranus

84 years

Neptune

164.8 years

Pluto

248 years

Explanation / Answer

The code goes as follows:

JohnSpaceAge.java

import java.util.Scanner;
public class JohnSpaceAge
{
   private static int earthAge;
   private static void mercuryAge(){
       final double orbitalperiod = 88;
       System.out.println("Age in Mercury : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void venusAge(){
       final double orbitalperiod = 224.7;
       System.out.println("Age in Venus : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void marsAge(){
       final double orbitalperiod = 687;
       System.out.println("Age in Mars : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void jupiterAge(){
       final double orbitalperiod = 11.86 * 365.25;
       System.out.println("Age in Juptiter : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void saturnAge(){
       final double orbitalperiod = 29.46 * 365.25;
       System.out.println("Age in Saturn : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void uranusAge(){
       final double orbitalperiod = 84 * 365.25;
       System.out.println("Age in Uranus : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void neptuneAge(){
       final double orbitalperiod = 164.8 * 365.25;
       System.out.println("Age in Neptune : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
   private static void plutoAge(){
       final double orbitalperiod = 248 * 365.25;
       System.out.println("Age in Pluto : " + Math.round(earthAge * 3652500 / orbitalperiod) / 10000.0);
   }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter your age on Earth(years) : ");
        earthAge = sc.nextInt();
        mercuryAge();
        venusAge();
        marsAge();
        jupiterAge();
        saturnAge();
        uranusAge();
        neptuneAge();
        plutoAge();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote