CIS-2271 Homework #1: Basic Expressions

Due: Tuesday, September 2, 2014

Read Chapter 2 in the text (chapter 1 is also nice). You can delay reading Section 2.5 on strings until next week.

In your Eclipse create a project for Homework #1 (maybe named Hw01) containing a class with the same name. Fill in the main method as described below.

  1. The gravitational force between two objects is given (approximately) by Newton's Law of Gravity: F = G * m1 * m2 / (d * d). Where G = 6.67384e-11 is the universal gravitational constant. The masses of the two objects, m1 and m2, must be in kilograms, and the distance between them, d, must be in meters. The resulting force is then in newtons.

    Write a program that accepts your weight in pounds, a friend's weight in pounds, and the distance between you in feet. It should output the gravitational force between you and your friend in ounces. HINT: You might need to use the %e format specifier with printf. The %f specifier might only print out zero if the result is too small to otherwise display.

    To convert from pounds of weight to kilograms of mass multiply by 0.45359. To convert from feet to meters multiply by 0.3048. To convert from newtons to ounces multiply by 3.5969.

Be sure to include your name in comments in your program. Be sure to add comments that explain what the different parts of your program are doing (they can be short comments, this isn't a long program). Submit your source file to Moodle.

Last Revised: 2014-08-26
© Copyright 2014 by Peter C. Chapin <>