Circle.java: 1. Create a class named Circle, include a field for radius. - Inclu
ID: 3796983 • Letter: C
Question
Circle.java:
1. Create a class named Circle, include a field for radius.
- Include a default constructor that sets the radius to 0.
- Include setRadius() and getRadius() methods.
- The setRadius() methood sets the radius, also calculates the following methods: setCircumference(), setArea(), setDiameter (using the Math.PI constant)
- Add a toString() to display current state of the object, include in the state of the radius, diameter, area, and circumference of a cirlce (DO NOT create attributes for the diameter, area, and circumference).
CircleDriver.java
2. Create a class named CircleDriver that includes the main() method.
- Add two Circle objects
- Include a determineLargerCircle() method - displays the larger of two circle objects (pass the circle objects into this method from main() ).
- Include a getACircle() method - reads the radius of the circle from the input file (one by one), call this method twice from main() and return the circle object back to main()
- Include a displayACircle method - displays current state of the circle object, including radius, diameter, area, and circumference.
Explanation / Answer
import java.util.Scanner; public class TestCircle { public static void main(String[] arges) { TestCircle C1 = new TestCircle(); Scanner FirstNum = new Scanner(System.in); public class Circle { public int radius = 1; public double diameter; public double area; //Constructor for circle class public double Circle(int First){ return radius; } //Start set and get for radius private double setRadius(int r){ return radius = 5; } private double getRadius(){ return radius; } //Start set and get for diameter public double setDiamter(double d){ return diameter = 7; } public double getDiamter(){ return radius * diameter; } //Start set and get for diameter public double setArea(double a){ return area; } public double getArea(){ return area * Math.PI * 2; } } System.out.print("Enter a number between 1 and 10 to calculate the diamater"); First = inputDevice.nextInt; //here is where i thought i could call the First method from the other document. but i'm wrong }