Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I fix this error in the public class Circle? 5 points Status: Not Submitted This program is incorrectly comparing Circles using == Modify

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
How do I fix this error in the public class Circle?
5 points Status: Not Submitted This program is incorrectly comparing Circles using == Modify the CircleTester class to correctly compare Circle objects using .equals You'll need to implement the following methods in the circle class so that the CircleTester can correctly compare and print Circles: public String toString() public boolean equals(Circle other) equals should only return true if both Circles have the exact same attributes (color, radius, x, and y). toString should return a string of the form [color] circle with a radius of [radius] at position ([x], [y]). For example: Circle circle = new Circle(ie, "blue", 50, 40); System.out.println(circle) Should print out blue circle with a radius of 19 at position (50, 40) Save Submit + Continue 1 public class Circle 2-{ private int radius; private String color; private int x; private int y; public Circle(int theRadius, String theColor, int xposition, int y { radius - this.radius; color = this.color; X = this.xy y = this.y; 3 3 4 5 6 7 8 9 10 - 11 12 13 14 15 16 17 18 19 20 21 22 23 - 24 25 26 27 28- 29 public int getRadius() { return radius: } public int getxo { return x; } public int getY() 3.7.10. save public int getY() { return y; } 27 28 29 30 31 32 33 - 34 35 36 37 38 39 public String getColor() { return color; } // Implement a toString method and an equals method here! public String toString { 1/ Change this! return color+" circle with a radius of "+radius +" at position 40 3 41 42 43 44 45 46 47 48 49 50 51 52 53 54 ] public boolean equals(Circle other) { // Change this! if(this.color.equals(other color) && this.x - other.x && this return true; else return false; } Run Code Check Code 1 STOP Exception in thread "main" java.lang.NullPointerException at Circle.equals(Circle.java:48) at CircleTester.main(CircleTester.java:19) Errors: Circle.java: Line 48: You appear to be referencing a variable that is null

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 Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

What is Selenium? What are the advantages of Selenium?

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago