CS 1401, Exam #4, TR version

Date: Thursday, April 24, 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 sunny El Paso, one way to honor Earth Day is to promote the use of solar panels for generating electricity.

1-3. Let us start helping user of solar panels.

  1. Define a class SolarPanel in which each object has two parameters: its power (in Watts) and its cost (in dollars). Include a constructor method, accessor methods, mutator methods, a method that computes and returns cost per unit power, and an appropriate toString method.

  2. In the main method, define a new object of this class that describes the solar panel PW110 that produces 110 Watt of power and whose cost is $569.99; compute and print its cost per Watt (should be approximately $5.18).

  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 area of a solar panel. Define a subclass SolarPanelDetailed of the class SolarPanel which contains a new field: the panel's area in square meters. In the main method, define a new object corresponding to PW110 whose area is 1.0 square meter.






















































5. Write a method that, given an array of objects of type SolarPanel (defined in Problems 1-3), prints the specifications of the best solar panel from this array, i.e., the solar panel with the largest ratio of power per unit cost.
























































6. Friends from sunny Spain sent us a file containing data about Spanish-produced solar panels. Each line of this file contains the panel's area, power, and cost. Write a code that reads this information line by line and places this information into an array of objects of type SolarPanel. Use try-catch block to produce the meaningful error message when the power is 0 or negative.
























































7. To help promote the cause of solar panels, students scanned several papers and placed them on the web, including papers which are protected by copyrights. Is this ethical? Provide two arguments why students may consider this ethical, and two arguments why other people may consider these postings unethical.