Program 2 - Barbell

Goal Description Hints Passoff

Due Date - 26 Jan


  • Create a working Java program
  • Get information that the user types in
  • Print out information for the user
  • Do simple arithmetic
  • Create a simple 2D shape based on user input
 CS 142

This program will ask the user for how much weight they want on their barbell. You will need to ask the user for the amount of weight that they want then print out what their answer was. You must then calculate the diameter of the weights that you need. The radius of each wieght should be the number of pounds for each wieght divided by 3.0. Remember there are two weights, one on each end. You should print out the calculated radius.

You should then display a 2D picture of your barbell wieghts of the correct diameter.


Print the following message on the screen

How much weight do you want?  

The user will then type a number that you will read and store in a variable.

Print the following message on the screen

You have asked for PPPP pounds.
Your weights will have radius RRRR.

Your console window should now look like this:


Create a new 2D window

Display the barbell in the window.

It should like approximately like the picture below. The colors you can choose for yourself. I have included axes because it makes it easier to choose sizes but you can leave them out if you want.


  • The documentation for drawing 2D images is found here.
  • The Phun tutorial is here.
  • For examples of how to use nextInt() to get a number see the sample program on page 53 of your text and also ComputeWages.


Do each step one at a time and check the result before going on. Do not try to write the whole thing at once.


__ 1) All code neatly indented

__ 1) Understandable variable names with proper style

__ 2) Radius is correctly calculated and presented

__ 3) An acceptable and realistic barbell appears

__ 1) The radius of the weights changes correctly with different user input