what are the debuggers in Java?
import java.text.NumberFormat;
/**
*
* This class represents a circle that would be used as part
* of a larger geometry application
*/
public class Circle {
private double radius;
private NumberFormat numberFormat;
/**
* Constructor for the Circle.
* @param radius for the circle
*/
public Circle(double r) {
radius = r;
}
/**
* This method uses the radius of the circle to compute
the area.
* Math.PI is used as the value for pi.
* @return the area of the circle.
*/
public double getArea() {
return (radius * radius) *
Math.PI;
}
/**
* This method uses the radius of the circle to compute the
diameter.
* @return the diameter of the circle.
*/
public double getDiameter() {
return radius * 2;
}
/**
* This method uses the radius of the circle to compute the
circumference.
* Math.PI is used as the value for pi.
* @return the circumference of the circle.
*/
public double getCircumference() {
return this.getDiameter() *
Math.PI;
}
/**
*
* @return the NumberFormat instance for the
circle.
*/
public NumberFormat getNumberFormat() {
return numberFormat;
}
/**
* @param args - the command line arguments. This
application does not use them.
* main method where execution begins to test the
methods of the circle test.
*/
public static void main(String[] args) {
Circle c = new Circle(14);
printCircleDetails(c);
}
/**
* This method prints the details of the passed in
circle object to System.out.
* The passed in number formatter is used to format the circle
details.
* @param c - the circle to print the details of
* @param nf - the number formatter to use when printing the
details.
*/
private static void printCircleDetails(Circle c)
{
System.out.println("Circle
characteristics");
double diameter =
c.getDiameter();
NumberFormat nf =
c.getNumberFormat();
System.out.println("the diameter is
" + nf.format(diameter));
System.out.println("the area is " +
nf.format(c.getArea()));
System.out.println("the
circumference is " + nf.format(c.getCircumference()));
}
}
The number representation differ from one locale to another. Internationalizing the number is one of the best solution for the application. I have modified the code. Please find the below solution.
------------------------------------------------------------------------------------------------------------
import java.text.NumberFormat;
import java.util.Locale;
/**
*
* This class represents a circle that would be used as part
* of a larger geometry application
*/
public class Circle {
private double radius;
private NumberFormat numberFormat;
/**
* Constructor for the Circle.
* @param radius for the circle
*/
public Circle(double r) {
radius = r;
}
/**
* This method uses the radius of the circle to compute the
area.
* Math.PI is used as the value for pi.
* @return the area of the circle.
*/
public double getArea() {
return (radius * radius) * Math.PI;
}
/**
* This method uses the radius of the circle to compute the
diameter.
* @return the diameter of the circle.
*/
public double getDiameter() {
return radius * 2;
}
/**
* This method uses the radius of the circle to compute the
circumference.
* Math.PI is used as the value for pi.
* @return the circumference of the circle.
*/
public double getCircumference() {
return this.getDiameter() * Math.PI;
}
/**
*
* @return the NumberFormat instance for the circle.
*/
public NumberFormat getNumberFormat(Locale locale) {
NumberFormat formatter =
NumberFormat.getNumberInstance(locale);
return formatter;
}
/**
* @param args - the command line arguments. This application does
not use them.
* main method where execution begins to test the methods of the
circle test.
*/
public static void main(String[] args) {
Circle c = new Circle(14);
printCircleDetails(c);
}
/**
* This method prints the details of the passed in circle object to
System.out.
* The passed in number formatter is used to format the circle
details.
* @param c - the circle to print the details of
* @param nf - the number formatter to use when printing the
details.
*/
private static void printCircleDetails(Circle c) {
System.out.println("Circle characteristics");
double diameter = c.getDiameter();
NumberFormat nf = c.getNumberFormat(Locale.US);
System.out.println("the diameter is " + nf.format(diameter));
System.out.println("the area is " + nf.format(c.getArea()));
System.out.println("the circumference is " +
nf.format(c.getCircumference()));
}
}
what are the debuggers in Java? import java.text.NumberFormat; /** * * This class represents a circle...
Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { } //get method (Accessor Methods ) public double getRadius (...
Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...
My assignment is to create a rectangle class in java. •Create a MyRectangleClass •There are two private instance variables, length l and width w with double data type. •There is a constructor with two parameter •There are 4 public methods which are circumference, area, getWidth, and getLength. •circumference method will return circumference to the caller.(the formula for circumference is 2 *l + 2*w ) •Area method Return the area to the caller(:l*w) •getLength method will return length to the caller....
C++ 8. Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area...
1. Consider the class Circle below. Add an equals method to this class. The method should accept a Circle object as an argument. It should return true if the argument object contains the same data as the calling object, and false otherwise. public class Circle { private double radius; public Circle(double r) { radius = r; } public double getArea() { return Math.PI * radius * radius; } public double...
Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...
Create a Java application that allows user to build a Priority Queue of Circle Elements (i.e., priority based on the radius of the circle). The application must be menu controlled similar to Project 4 and provide the following. Allow insertion of a "Circle" object/structure in the Priority Queue data structures. Allow display of all elements from Priority Queue data structure by Invoking a method/function "DisplayPriorityQueue" (uses "DeQueue" method). Allow for deletion of the Queue This is what I have so...
2.1.1: Area of a Circle w/ Ra... SUBMIT CONTINUE RUN CODE TEST CASES ASSIGNMENT DOCS GRADE MORE Description Write a method that returns the area of a circle given the radius 1 import java.util.Scanner; 2. public class Main { 3. public static void main(String[] args) { Scanner io- new Scanner(System.in); System.out.println("Inout the radius of the circle: "); 6 double radius - io.nextDouble 7 System.out.println("Perimeter is -" + (2 radius - Math.PD)): 8 System.out.println("Area is - " . (Math.PI. radius radius)):...
Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type double named radius to represent the radius. Set to 1. 2. Constructor Methods: • Python : An overloaded constructor method to create a default circle. • C# & Java: Default Constructor with no arguments. • C# & Java: Constructor method that creates a circle with user-specified radius. 3. Method getRadius() that returns the radius. 4. ...
I have given you a piece of code to test that your circle class works correctly. Add your circle class to the code. public class Lab2Num1 { public static class Circle { private double radius; //your code goes here //provide default constructor, constructor with one parameter, area, and circumference } public static void main(String[] args) { Circle c = new Circle(1.5); System.out.printf("The circumference of a circle of radius " + c.getRadius()+ " is %5.2f\n", c.circumference()); System.out.printf("The area of...