Q3Java please What errors does this class have How would you

Q3-Java please

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.printf(\"This Area of the square is:\\t +sq. getArea);

Solution

The correct code is

public class Square{
private double sideLength;
private double area;
public Square(double sideLength){
sideLength = sideLength;
area = sideLength*sideLength;
}


public double getArea(){
return area;
   }
// S should be capital as String is a defined class in java
public static void main(String[] args){
   Square sq = new Square(4.4);

//\"\" were not closed and include () after function call
   System.out.print(\"This Area of the square is: \\t\" + sq.getArea() );
   }// function was not closed
}// class was not closed

Q3-Java please What errors does this class have? How would you fix them? Rewrite the correct version of this class. public class Square {private double sideLeng

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site