Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; /** * The Circle class defines a circle specified in double precision. * */ public class Circle { /** * The circle's immutable

import java.util.Scanner;
/**
* The Circle class defines a circle specified in double precision.
*
*/
public class Circle {
/**
* The circle's immutable radius.
*/
private final double radius;
/**
* Constructs a new Circle with the specified radius
*
* @param radius the radius of the circle
*/
public Circle(double radius) {
this.radius = radius;
}
/**
* Returns the radius of this Circle in double precision.
*
* @return the radius of this Circle.
*/
public double getRadius() {
return radius;
}
/**
* Returns the diameter of this Circle in double precision.
*
* @return the diameter of this Circle.
*/
public double getDiameter() {
return 2 * 3.1415926 * radius;
}
/**
* Returns the area of this Circle in double precision.
*
* @return the area of this Circle.
*/
public double getArea() {
return 3.1415926 * radius * radius;
}
/**
* Returns the length of an arc for this Circle given an angle specified in radians.
*
* @param theta the angle in radians.
* @return the arc length for the given angle.
*/
public double getRadiansArcLength(double theta) {
return radius * theta;
}
/**
* Returns the length of an arc for this Circle given an angle specified in degrees.
*
* @param alpha the angle in degrees.
* @return the arc length for the given angle.
*/
public double getDegreesArcLength(double alpha) {
return 3.1415926 * radius * alpha / 180;
}
/**
* Returns the area of a sector for this Circle given an angle specified in radians.
*
* @param theta the angle in radians.
* @return the sector area for the given angle.
*/
public double getRadiansSectorArea(double theta) {
return radius * radius * theta / 2;
}
/**
* Returns the area of a sector for this Circle given an angle specified in degrees.
*
* @param alpha the angle in degrees.
* @return the sector area for the given angle.
*/
public double getDegreesSectorArea(double alpha) {
return 3.1415926 * radius * radius * alpha / 360;
}
/**
* Main method that tests the calculation of Circle properties.
*
* @param args the unused command line arguments.
*/
public static void main(String[] args) {
System.out.println("------------------------------------------------------------");
System.out.println("CircleCalc v1.0");
System.out.println();
System.out.println("Calculates and prints information for a user-supplied radius");
System.out.println("------------------------------------------------------------");
System.out.print("Enter the circle's radius: ");
Scanner in = new Scanner(System.in);
Circle c = new Circle(in.nextDouble());
System.out.println();
System.out.println("Circle properties:");
System.out.println("\tRadius: " + c.getRadius());
System.out.println("\tDiameter: " + c.getDiameter());
System.out.println("\tArea: " + c.getDiameter());
System.out.println("\tArc length at 1.57 radian: " + c.getRadiansArcLength(1.57));
System.out.println("\tArc length at 90 degrees: " + c.getDegreesArcLength(90));
System.out.println("\tSector area at 1.57 radian: " + c.getRadiansSectorArea(1.57));
System.out.println("\tSector area at 90 degrees: " + c.getDegreesSectorArea(90));
}
}
image text in transcribed
Deadline: Instructions: - The lab activity solutions are expected to be as individual work, not the products of group effort. - All submissions will be submitted electronically. - As an example of simple refactoring, we'll provide some sample "bad code" with a prevalent smell and ask you to walk through the process of refactoring it. Checkout the CircleCalc Eclipse project from https://subversion.assembla.com/svn/ee4611circlecalcrefactoring/trunk/ and perform the following actions: 1. Critique the code - Identify the most offensive smell. - Identify potential problems that could be encountered in developing and/or maintaining a system that uses the code as it is written. 2. Identify a refactoring from https://refactoring.com/catalog/index.html that can be applied to remove the smell. 3. Apply the refactoring to "fix" the code. 4. Describe why the refactored code is better. 5. Suggest at least 2 strategies to speed-up the code. (C) 2022, CCSW325-Software Construction, SW Eng. Depart, CCSE, UJ

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions