Question: Write a program to determine the surface gravity (g) on a planet in our solar system. Create a new project called 02 Defining New Methods

Write a program to determine the surface gravity (g) on a planet in our solar system.

  1. Create a new project called 02 Defining New Methods in the Mod05Assignments folder.
  2. Create a class called PlanetGravity in the new project folder.
  3. Read the Background section below to learn how to calculate each planet's surface gravity.
  4. Look over the planet data below that contains the diameter and mass of each planet. Be sure to note the units of each value.
  5. Select only one planet, other than Earth, to use in the program. The name of the planet along with its diameter and mass should be declared and initialized into variables in the main() method.
  6. Create 3 static methods to break your program down into functional sections. For each method, think about:
    • What values (parameters), if any, will this method need to perform its task?
    • Does the method need to return data? If it does, what is the data type?
    • Write a method to calculate the surface gravity for the planet. Depending on the accuracy of your information source, calculated values should be reasonably accurate but may vary somewhat. Be sure to double check your units (1 km = 1000 m).
    • Write a method to display just the title output - see the header info in the sample output. (Hint: use the t escape character to format).
    • Write a method to display the planet's data neatly. (Hint: use the t escape character to format).

Note:By displaying the header in a separate method, the method with the planet data can be used to display multiple planets if the need arises in the future. Being able to easily expand a program's scale is why it is important to have functional sections (methods) that do just one task.

Background:Even if you have not taken physics, you have an intuitive understanding of gravity, the force that causes an object to fall when you drop it and keeps us from drifting off into space.

The surface gravity (g) of every planet is different, but can be easily calculated using two basic measurements: the planet's mass (M) and radius (r). If you have taken physics, the following equation will be very familiar. If not, simply look at it arithmetically; itonly involvesmultiplication and division.

The following example shows how to calculate the Earth's surface gravity:


where g is the surface gravity in m/s2, G is the Universal Gravitational Constant, M is the mass of the planet inkilograms, r is the radius of the planet inmeters.


Planet Data:Select one planet below (other than Earth) to work with in your program.

Planet Diameter (km) Mass (kg)
Mercury 4,880 3.30e23
Venus 12,103.6 4.869e24
Earth 12,756.3 5.972e24
Mars 6,794 6.4219e23
Jupiter 142,984 1.900e27
Saturn 120,536 5.68e26
Uranus 51,118 8.683e25
Neptune 49,532 1.0247e26

Step by Step Solution

3.40 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres an example program that calculates the surface gravity on a planet in our solar system java public class PlanetGravity public static void mainSt... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!