Java I CS 142 Week 06 Assignment.docx

advertisement
Java I CS 142 Week 06 Assignment
This program will use methods and classes. You will submit three files:
1. Week06.java – containing the main program (in a class named Week06)
2. Circle.java – containing the Circle class
3. Trapezoid.java – containing the Trapezoid class
Your main program should:
1. Display your name and the assignment (“Week06”) for ease while I’m grading
2. Have your name in a comment in the first line of the file.
3. Have a loop which:
a. Asks the user whether a new object is to be a “Circle”, a “Trapezoid”, or “Done”.
b. Exit the loop if the user enters “Done”.
c. (all comparisons should be case-insensitive)
d. Then asks the user relevant information about the object:
i. If a Circle, ask the user for radius
ii. If a Trapezoid, ask the user base1, base2, and height
e. Create an instance of the object using a constructor.
f. Determine the area of the object using a method named “.getArea()”
g. Display the area
h. If the object is a Circle, display the circumference and diameter.
4. When done with the loop, the program should display a count of how many objects were
created, the number of Trapezoids and Circles, and the total of all the areas. It should use the
static methods described below to get the counts.
The Circle class should:
1.
2.
3.
4.
5.
6.
7.
8.
9.
Have a double field (radius)
Have one static int field to keep track of how many have been created.
Have your name in a comment as the first line of the file.
Have a constructor that accepts a single argument: radius.
Have a set and a get for radius named setRadius and getRadius, respectively.
Have a method named getArea() which returns a double, the area of the circle.
Have a method named getDiameter(), which returns the diameter of the circle.
Have a method named getCircumference(), which returns the circumference of the circle.
Have a static method named getHowManyCircles(), which should return, as an int, the number
of circles created.
The Trapezoid class should:
1. Have three double fields (base1, base2, and height)
2. Have one static int field to keep track of how many have been created.
3.
4.
5.
6.
7.
Have your name in a comment as the first line of the file.
Have a constructor which accepts three double arguments in the above order.
Have set and get methods: setBase1, getBase1, setBase2, getBase2, setHeight and getHeight
Have a method named getArea(), which returns a double, the area of the trapezoid.
Have a static method named getHowManyTrapezoids(), which should return, as an int, the
number of trapezoids created.
Note: even though your test program may not use all the sets and gets, I will have a test program that
will!
The three files should be submitted to the drop box. It is set up to accept multiple files.
The assignment is due at noon, Sunday, February 12th. As always, up to a week late will be accepted,
albeit with small penalty. 
Sample output from my version:
Week 06 programming assignment for Dave
Enter 'Circle', 'Trapezoid', or 'Done':
Enter radius: 7.5
Area is: 176.7145867644257
Diameter is: 15.0
Circumference is: 47.12388980384685
Enter 'Circle', 'Trapezoid', or 'Done':
Enter base1: 4.5
Enter base2: 7
Enter height: 9.2
Area is: 52.9
Enter 'Circle', 'Trapezoid', or 'Done':
There were 2 figures.
The total area was 229.6145867644257
Straayer
Circle
Trapezoid
Done
Download