CS 1401, Exam #4, MWF version

Date: Friday, April 25, 2008
Name (please type legibly, ideally in block letters): ______________________________________________________________________

This week, we honor the Earth Day. According to the US Government website, Earth Day "is a time to celebrate gains we have made and create new visions to accelerate environmental progress". In El Paso where winds are frequent, one way to honor Earth Day is to promote the use of wind turbines for generating electricity.

1-3. Let us start helping user of wind turbins.

  1. Define a class WindTurbine in which each object has two parameters: its height (in meters) and its power (in Watts). Include a constructor method, accessor methods, mutator methods, a method that computes and returns its height in feet, and an appropriate toString method. Reminder: 1 ft = 0.3048 m.

  2. In the main method, define a new object A of this class that describes the wind turbine whose height is 30 meters that produces 5,000 Watt of power; compute and print its height in feet (should be approximately 100 feet).

  3. Trace your code from Problem 2 step-by-step.
































4. When we defined our class in Problems 1-3, we did not include an important characteristic: the cost of a wind turbine. Define a subclass WindTurbineWithCost of the class WindTurbine which contains a new field: the turbine's cost in dollars. In the main method, define a new object corresponding to the turbine A whose cost is $6,000.00.






















































5. Write a method that, given an array of objects of type WondTurbineWithCost (defined in Problems 1-4), prints the specifications of the cheapest wind turbine from this array.

























































6. Let us save the data about wind turbines which is currently stored in an array of objects of type WindTurbine. Write a code that writes all this data into a file line by line, so that the data about each wind turbine is placed into a separate line. In some cases, the users who typed the values into an array may have made a mistake and entered height in feet instead of the height in meters. Use try-catch block to produce the meaningful error message when the height is 40 meters or larger.






















































7. To help promote the cause of wind turbines and renewable energy, a group of activists hacked into the oil companies computers and brought the oil production to a halt. Provide two arguments why activists may consider such behavior ethical, and two arguments why other people may consider this behavior unethical.