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

b) rite code for the method loadshapes. opens the file \"Shapes.txt\" and create

ID: 3831552 • Letter: B

Question

b) rite code for the method loadshapes. opens the file "Shapes.txt" and creates appropriate adding them to the ArrayList parameter. Be sure to declare any additional variables you need. Don't about exceptions. worry Name public static void rray List shape shapes Scanner fin new Scanner (new File ("Shapes declare/initialize other variables you need while (fin hasNext()) f end loop fin close(); end method c) Write code for the Circle class toString method. This method should return a string like: "Circle: position (15, 20) radius 10, area 314.16". in Circle class public string tostring f end function write code for the Rectangle class toString method. This method should return a string like: 'Rectangle: position (15, 20) length 10, width 8, area 80". in Rectangle class public string to string f

Explanation / Answer

a)

List<Shape> shapes = new ArrayList<>();
  
loadShapes(shapes);
for(Shape s : shapes)
{
System.out.println(s);
}

b) Cannot implement without knowledge of content of s and Shape class.

c) public String toString()
{
return ""Circle: position (" + getX() + ", " + getY() + ")" + " radius " + getRadius() + ", area " + getArea() + "".";
}

d)

public String toString()
{
return ""Rectangle: position (" + getX() + ", " + getY() + ")" + " length " + getLength() + ", width " + getWidth() + ", area " + getArea() + "".";
}