Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class named Circle with:Data fields: Radius Default and custom constructors Methods Set radius Get radius Get circumference Get area Create three different instances

Create a class named Circle with:Data fields:

Radius

Default and custom constructors

Methods

Set radius

Get radius

Get circumference

Get area

Create three different instances of the circle with different values and store them in an ArrayList. Test each method of the Circle class through the ArrayList.

I need to fix the program it said class, interface or enum expected in order to work. I don't know what to do to fix my code to work.

This is my program:

class Circle { private double radius; final private double PI = 22.0d/7.0d; public Circle() { } public Circle(double r) { radius = r; } public double getArea() { return PI*radius*radius; } public double perimeter() { return 2.0*PI*radius; } public double getRadius() { return radius; } public void setRadius(double radius) { this.radius = radius; } public double getPI() { return PI; } public String toString(){ return " Radius :"+radius+" , Area : "+getArea()+" "; } }

import java.util.ArrayList; import java.util.List;

public class CircleTest {

public static void main(String[] args) { List circlelist = new ArrayList<>(); circlelist.add(new Circle(5)); circlelist.add(new Circle(10)); circlelist.add(new Circle(15)); for(int i=0; i

}

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_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Databases questions

Question

Assemble short, logical paragraphs

Answered: 1 week ago