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

Given the following UML class diagram, implement the class as described by the model. Use your...
Given the following UML class diagram, implement the class as described by the model. Use your best judgment when implementing the code inside of each method. +---------------------------------------------------+ | Polygon | +---------------------------------------------------+ | - side_count : int = 3 | | - side_length : double = 1.0 | +---------------------------------------------------+ | + Polygon() | | + Polygon(side_count : int) | | + Polygon(side_count : int, side_length : double) | | + getSides() : int | | + setSides(side_count : int) | |...
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....
Given the following code below: public class Calculation { //method that returns cube of the given...
Given the following code below: public class Calculation { //method that returns cube of the given number public int findMax(int arr[]){    int max=0;    for(int i=1;i<arr.length;i++){        if(max<arr[i]){           max=arr[i]; }     }     return max;   } //method that returns cube of the given number   public static int cube(int n){        return n*n*n;     }   } (5 points) Define the class CalculationTest a subclass of TestCase (10 points) Define a setUp() method (20 points) Define a test method testfindMax that exercises Calculation.findMax() in Calculation class (5 points)Define...
Given the following definition of the LNode class, implement the non-recursive method saveCountinLastNode and the recursive...
Given the following definition of the LNode class, implement the non-recursive method saveCountinLastNode and the recursive method addOddNodes for the LinkedList class which represents singly linked lists. public class LNode { private int m_info; private LNode m_link; public LNode(int info){ m_info = info; m_link = null; } public void setLink(LNode link){ m_link = link; } public LNode getLink(){   return m_link; } public void setInfo(int info){ m_info = info; } public int getInfo(){   return m_info; } } public class LinkedList {...
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
JAVA: You're given 3 files. Demo.java, SampleInterace.java, and OverflowException.java. Use your Demo class to implement SampleInterface,...
JAVA: You're given 3 files. Demo.java, SampleInterace.java, and OverflowException.java. Use your Demo class to implement SampleInterface, and the OverflowException class should handle any errors that may come from the addNum method. Demo.java: public class Demo implements SampleInterface { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated constructor stub } @Override public void addNum(int value) throws OverflowException { // TODO Auto-generated method stub } @Override public void removeNum(int value) { // TODO Auto-generated method stub...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT