Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 8 of the textbook introduces object-oriented programming by incrementally developing a class called Point.java and a program called PointMain.java which uses objects of the

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Chapter 8 of the textbook introduces object-oriented programming by incrementally developing a class called Point.java and a program called PointMain.java which uses objects of the Point class. In this assignment you will follow a similar pattern to develop a class called Circle.java and a program called CircleMain.java. Turn in a single zipped folder called Assignment8.zip containing both java files. General Requirements: Make sure that your code conforms to the conventions covered in class, that is: Indent your code consistently; be consistent with the placement of curly braces. Give meaningful names to methods and variables in your code. Follow Java's naming conventions about the format of ClassNames, methodAndVariableNames, and CONSTANT_NAMES. Localize variables whenever possible -- that is, declare them in the smallest scope in which they are needed. Include a multiline comment at the top of the program, as in: File Name * TCSS 142 - Assignment 7 After the multiline comment include a line of whitespace followed by any required import statements, followed by a line of whitespace, followed by a Javadoc class comment with some basic information: Explain the purpose of this class .. Also, document class invariants (if any) here @author Your Name @version public class MyClassName { Include a Javadoc comment at the start of each method to explain the purpose of the method. include @param and @return tags where needed: Explain the method's purpose. (Prompts for..., Calculates..., etc) @param myParameterName (Explain the purpose of this parameter here) @return (Explain what the method returns here) public static myMethodName ( ) { Include a Javadoc comment for any class constants used: Explain the purpose of the constant here... public static final int MY_CONSTANT_NAME Include a Javadoc comment for any class fields used: Explain the purpose of the field here... public int myFieldName; Part 1: Write a class called Circle.java which has a single field of type double called radius. Circle.java should include the following instance (non-static) methods: A default (no argument) constructor public Circle () which constructs a (unit) circle of radius 1. An overloaded constructor public Circle (double newRadius) that accepts a value for the radius. An accessor public double getRadius () which returns the radius of the circle. A mutator public void setRadius (double newRadius) which accepts a value for the radius. An accessor public double calculateDiameter () which returns the diameter of the circle. An accessor public double calculateCircumference () which returns the circumference. An accessor public double calculateArea () which returns the area of the circle. A public String toString() method which returns a String representation of the circle such as "Radius: 8.20". The toString() method should not print anything, it should just return a String. The String that is returned should include the value of the radius field, rounded to exactly 2 decimal places (look at the format() method of the String class).toString should not include calculated values such as diameter, circumference, or area. A public boolean equals (Object other) method which returns true if the circle is compared to another circle of equal radius and returns false otherwise. Do not change any of these method signatures; write them exactly as they are shown above. Each method requires a javadoc comment including @param, @return, and @throws tags as appropriate. The methods of the Circle class must enforce the invariant that radius > O by throwing IllegalArgumentException if the invariant is ever violated. Recall that diameter = radius * 2 circumference = PI * diameter area = PI * radius Part 2: Write an interactive program called CircleMain.java that uses objects of type Circle. Use static methods to organize your program. Use static methods to display an introduction and an exit message. Use additional static methods, as necessary, to structure the work of the program. Each static method should perform a single function. Your program must include a method to prompt the user for the radius of a circle and to return a result to main(). Restrict the range of valid values to non-negative numbers. After obtaining a valid radius from the user, your program should construct a new object of type Circle with the user specified radius. Your program must include a method which accepts a Circle as a parameter and displays the following: A String representation of the Circle (use the toString() method of the Circle class for this). The diameter, circumference, and area of the Circle. The values for diameter, circumference, and area should be labeled and display exactly 2 decimal places (using printf or String.format()). Your program must maintain an array of the most recent 3 Circle objects created. The program must display information about the most recent 3 circles. Additionally, the output must include a message indicating how many circles in the array are equal. (Use the .equals() method of the Circle class.) Your program should repeat until the user enters 0 as the radius. (O is a sentinel value) The program's exit message must report the total number of circles created. Note: No calculations should be done in Circle Main.java. The values of the diameter, circumference, and area must all be obtained from the Circle object by using its instance methods. The methods of the Circle class should return full precision values (Not rounded values). Sample output for the program with this modification (user input in bold): This program will prompt for the radius of a circle and display the circle's diameter, circumference, and area. The program will repeat until the user chooses to quit. Enter a radius (0 to quit): 10 Here is your new Circle: Radius: 10.00 Diameter: 20.00, Circumference: 62.83, Area: 314.16 Here are the most recent 3 circles: Radius: 10.00, Diameter: 20.00, Circumference: 62.83, Area: 314.16 null. null. None of the Circles are equal. Enter a radius (0 to quit): 3.3 Here is your new Circle: Radius: 3.30 Diameter: 6.60, Circumference: 20.73, Area: 34.21 Here are the most recent 3 circles: Radius: 3.30, Diameter: 6.60, Circumference: 20.73, Area: 34.21 Radius: 10.00, Diameter: 20.00, Circumference: 62.83, Area: 314.16 null. Your Radius: 3.30 Diameter: 6.60, Circumference: 20.73, Area: 34.21 Here are the most recent 3 circles: Radius: 3.30, Diameter: 6.60, Circumference: 20.73, Area: 34.21 Radius: 3.30, Diameter: 6.60, Circumference: 20.73, Area: 34.21 Radius: 10.00, Diameter: 20.0, Circumference: 62.83, Area: 314.16 2 of the Circles are equal. Enter a radius (0 to quit): -4 The radius must be a positive number; please try again. Enter a radius (0 to quit): Hello Not a number; try again. Enter a radius (0 to quit): 3.3 Here is your new Circle: Radius: 3.30 Diameter: 6.60, Circumference: 20.73, Area: 34.21 Here are the most recent 3 circles: Radius: 3.30, Diameter: 6.60, Circumference: 20.73, Area: 34.21 Radius: 3.30, Diameter: 6.60, Circumference: 20.73, Area: 34.21 Radius: 3.30, Diameter: 6.60, Circumference: 20.73, Area: 34.21 All 3 of the Circles are equal. Enter a radius (0 to quit): 0 Thanks for using the Circle program. Circles created: 4

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: 3

blur-text-image

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

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago