Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 13, Problem 13.6PE
Program Plan Intro
Program to ComparableCircle class
Program Plan:
- Include a class name named “Exercise_13_06”.
- Declare the main() method.
- Create two instances of ComparableCircle objects by referencing the ComparableCircle class.
- Display comparableCircle1 and ComaprableCircle2 objects.
- Find and display the larger of the two ComparableCircle objects by using the compareTo() method in GeometricObject class.
- Close the main() method.
- Close the class.
- Include an abstract class “GeometricObject”.
- Declare all the data types of the variables.
- Construct a default geometric object.
- Construct a geometric object with color and filled value.
- Assign color and fill to the object.
- Set a new color.
- Define an isFilled method returns filled and since filled is Boolean; the get method is named isFilled.
- Set a new filled and getDateCreated method.
- Override toString function to return output.
- Define Abstract method getArea.
- Define Abstract method getPerimeter.
- Close class.
- Include a class “ComparableCircle”.
- Construct a ComparableCircle method with specified radius.
- Construct a ComparableCircle method with specified properties.
- Construct an override function to implement the compareTo method defined in Comparable.
- Construct an override function to implement the toString method defined in Circle class.
- Close class.
- Include a class “Circle” that extends the class GeometricObject class.
- Declare radius variable.
- Create a Circle constructor.
- Assign values to radius.
- Create a function to set color and set fill in the Circle.
- Create a Function to return radius.
- Create a function to set a new radius.
- Create an override function to return area.
- Create an override function to return perimeter.
- Create an override string description of circle object.
- Close class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Triangle class) Design a new Triangle class that extends the abstract
Geometricobject class. Draw the UML diagram for the classes Triangle and
Geometricobject then implement the Triangle class. Write a test program
that prompts the user to enter three sides of the triangle, a color, and a Boolean
value to indicate whether the triangle is filed. The program should create a Tri-
angle object with the se sides, and set the color and filled properties using the
input. The program should display the area, perimeter, color, and true or false to
indicate whether it is filled or not.
(Triangle class) Design a new Triangle class that extends the abstract GeometricObject class.
Draw the UML diagram for the classes Triangle and GeometricObject and then implement
the Triangle class. Write a test program that prompts the user to enter three sides of the
triangle, a colour, and a Boolean value to indicate whether the triangle is filled. The program
should create a Triangle object with these sides and set the colour and filled properties using
the input. The program should display the area, perimeter, colour, and true or false to indicate
whether it is filled or not.
(The ComparableSquare class) Define a class named ComparableSquare thatextends Square and implements Comparable. Implement the compareTo methodto compare the Squares on the basis of area. Write a test class to find the larger oftwo instances of ComparableSquareobjects.
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Knowledge Booster
Similar questions
- (Java) Question 5 Explain the answer step-by-step and include verbal explanation. Thank you! Write an interface as follows: The interface is named ServiceReminder It has one method named timeForService that has no parameters and returns a boolean variable. Now, update the below class so that is inherits from ServiceReminder Note that the next service date should be 90 days from the last service public abstract class Car { private double gasGauge; private double currMileage; private String color; private String make; private String model; private int daysLastService; public Car(String color, String make, String model, int daysLastService) { this.color = color; this.make = make; this.model = model; gasGauge = 0.0; currMileage = 0.0; this.daysLastService = daysLastService; } @Override public String toString() { return "Make: " + make + "\nModel: " + model + "\nColor: " + color…arrow_forward(Car Class) Create a class called Car that includes three instance variables-a model (type String), a year (type String), and a price (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the price is not positive, do not set its value. Write a test application named CarApplication that demonstrates class Car's ca- pabilities. Create two Car objects and display each object's price. Then apply a 5% discount on the price of the first car and a 7% discount on the price of the second. Display each Car's price again. 3.13arrow_forward(The MyPoint class) Design a class named MyPoint to represent a point with x- and y-coordinates. The class contains: 1 The data fields x and y that represent the coordinates with getter methods. 1 A no-arg constructor that creates a point (0, 0). I A constructor that constructs a point with specified coordinates. I A method named distance that returns the distance from this point to a specified point of the MyPoint type. I A method named distance that returns the distance from this point to another point with specified x- and y-coordinates. Draw the UML diagram for the class and then implement the class. Write a test program that creates the two points (0, 0) and (10, 30.5) and displays the distance between them.arrow_forward
- (The Rectangle class) Following the example of the Circle class in Section 8.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 andheight 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.Draw the UML diagram for the class and then implement the class. Write a testprogram that creates two Rectangle objects—one with width 4 and height 40and the other with width 3.5 and height 35.9. Display the width, height, area,and perimeter of each rectangle in this order.arrow_forward(The Rectangle class) Following the example of the Circle class in Section 8.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 andheight 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.Draw the UML diagram for the class and then implement the class. Write a testprogram that creates two Rectangle objects—one with width 4 and height 40and the other with width 3.5 and height 35.9. Display the width, height, area,and perimeter of each rectangle in this order.arrow_forward(Algebra: quadratic equations) Design a class named QuadraticEquation for a quadratic equation ax² + bx + x = 0. The class contains: 1 The private data fields a, b, and c that represent three coefficients. 1 A constructor for the arguments for a, b, and c. 1 Three get methods for a, b, and c. A method named getDiscriminant() that returns the discriminant, which is b? – 4ac. The methods named getRoot1() and getRoot2() for returning the two roots of the equation using these formulas: -b + Vb? – 4ac -b - Vb? – 4ac and r2 2a 2a These methods are useful only if the discriminant is nonnegative. Let these meth- ods return 0 if the discriminant is negative. Draw the UML diagram for the class, and then implement the class. Write a test program that prompts the user to enter values for a, b, and c and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0, display the one root. Otherwise, display "The equation has no…arrow_forward
- (The Account class) Account -id: int -balance: double -annualInterestRate : double -dateCreated : Date +Account( ) +Account(someId : int, someBalance : double) +getId() : int +setId(newId : int) : void +getBalance() : double +setBalance(newBalance : double) : void +getAnnualInterestRate( ) : double +setAnnualInterestRate(newRate : double) : void +getDateCreated( ) : Date +getMonthlyInterestRate( ) : double +getMonthlyInterest( ) : double +withdraw(amt : double) : void +deposit(amt : double) : void Design a class named Account that contains: ■ A private int data field named id for the account (default 0). ■ A private double data field named balance for the account (default 0). ■ A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. Make it static. ■ A private Date data field named dateCreated that stores the date when the account was created. (private Date dateCreated)…arrow_forward(2e flaiks) An object of class Student (download the code from Blackboard) stores the studentName, the studentNumber and the major of a student. The class has the following methods: FinalExamProblem-2 • computeTuitionFees, which returns the fees paid by a student each term, • degreeToBeGranted, which returns the degree that will be grabnted to the student on successful graduation, and changeMajor, which changes the major the student is pursuing. Methods computeTuitionFees and degreeToBeGranted use complex conditional statements. To remove bad smells from the code, I have refactored the solution and provide a sample class diagram below. Your task is to implement the following class diagram using Java so that the purpose of the problem remains the same and still gives you the same output. Use the same FinalExamProblemTwoMain class. You are not allowed to make any changes in the FinalExamProblemTwoMain class. UNRE ERED UNREC TERED UNREGISTERED UNREGISTERED EGISTERED UNREGISTERED Student…arrow_forward(The Rectangle class) Following the example of the Circle class in Section 8.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. I A no-arg constructor that creates a default rectangle. I A constructor that creates a rectangle with the specified width and height. I A method named getArea() that returns the area of this rectangle. A method named getPerimeter () that returns the perimeter. Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects-one 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.arrow_forward
- (Java) Question 6 Explain the answer step-by-step and include verbal explanation. Thank you! Given the below Tesla class, update the class to inherit from the Comparable interface and also write a compareTo method that orders two Tesla objects according to 1. model, 2. range, and 3. color: public class Tesla { private String model; private int range; private String color; public Tesla(String model, int range, String color) { this.model = model; this.range = range; this.color = color; } @Override public boolean equals(Object o) { if (this == o) return true; } else if (!(o instanceof Tesla)) { return false; } else { Tesla t = (Tesla) o; return model.equals(t.model) && range == t.range && color.equals(t.color); } }}arrow_forwardProblem (Circle.java) Implement a class called Circle for representing a circle. The circle has two data members, a Point object representing the center of the circle and a float value representing the radius. Include appropriate constructors for your Circle class. Encapsulate it. Also include methods for finding the area and circumference of the circle. area = pi * radius * radius circumference = 2 * pi * radius. (You may use the static constant pi in the Math class) 5. Override the toString() and equals().arrow_forward(Java) Create a class named Customer that will determine the monthly repayment amount due by acustomer for a product bought on credit. The class has five fields: customer name, contactnumber, product price, number of months and the monthly repayment amount. Write get and setmethods for each field, except for the monthly repayment amount field. The set methods mustprompt the user to enter the values for the following fields: customer name, contact number,product price and number of months. This class also needs a method to calculate the monthlyrepayment amount (product price divided by the number of months).Add a subclass named Finance_Period that will determine if a customer will pay interest or not. Ifthe number of months to pay for the product is greater than three, the customer will pay 25%interest, or else no interest applies. The maximum number of months to pay for the product is 12.Override the calculate_repayment() method by determining if the customer will pay interest ornot…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education