I need help fixing these errors for the bolded parts because I have no idea how to fix it 4 errors found: File: E:\Recta
Posted: Fri May 20, 2022 5:29 pm
I need help fixing these errors for the bolded
parts because I have no idea how to fix it
4 errors found:
File: E:\Rectangle.java [line: 71]
Error: The method compare(int, int) is undefined for the type
Integer
File: E:\Rectangle.java [line: 72]
Error: The method compare(int, int) is undefined for the type
Integer
File: E:\Rectangle.java [line: 73]
Error: The method compare(int, int) is undefined for the type
Integer
File: E:\Rectangle.java [line: 74]
Error: The method compare(int, int) is undefined for the type
Integer
class Rectangle{
//variables to store the values of the objects
int x;
int y;
int width;
int height;
//constructor to create objects
public Rectangle (int x, int y, int width, int height){
//this keyword to resolve name conflict
this.x = x;
this.y = y;
this.width = width;
this.height = height;
//making sure the width and height are postive
if(width < 0 || height < 0)
System.out.println("Width and height of rectangle must be
positive");
}
//method to get height of the object
public int getHeight(){
//returning the height of thw object
return height;
}
//method to get width of the object
public int getWidth(){
//returning the width of the object
return width;
}
//method to get X coordinate of the object
public int getX(){
//returning the X coordinate of the object
return x;
}
//method to get Y coordinate of the object
public int getY(){
//returning the Y coordinate of the object
return y;
}
//Overriding equals() method to compare two objects of class
Rectangle
@Override
public boolean equals(Object o){
//if object o is compared to itself, return true
if (o == this) {
return true;
}
//if o is not an instance of class Rectangle, return false
if (!(o instanceof Rectangle)) {
return false;
}
return false;
}
public Integer compare(Rectangle R, int x, int y, int width, int
height) {
//Compare the values of objects and return value
accordingly
return Integer.compare(x, R.x) == 0
&& Integer.compare(y, R.y) == 0
&& Integer.compare(width, R.width) == 0
&& Integer.compare(height, R.height) == 0;
}
//driver code
public static void main(String[] args){
//creating two objects
Rectangle r1 = new Rectangle(2, 3, 4, 3);
Rectangle r2 = new Rectangle(4, 3, 4, 5);
//calling methods for object r1
System.out.println("X cordinate is = " + r1.getX());
System.out.println("Y cordinate is = " + r1.getY());
System.out.println("Width = " + r1.getWidth());
System.out.println("Height = " + r1.getHeight());
//checking if r1 and r2 are equal
if (r1.equals(r2))
System.out.println("Objects are Equal");
else
System.out.println("Objets are Unequal");
}
}
parts because I have no idea how to fix it
4 errors found:
File: E:\Rectangle.java [line: 71]
Error: The method compare(int, int) is undefined for the type
Integer
File: E:\Rectangle.java [line: 72]
Error: The method compare(int, int) is undefined for the type
Integer
File: E:\Rectangle.java [line: 73]
Error: The method compare(int, int) is undefined for the type
Integer
File: E:\Rectangle.java [line: 74]
Error: The method compare(int, int) is undefined for the type
Integer
class Rectangle{
//variables to store the values of the objects
int x;
int y;
int width;
int height;
//constructor to create objects
public Rectangle (int x, int y, int width, int height){
//this keyword to resolve name conflict
this.x = x;
this.y = y;
this.width = width;
this.height = height;
//making sure the width and height are postive
if(width < 0 || height < 0)
System.out.println("Width and height of rectangle must be
positive");
}
//method to get height of the object
public int getHeight(){
//returning the height of thw object
return height;
}
//method to get width of the object
public int getWidth(){
//returning the width of the object
return width;
}
//method to get X coordinate of the object
public int getX(){
//returning the X coordinate of the object
return x;
}
//method to get Y coordinate of the object
public int getY(){
//returning the Y coordinate of the object
return y;
}
//Overriding equals() method to compare two objects of class
Rectangle
@Override
public boolean equals(Object o){
//if object o is compared to itself, return true
if (o == this) {
return true;
}
//if o is not an instance of class Rectangle, return false
if (!(o instanceof Rectangle)) {
return false;
}
return false;
}
public Integer compare(Rectangle R, int x, int y, int width, int
height) {
//Compare the values of objects and return value
accordingly
return Integer.compare(x, R.x) == 0
&& Integer.compare(y, R.y) == 0
&& Integer.compare(width, R.width) == 0
&& Integer.compare(height, R.height) == 0;
}
//driver code
public static void main(String[] args){
//creating two objects
Rectangle r1 = new Rectangle(2, 3, 4, 3);
Rectangle r2 = new Rectangle(4, 3, 4, 5);
//calling methods for object r1
System.out.println("X cordinate is = " + r1.getX());
System.out.println("Y cordinate is = " + r1.getY());
System.out.println("Width = " + r1.getWidth());
System.out.println("Height = " + r1.getHeight());
//checking if r1 and r2 are equal
if (r1.equals(r2))
System.out.println("Objects are Equal");
else
System.out.println("Objets are Unequal");
}
}