Create Software Components 

Using Java Level 2

 

 

Course Info

Scheme

Resources

Tutorials

Java Demos

Utilities

Links


 

 

    Class Exercise

 Operators & Expressions Exercise

 

This exercise should be carried out after reading 

the tutorial on  Operators & Expressions

 

    Exercise 1: Sphere Application

The formula for calculating the volume of a sphere is given by...

V =  43 p r3

Where, V is the volume, r is the radius and p is pi, which you can approximate as 3.141.

 

The formula for calculating the surface area of a sphere is given by...

A =  4 p r2

Where, V is the volume, r is the radius and p is pi, which again you can approximate as 3.141.

 

  1. Write Java code that prints out to the command prompt windows the volume and surface area of a sphere.  Your code should use variables such as V, PI (for p) and r and declare them using appropriate data types.

  2. Check that your program works correctly by getting it to calculate the volume and surface area of a sphere with a radius of 8cm.  You should get an answer of approximately 2150 for the volume and 804 for the surface are.

 

Have fun!

 

 

  Site Home 

Java Home   

  Forum  

Course Info

Welcome

Overview

Assessment

Qualification

Scheme of Work

Assignments

Resources

Information

Blackboard

Learning Center

Web Materials

Reading

Java Demos

Utilities

Links

Lecture Materials

Tutorials & Notes

Exercises

Activities

Quizzes

 

Site Home

Top

Unit Home

ADR 2002