COSC 135 B Programming Assignment 5
Due Monday 10-23-00

You may work together on this assignment.

  1. In a file named Roots.java, write a solution to chapter 5 programming problem 5 on page 111 of the text. Not, the GUI design is now up to you. Make sure a user knows what the program does and how to run it! A quadratic equation has the form a*x^2 + b*x + c, where a != 0. The roots or solutions to this equation have the form
x = [-b + sqrt( b^2 - 4ac) ] / (2a) and x = [-b - sqrt( b^2 - 4ac) ] / (2a).
The quantity inside the squareroot, namely b^2 - 4ac is called the descriminant. The descriminant, say d, determines the form and number of real solutions (or roots) as follows:
    1. When d = 0, there is only one real root (namely x = -b / (2a) ) and this root is called a double root.
    2. When d > 0, there are two different real solutions.
    3. When d < 0, there are no real solutions (both solutions are complex).
    Your program should handle the cases where a, b and c are integers. You must write a method called discriminant that takes in the integers a, b, and c and returns the value (a double) of the discriminant. Make a GUI that clearly indicates the problem, and provides fields for the user to enter the integers a, b and c.
  1. In a file called PerfectNumbers.java, write a solution to problem 7 in chapter 5 of the text. A perfect number is a positive integer N such that the sum of the proper divisors of  N is equal to N. For example, N = 28 is a perfect number since the proper divisors of 28 are 1, 2, 4, 7, and 14, and 1 + 2 + 4 + 7 + 14 = 28. When the sum of the proper divisors of N is less than N, the number N is called deficient. When the sum exceeds N, the number is called abundant. Your program should take a positive integer N as input and use a messageBox to display a message stating that the number is perfect, deficient or abundant. You must define the following two methods:
    1. boolean isDivisior( int number, int divisor) which returns true whenever the second parameter is a divisor of the first parameter, and false otherwise.
    2. int divisorSum( int number) that returns the sum of all proper divisors of the input parameter.

    You should design and test your code incrementally, testing each piece as it is created, rather than writing all the code and then trying to test it all together.


  2.