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) | |...
A UML class diagram can be used to model UML by considering each graphical component of...
A UML class diagram can be used to model UML by considering each graphical component of the notation to be a class. For example, a class diagram contains a collection of classes. Your problem is to construct and draw one class diagram with the below UML elements. That is, there will be a class for each of the elements listed. You must also provide ALL of the relationships between each of these classes. The elements to model in the class...
Write two classes, ToDoList and Driver ToDoList should implement the following UML class diagram: ToDoList -list:String[]...
Write two classes, ToDoList and Driver ToDoList should implement the following UML class diagram: ToDoList -list:String[] -size:int +ToDoList() +add(String item):void +remove(String item): boolean +toString():String add(String item) should add the item as the last element in the list, updating size. remove(String item) should remove the item and return true, or, if the item was not in the list, return false.   To remove the item, check every list element from 0 to size-1, and if that item is equal to the parameter...
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....
Need Java Code and UML Design for the following program: Use the Account class created above...
Need Java Code and UML Design for the following program: Use the Account class created above to simulate an ATM machine. Create five accounts in an array with id 0, 1, ..., 4, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run (see below). You can...
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...
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
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 {...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT