Question: Write a Java program using good object-oriented programming principles that will demonstrate the use of multiple classes. main() will become a list of the static

Write a Java program using good object-oriented programming principles that will demonstrate the use of multiple classes.

main() will become a list of the static and class methods to execute.

In main():

  • prompt the user using a menu that will ask if the user would like to calculate the area of a circle, a rectangle, or a triangle. (Advanced students: feel free to use an ellipse, trapezoid, cylinder, etc...choose 3 other shapes)
  • be sure to test for valid input from the menu selection and allow the user additional attempts if invalid input is entered.
  • for the shape selected:
    • call the static methods that will prompt and read in necessary values. Call static method(s) to validate all input values. If invalid input found, allow the user to input repeatedly as necessary.
    • instantiate an object of the shape (if circle selected, instantiate an object of class Circle, for example)
    • calculate and display the area from the object's class

For each shape's class:

  • create private members setting PI to 3.14159 where appropriate
  • create default constructors that sets the private member to 0.0 and overloaded constructors that sets private members to the user input value(s)
  • create mutator and accessor methods for each private member
  • create methods to calculate and return the area of the shape

Formulas:

Area of a circle = PI x radius2

Area of a rectangle = length x width

Area of a triangle = base x height / 2

Be sure to:

  • validate all user input values
  • use units of measurement when prompting for input data and displaying output
  • make PI a constant variable
  • use the this keyword where appropriate
  • all output values are set to 2 decimal places
  • create a .java file for each class for a total of 4 .java files when the project is complete

To Do:

  1. Zip the entire contents of your project folder together and upload your .zip file to the Project 4 Drop Box.
  2. Check the Calendar for the due date!
  3. Be sure to use the template code (the file called template code under the Eclipse module in Canvas).
  4. Check the rubrics to see how your project will be graded.

NOTE: Any submitted project that has all code written in main() and/or does not use a class/object to call mutator and accessor methods will result in a submission grade of 0.

Item
Program runs without errors.
Program code is commented throughout.
Template code is used and placed at the top of the source file.
Program is written using good object-oriented principles.
Program displays a menu prompting the user to choose a shape.

Depending on the shape selected, the program prompts for input for dimensions needed:

  • circle prompts for radius
  • rectangle prompts for length and width
  • triangle prompts for base and height
All input values (menu selection and dimensions) are validated for values less than or equal to 0. If invalid data entered, the user is given an error message and prompted to try entering input again.
All values are displayed with units of measurement (inches, cm, etc...)
Each shape has their own class and own .java file. A total of 4 .java files are submitted.
The value of PI is set as a constant and as 3.14159
Static methods are used to prompt the user for input and to validate input values
All methods complete one task only.
The object of a class is instantiated and used appropriately
Default and overloaded constructors are used in all the shape classes
Appropriate mutator and accessor methods are created and used
Area calculations are correct
Output values are displayed with 2 decimal places
The output displayed is correct.
A title and ending statement are added as shown in the example in the specifications.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!