Homework 4


Distance Conversion (50 PTS) 1. You need to create a class along with a test GUI that will allow a user to convert kilometers to miles, yards, feet and inches.

  • you need just one text field for input
  • you need one command button which the user will press because we will assume their input is in kilometers
  • you want to convert the distance so that it reflects
    • miles (integer)
    • yards (integer)
    • feet (integer)
    • inches (float)
  • so you will need four text fields for output

You can choose to approach this problem in one of two ways.

  • For example, you want to make certain your code converts something like 10 kilometers into as many miles as it contains first ... likely to be 6 miles ... then converts the remainder to yards ... the remainder to feet ... then the remainder to inches.  You want to make certain the number of miles, yards and feet are all integers.
  • You can convert the kilometers to
    • miles
    • yards
    • feet
    • inches

so that you are not looking at the remainders and working with all doubles.

You also need to have helpful error trapping and input validation.


Working with Complex Numbers  (50 PTS Total) (Problem 8.2 P440) 2.  Create a class called Complex for performing arithmetic with complex number.  You will also need to write a driver program to test your class along with a GUI. 

Use the instance variable and method names that are provided within this problem statement.

  • Use integer variables to represent the private instance variables of the class - the realPart and imaginaryPart.
  • Assume the realPart and imaginaryPart can be real numbers.
  • Provide a constructor method that enables an object of this class to be initialized when it is declared.  
  • Make sure there is a no-argument constructor with default values in case no initializers are provided.

Provide public methods for each of the following.

  1. Addition of two Complex numbers.
  2. Subtraction of two Complex numbers.
  3. Multiplication of two Complex numbers.
  4. Develop a toString( ) method for Complex numbers in the form a + bi , where a is the realPart and b is the imaginaryPart.

You also need to provide for input validation and appropriate error messages.