CS256: Lab 1


Due: See Moodle for the due date and time

Goals:

1)    Become familiar with the JGrasp Integrated Development Environment (IDE)

2)    Write executable java code that you can run and test.

Requirements:

0)  Create a folder named lab1 in your cs256 folder.

1)  Include your name in a comment at the top of each java file you write.  Files without your name in a comment at the top of the file are an automatic 2 point deduction.

2)    Write, compile, and test a class named SphereVolume  to input a radius and then calculate the volume of the corresponding sphere.  The formula is vol = 4.0/3.0 π r (cubed).  Hint: The value for π is stored inside a class that comes with the java language.  Type Math.PI at the point in the expression that you want to reference the value πr (cubed) means r * r * r.  When you type in the formula, be sure to use 4.0, not 4. 

3)    Write and test a class named EnglishToMetric that can be used to convert a weight in the English pound system to an equivalent weight in the metric kilogram system.  There are 2.2 lb in 1 kg.

4)    Write and test a class named FahrenheitToCelsius that can be used to convert Fahrenheit temperatures to Celcius.  The formula is: 5.0(f-32)/9 = c.

5) In the comment at the top of your code below your name, write short answers to the following synthesis questions:

·         What is the purpose of a variable declaration?

·         What happens when a variable assignment is executed?

·         What does the ‘.’ In Math.PI tell the compiler to do?

·       In the formula in problem 1, what happens if you use the expression 4/3 rather than 4.0/3.0?  Why?

Missing synthesis question answers is an automatic 10 point deduction.

6)    Make a zip file of your entire lab1 directory and submit this file on moodle.

 

Approach:

1)    Create the directory P:\CS256\lab1

2)    Save ../demos/TextIO.java to P:\CS256\lab1

3)    Understand each problem by coming up with tests that will demonstrate that your program does what it is required to do, e.g.,

4)    With a radius of 1, the volume of a sphere is about (4 * 3.14159 * 1) / 3, which is very close to 4.1887867.  How about 0?  What other radii should you test?  Negative?  (You are not required to handle negative inputs in this lab.)

5)    When finished, you should have 3 java source files in the same directory: SphereVolume.java, EnglishToMetric.java, and FahrenheitToCelsius.java

 

Hints:

·         Start with TrapezoidArea.java, which you wrote in class, or download ../demos/W01N02.java to your lab1 directory and run it before starting.  Then use it as a template for producing the lab programs.