Java TOPIC 29 – FUNCTIONS & OBJECTS LESSON WORK QUESTION 1
– MIDDLE OF RECTANGLE
QUESTION 2 – SCALED CIRCLE Write a function that gets a Circle object as
parameter as well and a double variable called scale. The functions returns
a new circle with the new scale.
Students will have to create a Circle class before starting. QUESTION 3 – GLASSES Consider the following Glass class that represents
a normal cylindrical glass that you can drink out of. public class Glass { public double radius; public double height; public String contents; public double percentFull; //0.50 = 50%
full } //1.00 =
100% full
In the main function of class called Tester,
create two different glass objects.
The first, named glass1 has a radium of 4cm and a height of 12cm. It contains “water” and is 80% full. The second glass object is named glass2 and
has a radius of 3cm and a height 16cm.
It also contains “water” and is 90% full. PART
2 Still in the class Tester, write a function called
volumeOfGlass that gets a glass object and returns
the total volume for that glass. Test
your function. Again in the class Tester, write a function called
remainingRoom that gets a glass object and returns
the unused volume left in the glass. Note
that you might want to use your previously created functions to help
you. Test your function. PART
5 Back in the main function, create a third glass. Its name is dglass
which is short for destination glass.
It has a radius of 6cm and the height 18cm. It is empty. PART
6 |
|