Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Microsoft Word-Proj6d cs 2.pdf e Chegg Study | Guided Sol * Files x/ D Microsoft

ID: 3681536 • Letter: M

Question

Microsoft Word-Proj6d cs 2.pdf e Chegg Study | Guided Sol * Files x/ D Microsoft Word-Lab7dc N Netflix × CS × C file:///C:/Users/Patrick/Downloads/Lab7.pdif +findVolume0:double 1) Create a class called Circle using the UML class diagram given above. PI should be declared as a constant (please use your own declared constant for this lab, rather than Math.PI The class contains two constructors one that set the data properties to the default (assume default radius is 1.0 and the default color is white) and the 2-arg constructor sets the data properties to the values passed in. In addition, add the get/set methods and the find methods given in the UML diagram. (yes, this is a Circle class, but we can still use the data properties to calculate values for a Sphere...) Circumference 2 . . radius . diameter Circle Area : -rz-. -d2 Sphere Surface Area: 4 . . r 2-1' d2 Sphere Volume: 4/3 . . r33( -d 3)/6 2) Create the application class CircleApp. In this class, you will create 2 circle objects (circle and circle2). For circleI, use the default constructor and display as shown below.). For circle2, ask the user for the radius and color of the circle and use the 2-arg constructor Display all values (except radius) to 3 decimals. This can be done in either the Circle class or the CircleApp class - you decide Your output should look like the following: Circle 1: Color: white Radius: 1.0 Area: 3.142 Circumference: 6.283 Surface Area: 12.566 Volume: 4.189 Enter in the radius of Circle 2: 5.5 Enter in the color of Circle 2: red Color: red Radius: 5.5 Area: 95.033 Circumference: 34.557 Surface Area: 380.132 Volume: 696.909 Lab7.pdf Show all downloads 9:24 AM 3/25/2016 Ask me anything

Explanation / Answer

CircleApp.java

package com.test.chegg;

import java.util.Scanner;

/**
* Tester class to check the Circle properties
*
* @author yourName
*
*/
public class CircleApp {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       // Instantiating new circle object with default constructor
       Circle circle1 = new Circle();
       System.out.println("Circle1:");
       // Displaying the circle properties
       System.out.println(circle1.toString());

       System.out.println("Enter in the raidus of Circle 2:");
       // Accepting radius from user
       double radius = sc.nextDouble();
       System.out.println("Enter in the color of Circle 2:");
       // Accepting color from user
       String color = sc.next();
       // Instantiating new circle object with arg constructor
       Circle circle2 = new Circle(radius, color);
       System.out.println("Circle2:");
       // Displaying the circle properties
       System.out.println(circle2.toString());
       sc.close();
   }
}

Circle.java

package com.test.chegg;

/**
* Circle Class to calculate the area,volume,circumference and surface area of a
* circle
*
* @author yourName
*
*/
public class Circle {
   public final double PI = 3.14159;
   private double radius;
   private String color;

   // Default Constructor
   Circle() {
       setRadius(1.0);
       setColor("White");
   }

   // Argument Constructor
   Circle(double radius, String color) {
       setRadius(radius);
       setColor("color");
   }

   /**
   * @return the radius
   */
   public double getRadius() {
       return radius;
   }

   /**
   * @param radius
   * the radius to set
   */
   public void setRadius(double radius) {
       this.radius = radius;
   }

   /**
   * @return the color
   */
   public String getColor() {
       return color;
   }

   /**
   * @param color
   * the color to set
   */
   public void setColor(String color) {
       this.color = color;
   }

   /**
   * Method to find the volume of a circle
   *
   * @return volume
   */
   public double findVolume() {
       double volume = 4 * PI * getRadius() * getRadius() * getRadius() / 3;

       return volume;
   }

   /**
   * Method to find the area of a circle
   *
   * @return circleArea
   */
   public double findArea() {
       double circleArea = PI * getRadius() * getRadius();
       return circleArea;
   }

   /**
   * Method to find the surface area
   *
   * @return surfaceArea
   */
   public double findSurfaceArea() {
       double surfaceArea = 4 * PI * getRadius() * getRadius();
       return surfaceArea;
   }

   /**
   * Method to find the surface area
   *
   * @return circumference
   */
   public double findCircumference() {
       double circumference = 2 * PI * getRadius();
       return circumference;
   }

   public String toString() {
       return "Color:" + getColor() + " Radius:" + getRadius() + " Area:"
               + String.format("%.3f", findArea()) + " Circumference:"
               + String.format("%.3f", findCircumference())
               + " Surface Area:" + String.format("%.3f", findSurfaceArea())
               + " Volume:" + String.format("%.3f", findVolume());
   }
}

Output:

Circle1:
Color:White
Radius:1.0
Area:3.142
Circumference:6.283
Surface Area:12.566
Volume:4.189
Enter in the raidus of Circle 2:
5.5
Enter in the color of Circle 2:
red
Circle2:
Color:color
Radius:5.5
Area:95.033
Circumference:34.557
Surface Area:380.132
Volume:696.909