Question
public class TestSimpleCircle { /** Main method */ public static void main(String[] args) { // Create a circle1 with radius 1 SimpleCircle circle1 = new
public class TestSimpleCircle { /** Main method */ public static void main(String[] args) { // Create a circle1 with radius 1 SimpleCircle circle1 = new SimpleCircle(); System.out.println("The area of the circle of radius " + circle1.radius + " is " + circle1.getArea());
// Create a circle2 with radius 25 SimpleCircle circle2 = new SimpleCircle(25); System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea());
// Create a circle3 with radius 125 SimpleCircle circle3 = new SimpleCircle(125); System.out.println("The area of the circle of radius " + circle3.radius + " is " + circle3.getArea());
// Modify circle radius of 100 circle2.radius = 100; // or circle2.setRadius(100) the () parameter System.out.println("The area of the circle of radius " + circle2.radius + " is " + circle2.getArea()); } }
// Define the circle class with two constructors class SimpleCircle { double radius;
/** Defuat()Construct a circle with radius 1 */ SimpleCircle() { radius = 1; }
/**+ Construct a circle with a specified radius */ SimpleCircle(double newRadius) { radius= newRadius; }
/** Return the area of this circle */ double getArea() { return radius * radius * Math.PI; }
/** Return the perimeter of this circle */ double getPerimeter() { return 2 * radius * Math.PI; }
/** Set a new radius for this circle */ void setRadius(double newRadius) { radius = newRadius; } }
I need to change my code above to fit this question below. (JAVA)
Chapter 9-OOP, Classes, and objects (2) Two programming challenges each worth 10 points 9.1 (THE RECTANGLE CLASS) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. A method named getPerimeter() that returns the perimeter. Write a test program that creates two Rectangle objectsone with width 4 and height 40, and the other with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle in this order. ----GRASP exec: java Exercise09_01 The area of a rectangle with width 4.0 and height 40.0 is 160.0 The perimeter of a rectangle is 88. The area of a rectangle with width 3.5 and height 35.9 is 125.64999999999999 The perimeter of a rectangle is 78.8 --GRASP: operation complete. LStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started