Question
I need help with adjusting this code I made that the following will be able to print out with the given code, The coding language
I need help with adjusting this code I made that the following will be able to print out with the given code, The coding language must be in java and stay in java, also any comments left in the code don't edit it out just the source code. I will also post the code and what it prints out, and I will make a print a section of what I want it to give and it must be java, please help me , I am a beginner.
Here are my issues for this assignment:
-Add the required controls so that the length and width of the rectangle are always integers greater than 0.
-If the value of length or width is given a negative number, the absolute value of that number is considered exa. if (-1) was enter then it will print out (1) instead.
-The length and width if the value is 0 for the length or the width it will give 1 instead.
-Section of isBiggerThan method in this class that takes an object of type Rect as a parameter and compares it with the current rectangle (i.e., the object on which the isBiggerThan method is called), and if the area of the current object is larger than the area of the parameter object, return true and otherwise return false.
-I want a System.out.println("") that states what the area of the second rectangle is and if its current object is bigger it will print out true and if not false
What I want it to Print as an example:
-coordinates x=3 and y= 4 -Length: 2 width: 1 -Area: 2 -circumference: 4 -Area of the second Rectangle: 4
-Is the first area bigger than the second: false
The Source code that I wrote that needs to be adjusted:
2 /** ENGG 1420 Assignment 4 question 1 By Markus Roxik-Turner February 7,2022 assignment 4 question 1 Purpose of the code**/ 24 import java.util.*; 7 // Importing all Math classes 8 // from java.lang package import java.lang. Math; //rect class public class Rect { 12 //MODIFICATION:coordinates x,y are made private so that they can't be accessed directly 13 private int X, Y; 14 //MODIFICATION2: length and width of rectangle are made private so that they can't be accessed directly 15 private int length,width; 16 //MODIFICATION3: constructor to create an object of Rect by giving length and breadth 17 - Rect(int length, int width) {|| 18 this.length=length; 19 this.width=width; 20 } //MODIFICATION4: removed the default constructor because we have to make only 2 ways to construct the object of Rect //MODIFICATIONS:constructor to create an object of Rect by gicing length, width and coordinates of rectangle 23 Rect(int length, int width, int x, int y){ this.length=length; this.width=width; X=x; 27 Y=y; //to check if length is negative and to make it positive if(length=0) length=-length; //if length==1 then length will become 1 32 else if(length==0) 33 length=1; 34 //to check if width is negative and to make it positive 35 if(width=0) 36 width=-width; //if width==1 then length will become 1 38 else if(width==0) 39 width=1; 40 } 41 //MODIFICATION6: method to compare the areas of 2 rectangles 42 public boolean isBiggerThan (Rect obj) { 43 //areal is the area of the rectangle which is calling the function 44 int areal = this.getArea(); 45 //area2 is the area of the rectangle which is passed as parameter 46 int area2=obj.getArea(); 31 47 //if area of the cuurent object is greater return true SA if (area1>area 2) 49 return true; 50 //else return false 51 else 52 return false; 53 } 54 //method to return perimeter of rectangle 55 % public int getcircumf () { 56 //perimeter is 2*(length+width) 57 return 2*(length+width); 58 } 59 //method to return area of the rectangle 60 q public int getArea() { 61 //return area=length*width 62 return length*width; 63 } 64 //method to change the coordinates 65 public void move(int x, int y){ 66 //X tox 67 X=x; 68 //Y to y: 69 70 } 71 //method o change the size 72 q public void changesize(int n) { 73 //set length and width to n 74 length=n; 75 width=n; 76 } 77 //function to print the details of the rectangle v public static void main(String[] args) { 79 //print the coordinates and the length and width 80 Rect r = new Rect( length: Math.abs( a:0), width: Math.abs( a:-1), x:3, y: 4); 81 System.out.println("coordinates x="+ r.X +" and y= "+r.Y); 82 //print the length and width 83 System.out.println("Length: "+r.length+" width: "+r.width); 84 //get are of rectangle of getArea method 85 int area=r.getArea(); 86 //print the area 87 System.out.println("Area: "+area); 88 //get perimeter by getcircumf method 89 //this keyword is used to call the current object 90 int circum=r.getcircumf(); 91 //print the perimeter 92 System.out.println("circumference: "+circum); Y=y; 93 94 95 96 97 98 99 100 101 102 103 104 105 //get the second area of rectangle of getArea method //this keyword is used to call the current object // int area2=r.getArea(); System.out.println("Area of the second Rectangle: "+area2); } } run: coordinates x=3 and y= 4 Length: 0 width: 1 Area: 0 circumference: 2 Area of the second Rectangle: 0 BUILD SUCCESSFUL (total time: 0 seconds)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started