Question: Please help, Java Objectives 1. (10 points) Write the constructors for Shape class with the required parameters, which will allow setting up class variables for
Please help, Java



Objectives 1. (10 points) Write the constructors for Shape class with the required parameters, which will allow setting up class variables for each instance and separate the data of each shape 2. (10points) Writethelogic for methodgetArea( which willreturn the calculated area of the specific shape 3. (10points) Construct the object for Shape class in the driver class with respect to the inputfrom the user. If the user enter circle, object shape class will be created for circle. 4. (10 points) Write the mutator methods for Shape class and call one mutator method to change the parameters of the shape 5. (5 points) Write the body of toString 0 method to display the details of the specific shape 6. (5 points) Use meaningful variable names, consistent indentation, and whitespace to make your code readable. Add comments to explain the overall steps of your program. Description The Universal Modeling Language (UML) is a tool used by software engineers to graphically represent the way software is designed. UML has many ways of representing software, but in this course, we will learn about just one: the class diagram. A UML class diagram represents a class as a rectangle with three compartments. The top compartment contains the class name, the middle compartment contains the class fields (the data associated with the class and its objects), and the bottom compartment contains the class methods (constructors, accessors, and mutators). In this project, we will practice translating a class diagram into code. The diagram for a class named "Shape" is given on the following page. You will write an implementation of this class. After writing the Shape class, we will write a second class named "Driver" that contains the main method. The Driver class will take input from keyboard to perform the required calculations. If keyboard input for shape name is circle, then radius will be required as dimensions for the shape. With the value of radius, area of circle will be calculated. You need to declare and construct the object for Shape class in the Driver class. You will use accessor and mutator methods to set the dimensions of the shape and to get the area of the specific shape. Please read the UML diagram carefully to understand the Shape Class variables, parameters, and return type of the methods. UML Class Diagram: 'The class diagram for the class Shape is shown below. Note that the data type of each field and parameter appears after the identifier and it's separated by semi-colon. Similarly, the return type of each method is shown after the identifier and parameter list. For example, setSideOne(i: int): boolean, this represents method setSideOne where i is the parameter of int data type and boolean is the return type. In this project, we will be implementing two classes, Shape and Driver, and calculate area of different shapes with different dimensions from keyboard input. In this program, we will be calculating area for circle, rectangle, and triangle. The constructors define which type of shape is defined. As, for circle, only radius is required, but for rectangle you would need width and height. All the method in the shape class is non-static method. To use accessor and mutator methods, you need to create object of the Shape class in Driver class. Below are the formulas, you will be using to compute the area: Area of circle =r2 Area of rectangle = height width Area of Triangle = We will be using Heron's formula, where area of triangle with sides as a, b, and c can be calculated as: Sqrt(s(sa)(sb)(sc)) Where, s=(a+b+c)/2 Shape Class: Shape class consists of three definitions for constructor, which will take different sets of argument as input. Each constructor defines a type of Shape. Constructor for circle will only have one parameter, for rectangle, two parameters, and for triangle, three parameters. By understanding UML diagram, you need to update the Shape class. 3 getArea0 method is the accessor method, which will use the instance data to compute the area of specific shape. setSideOne 0 method is one of the mutator method, which will update the data of existing object. For setSideTwo0 method, you can update the instance data only if the shape is rectangle or triangle and for setSideThree 0 method, you can update the instance data only if the shape is triangle. The toString method will return the String of specific instance as below: Area of Triangle: 43.44 Driver Class: Starting with this project, our program will consist of two classes. The Driver class will include main method that runs this program. We have provided the starters code. This class (Driver) is designed like our previous programs have been-with no instance data. Driver class should have the following, to be able to test Shape class properly: - You will construct different objects of Shape class, one for Circle, one for Triangle and one for Rectangle. Use these specific objects to calculate the area of these shapes. - Use the mutator method to update the existing object and compute the area of the shape again. - Use toString0 method to display the information. Sample run from the Driver class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
