Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q. 2. What errors does this class have? How would you fix them? Rewrite the corr

ID: 3566394 • Letter: Q

Question

Q. 2. What errors does this class have? How would you fix them? Rewrite the correct version of this

class.

public class Square {

private double sideLength;

private double area;

public Square(double sideLength ){

sideLength = sideLength ;

area = sideLength * sideLength;

}

public double getArea() { return area; }

public static void main(string[] args){

Square sq = new Square(4.4);

System.out.print("This Area of the square is: +sq. getArea);

}

}

Q. 4. Write a program that asks the coefficients of a quadratic equation and displays the roots of the equation (only real roots).

Explanation / Answer

public class Square
{
   private double sideLength;
   private double area;
  
   public Square(double sideLength)
   {
       this.sideLength = sideLength; //error solved
       area = sideLength*sideLength;
   }
  
   public double getArea()
   {
       return area;
   }
  
   public static void main(string[] args)
   {
       Square sq = new Square(4.4);
       System.out.print("The area of square is: "+sq.getArea()); //error solved
   }
  
}

To run this code simply type: java findingRoots 1 2 3 where 1 2 3 are your a, b, c values respectively.