Question

In: Computer Science

Given the following UML class diagram, implement the class as described by the model. Use your best judgement when implementing the code inside of each method.

In java 

Given the following UML class diagram, implement the class as described by the model. Use your best judgement when implementing the code inside of each method.

+------------------------------+
| Circle |
+------------------------------+
| - radius : double = 1.0 |
+------------------------------+
| + Circle(radius : double) |
| + getRadius() : double |
| + setRadius(radius : double) |
| + area() : double |
| + perimeter() : double |
+------------------------------+

The following information might also be useful:

Formula for area of a circle with radius r:
       A = πr^2

Formula for perimeter of a circle with radius r:
       P = π2r

Solutions

Expert Solution

Below is the JAVA code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

import java.util.Scanner;
class Circle
{
   private double radius;
   static final double PI =3.14;   //constant
    public Circle()    //default constructor
    {
        radius = 1;
    }
   public Circle (double rad) //parameterized constructor
   {
       radius = rad;
   }
   public double getRadius()
   {
       return radius;
   }
   public void setRadius(double r)
   {
       radius = r;
   }
   double area()
   {
       return PI*radius*radius;
   }
   double perimeter()
   {
       return 2*PI*radius;
   }

   public static void main(String [] args)
   {
       Scanner input = new Scanner(System.in);
       Circle c1 = new Circle(); //default constructor invoked
       System.out.println("Enter the radius :");
       double r = input.nextDouble();
       c1.setRadius(r);
       System.out.println("Area of circle is :" + c1.area());
       System.out.println("Perimeter of circle is :" + c1.perimeter());
   }
}

Below is the screenshot of output


Related Solutions

Q2. Update the given code 2 to implement the following problem: Create a class triangle Use...
Q2. Update the given code 2 to implement the following problem: Create a class triangle Use dynamic memory allocation to create 10 objects of the class triangle Set default height and base of all created objects (triangle) to 5 and 10 respectively using a constructor Ask user to change only the height of the 5th triangle Print height and base of all (10) triangles to demonstrate that you did the task correctly Deallocate the 5th object Print height and base...
Given the following specification, design a class diagram using PlantUML. To design the class diagram, use...
Given the following specification, design a class diagram using PlantUML. To design the class diagram, use abstract, static, package, namespace, association, and generalization on PlantUML Specification: A school has a principal, many students, and many teachers. Each of these persons has a name, birth date, and may borrow and return books. The book class must contain a title, abstract, and when it is available. Teachers and the principal are both paid a salary. A school has many playgrounds and rooms....
Identify the inventory costing method best described by each of the following separate statements. Assume a...
Identify the inventory costing method best described by each of the following separate statements. Assume a period of increasing costs. 1. Mimics the actual flow of inventory for most businesses. 2. Cost of goods sold approximates its current cost. 3. Precisely matches the costs of items with the revenues they generate. 4. Yields the lowest net income. 5. Has the lowest tax expense because of reporting the lowest net income. OPTIONS: WEIGHTED AVERAGE, SPECIFIC IDENTIFICATION, FIFO, OR LIFO
Directions: Read through each case study. Use your best judgement and circle whether you think it...
Directions: Read through each case study. Use your best judgement and circle whether you think it is an incidental disclosure issue, a HIPPA violation, or neither. Explain the answer you selected. Scenario: While waiting in the reception room, a patient, Xavier Gomez, overhears a receptionist talking with another patient on the telephone about a colonoscopy appointment.
Use a style sheet to define the following rules and implement the given HTML code. Please...
Use a style sheet to define the following rules and implement the given HTML code. Please put your style information within the same file as the HTML code. Rules • Hyperlinks using the nodec class should display no decoration. • Hyperlinks should display text in white with a green background color when the mouse pointer is held over the link. (use the hover pseudo-class) • Unordered lists not nested within any other lists should be displayed in blue text and...
1. Give an example of when it might be best to use each of the following...
1. Give an example of when it might be best to use each of the following qualitative forecast techniques: a) Delphi method b) Jury of executive opinion c) Sales force composite d) Consumer market survey
For each of the following situations, identify the inventory method that you would use or, given...
For each of the following situations, identify the inventory method that you would use or, given the use of a particular method, state the strategy that you would follow to accomplish your goal: Inventory costs are increasing. Your company uses weighted-average cost and is having an unexpectedly good year. It is near year-end, and you need to keep net income from increasing too much in order to save on income tax. Suppliers of your inventory are threatening a labour strike,...
(a) From your understanding, when would you use each of the following simulation commands in LTspice?...
(a) From your understanding, when would you use each of the following simulation commands in LTspice? i. DC Operating Point ii. Transient iii. AC Analysis iv. DC Sweep
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT