next up previous
Up: APS105 Home

APS 105 - Computer Fundamentals

Lab #3: Methods

Fall 2000

You must submit this lab by 11:59pm Wednesday, October 4.


Objective
In this lab you will learn to write Java methods.


Part 1 -- Void Methods
In Java, not all methods return values. Those that do not are called void methods. An example of a void method is System.out.print(). You are to write a void method named printDouble() that takes two parameters. The first parameter is of type double, and is the value to be printed. The second parameter is of type byte, and indicates the number of decimal places to show when printing the value. Write a short program to demonstrate the use of your method. You may find it helpful to look at the example on p.44 of John Carter's notes.


Part 2 -- Boolean Methods

A perfect number is a positive integer for which the sum of the positive divisors less than the number is equal to the number itself. As an example, the number 28 is perfect because 1, 2, 4, 7, and 14 are the divisors and 1 + 2 + 4 + 7 + 14 = 28. Write a boolean-valued Java method isPerfect that takes an integer n as a parameter and returns true only if n is perfect.


Part 3 -- Triangles (Again!)

Create a file named Triangle.java containing a class named Triangle implement the following static methods:

     public static boolean isIsosceles(int a, int b, int c)

     public static boolean isEquilateral(int a, int b, int c)

     public static boolean isScalene(int a, int b, int c)

     public static boolean isRight(int a, int b, int c)

     public static boolean isObtuse(int a, int b, int c)

     public static boolean isAcute(int a, int b, int c)

     public static double area(int a, int b, int c)

     public static double angle(int a, int b, int c)

     public static int perimeter(int a, int b, int c)

The purpose of all of these methods should be clear from their identifiers with the exception of the method called angle. That method returns the magnitude, in radians, of the angle opposite the side whose length is given by a. For all of these methods, the parameters are the lengths of sides of a triangle. You may assume that the values of the parameters are valid -- no checking for valid values need be done.

In a file named Lab2Again.java, using a class name Lab2Again, re-write the program from Lab 2 using the methods implemented above. Note: the file Triangle.java must not contain a main() method.


What to Submit

Submit the files Triangle.java and Lab2Again.java from Part 3. We will test your methods using our own program, so it is important you adhere exactly to the descriptions given above.


next up previous
Up: APS105 Home
Guy G. Lemieux
2000-09-26