## Lab 1: Kepler's Third Law

### Getting The Code / Submission Instructions

Click here to download the .zip file for the skeleton code for this lab. When you are finished, please submit the file Lab1.java, which can be found in the src/ directory of your NetBeans project.

### Description

The purpose of this lab is to get students to practice with declaring variables, declaring constants, and writing mathematical expressions with the proper order of operations, all while writing clean code. Students will write a program that implements Kepler's Third Law, which gives a formula to determine the time of orbit of an object in the solar system given its mass m and the semi-major axis of the ellipse of its orbit (which is roughly its distance to the sun).

Given the mass m of a planet, as well as a, the length of the semi-major axis of its orbit it is possible to determine the length of its orbit, T, with the following formula

## $T = \sqrt{ \frac{4 \pi^2 a^3}{G(M+m)} }$

• The mass of the sun M = 1.989*1030 kg . In scientific notation, this can be written as 1.989e30, and Java will understand that.
• The gravitational constant G = 6.6743015e-11 meters3/(kg*sec2)

You will implement a program to determine the length of a year on a planet (the length of its orbit) in days, given its mass m and its semi-major axis a. The table below shows measured data of all the planets in our solar system, which you will use to check your program
NOTE: The formula may not match exactly, but the year lengths should be close.

 Planet Mass (kg) Semi-major axis (AU) Length of Year (Days) Mercury 3.285 x 1023 kg 0.38710 AU 87.9693 days Venus 4.867 x 1024 kg 0.72333 AU 224.7008 days Earth 5.972 x 1024 kg 1 AU 365.2564 days Mars 6.39 x 1023 1.52366 AU 686.9796 days Jupiter 1.898 x 1027 5.20336 AU 4332.8201 days Saturn 5.683 x 1026 kg 9.53707 AU 10775.599 days Uranus 8.681 x 1025 kg 19.1913 AU 30687.153 days Neptune 1.024 x 1026 kg 30.0690 60190.03 days
Here are some tips for dealing with converting units and writing good code:
• The length of the semi-major axis a is given in astronomical units (AU), or a length of measurement roughly equal to the distance from the earth to the sun. Before you apply the above formula, you will need to convert a to meters by multiplying it by this distance, which is approximately 149,597,870,700 meters.
• The formula above will give the period in seconds, but you will need to convert it to years, so be sure to divide it by the number of seconds in a year (you can write this as an arithmetic expression).
• All constants could be declared as final variables, and they should be in all capital letters.
• PI in Java is Math.PI
• To take a square root of a variable (e.g. x), write Math.sqrt(x)
• To raise a number (e.g. x) to a power (e.g. p), write Math.pow(x, p)
• If you try to implement the above formula all one one line, it will very messy and difficult to debug. Instead, you should split up different parts of the calculation on different lines. For example, you could first compute the value inside of the square root, and then take its square root. Then, you could convert it from seconds into years.