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

File Edit View Build Project Settings Iools Window Help Asgn1.java /Users/ios/Do

ID: 3752651 • Letter: F

Question

File Edit View Build Project Settings Iools Window Help Asgn1.java /Users/ios/Downloads - jGRASP CSD Java) public static void main(String[] args) Scanner scan new Scanner(System.in); Random radius- new Random (); System.out.println( "Enter the top-left coordinates for the rectangular portion: "); String x11scan.next() int xl -Integer.parseInt(x1l) String yll- scan.next( int yl = Integer.parseInt(y11); System.out.println("Enter the bottom-right coordinates for the rectangular portion: ") String x22 = scan.next(); int x2 -Integer.parseInt(22) String y22-scan.next( int y2 -Integer.parseInt (y22) System.out.print ( "Enter the radius of the circular portion of the field: " String radiusscan.nextInt int radius - Integer.parseInt (radius);L int side 1 = x2 - x1; int side2yl- y2; int perimeter-2*sidel 2*side2; double circumference2Math.PI* radius; double fenceLengthperimeter - 2radius 3.0 / 4 * circumference; System.out.println(You will need"+ fenceLength" meters of fence around this field." int rectangleAreasidel side2; double circleArea Math.PIradius * radius; double arearectangleArea 3.0 / 4 circleArea; System.out.println( "You have to cover"+ area square meters with grass."); Asgn1.java Compile Messages jGRASP Messages Run I/O Interactions Line:35 Col:45 Code:0 Top:15 OVS BLK

Explanation / Answer

Faults in the code:-

1. Variable 'radius' has been declared multiple times in the same method block.

Below are the declarations:

Line 11 : Random radius = new Random();

Line 26 : String radius = scan.nextInt();

Line 27 : int radius = Integer.parseInt(radius);

Solution : Variable 'radius' should be of double type as it can be a floating values.

double radius;

2. Since radius is of double type variable, scanner should read double value from the input.

Solution : double radius = scan.nextDouble();

Fixed Asgn1.java is here.

-------------------------

package assignment;

import java.util.Scanner;

public class Asgn1 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the top-left coordinates for the rectangular portion: ");

String x11 = scan.next();

int x1 = Integer.parseInt(x11);

String y11 = scan.next();

int y1 = Integer.parseInt(y11);

System.out.println("Enter the bottom-right coordinates for the rectangular portion: ");

String x22 = scan.next();

int x2 = Integer.parseInt(x22);

String y22 = scan.next();

int y2 = Integer.parseInt(y22);

System.out.println("Enter the radius of the circular portion of the field: ");

double radius = scan.nextDouble();

int side1 = x2 - x1;

int side2 = y1 - y2;

int perimeter = 2*side1 + 2*side2;

double circumference = 2 * Math.PI * radius;

double fenceLength = perimeter - 2 * radius + 3.0 / 4 * circumference;

System.out.println("You will need " + fenceLength + "meters of fence around this field.");

int rectangleArea = side1 * side2;

double circleArea = Math.PI * radius * radius ;

double area = rectangleArea + 3.0 / 4 * circleArea;

System.out.println("You have to cover " + area + "square meters with grass.");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote