Question
Too many circles!!! You may reuse code from Part 3 to create a TooManyCirclesTester class. At this point, you have likely noticed that the code
-
Too many circles!!!
You may reuse code from Part 3 to create a TooManyCirclesTester class. At this point, you have likely noticed that the code is getting quite long and repetitive. Lets simplify some of our code to be less wasteful.
-
Update your Circle class to have a new private attribute of type String named name
-
Update your Circle class to have new public methods for getting and setting the attribute name
-
Update your Circle class to have a public constructor that takes two parameters:
-
The first parameter should be a double named rad
-
The second parameter should be a String named circleName
-
-
Inside of the constructor, call the setRadius method using rad as the argument
-
Notice that we can call methods from inside of other methods. This is what we have already been doing inside of the main method, but up to this point, it may not have been obvious that this is what we have been doing.
-
Notice that we can pass parameters from one method as an argument for a parameter in a different method.
-
-
Inside of the constructor, call your setName method using circleName as an argument
-
Update your Circle class to have a new public method that returns a type of String named getInfo
-
Create a new String variable that you can use to build up the following as a single large string:
-
<name>: Radius: <radius> Diameter: <diameter> Area: <area> |
-
Use System.lineSeparator() to get a string of either or depending on the OS to separate lines in a string
-
Notice that we are making a string to store in a variable, not printing the information out directly to the screen
-
Return your String variable
-
Update your TooManyCirclesTester class, which reused code from part 3, with the following changes:
-
Replace references to the Circles default constructor (no arguments) with the newly created constructor.
-
Use the appropriate arguments as necessary
-
You may use string literals for each circles name
-
-
Remove any unnecessary calls to set a circles radius, i.e. immediately after a constructor.
-
Replace any print statements that print out a circles information with a single print statement that uses the Circle classes new getInfo method
-
Step 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