Concept explainers
Consider the following class declaration:
public class Circle
{
private double radius;
public Circle(double r)
{
radius = r;
{
public double getArea()
{
return Math.PI * radius * radius;
}
public double getRadius()
{
return radius;
}
}
- a. Write a toString method for this class. The method should return a string containing the radius and area of the circle.
- b. Write an equals method for this class. The method should accept a Circle object as an argument. It should return true if the argument object contains the same data as the calling object, or false otherwise.
- c. Write a greaterThan method for this class. The method should accept a Circle object as an argument. It should return true if the argument object has an area that is greater than the area of the calling object, or false otherwise.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
MyLab Programming with Pearson eText -- Access Code Card -- for Starting Out with Java: From Control Structures through Objects
Additional Engineering Textbook Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
SURVEY OF OPERATING SYSTEMS
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
- It is customary that we write this method to return a string representation of objects in a class. constructor mutator toString accessorarrow_forwardProblem Class In this exercise, you are going to create the Problem class. The Problem class is used to help simulate a math fact, for example: 2 + 5 = Your class needs to contain two contructors, one that takes String, int, int that represts the operator sign(+, -, *, or /), the minimum, and maximum values for the number range, and a second constructor that takes only a String that represents the operator sign. For the second constructor, the minimum should default to zero and the maximum to ten. Your Problem object should generate 2 random integers between the minimum and maximum values (inclusively). Each Problem object should only have one set of numbers that do not change. While you may include additional helper methods, two methods need to be available to the user. The first is the answer method that should return a double that represents the answer to the problem. The second is the toString that should return a String that represents the problem. The format should be: number…arrow_forwardjavaarrow_forward
- 9arrow_forward#pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardJAVAA7-Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program by invoking the methods that return the number of vowels and consonants. Print the counts returned.arrow_forward
- This code is used for the question being asked at the bottom. public class AccountBalance {private long accountNumber;private String ownersName;private double balance;public AccountBalance(long accountNumber, String ownersName, double balance) {this.accountNumber = accountNumber;this.ownersName = ownersName;setBalance(balance);}public long getAccountNumber() {return accountNumber;}public void setAccountNumber(long accountNumber) {this.accountNumber = accountNumber;}public String getOwnersName() {return ownersName;}public void setOwnersName() {this.ownersName = ownersName;}public double getBalance() {return balance;}public void setBalance(double balance) {if (balance < 0) {System.out.println("Balance Cannot be Negative.");balance = 0;}this.balance = balance;}} import java.util.Scanner;public class AccountBalanceDemo {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("Enter the name of the account holder: ");String name =…arrow_forward#pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardTrue or False The versions of an overloaded method are distinguished by the number, type, and order of their parameters.arrow_forward
- this is my retail item code: //Import statements public class RetailItem { private String description; private int units; private double price; public RetailItem() { } public RetailItem(String x, int y, double z) { description = x; units = y; price = z; } public RetailItem(RetailItem i) { } public void setDescription(String x) { description = x; } public void setPrice(double z) { price = z; } void setUnits(int y) { units = y; } public int getUnits() { return units; } public String getDescription() { return description; } public double getPrice() { return price; } // Main class public static void main(String[] args) { String str = "Shirt"; RetailItem r1 = new RetailItem("Jacket", 12,…arrow_forwardProblem Class In this exercise, you are going to create the Problem class. The Problem class is used to help simulate a math fact, for example: 2+5= Your class needs to contain two constructors, one that takes String, int, int that represents the operator sign(+,-, *, or /), the minimum, and maximum values for the number range, and a second constructor that takes only a String that represents the operator sign. For the second constructor, the minimum should default to zero and the maximum to ten. Your Problem object should generate 2 random integers between the minimum and maximum values (inclusively). Each Problem object should only have one set of numbers that do not change. While you may include additional helper methods, two methods need to be available to the user. The first is the answer method that should return a double that represents the answer to the problem. The second is the toString that should return a String that represents the problem. The format should be: number…arrow_forward#pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage