You just bought a small farm, and you would like to get a fenced area with grass
ID: 3748549 • Letter: Y
Question
You just bought a small farm, and you would like to get a fenced area with grass for some of your animals. The shape of this field is the following (grey line not included): Note: the center of the circular region is right on the upper-right corner of the rectangular region. Also, the radius will always be smaller than the sides of the rectangle You know the following information about this field: coordinates of 2 corners of the rectangular part (upper-left and lower-right), and the radius of the circular part (i.e., length of the grey lines). You need to know the length of fence you will need all around it, so that you can buy the right amount of materials to do it. Also, you need to know the size of the area to cover with grass, so that you can buy the right amount of grass seeds. In this assignment, you should write the program for calculating this. Here is what the final result should look like (the underlined text is what the user would enter...of course, it can be other numbers): Enter the top-left coordinates for the rectangular portion: 10 50 Enter the bottom-right coordinates for the rectangular portion: 60_15 Enter the radius of the circular portion of the field: 18 You will need 218.82292999999999 meters of fence around this field You have to cover 2513.40637 square meters with grass. You will need 23 bags of grass seeds for this. The total cost for seeds will be $322 before tax. Steps: 1. 2. Create the skeleton of your program (i.e., class name and main method) Write the code to match the first 3 lines of input/output above. Read the input and save it properly into 5 int variables. Note: when you have 2 numbers to read on the same line, you just need to write 2 consecutive "scan.nextlnt)" commands (one for each number).Explanation / Answer
Java code for first 3 lines of input/output:
import java.util.Scanner;
//class STARTS
public class FormCalculator {
//main method
public static void main(String[]arg){
//Scanner class object to read inputs from user
Scanner scan = new Scanner(System.in);
//asking user
System.out.print("Enter the top-left coordinates for the rectangular portion:");
int top=scan.nextInt();
int left=scan.nextInt();
System.out.print("Enter the bottom-right coordinates for the rectangular portion:");
int bottom=scan.nextInt();
int right=scan.nextInt();
System.out.print("Enter the radius of th circular portion of the field:");
int radius=scan.nextInt();
}
}
//class ENDS
Output: first 3 lines of input/output
Enter the top-left coordinates for the rectangular portion:10 50
Enter the bottom-right coordinates for the rectangular portion:60 15
Enter the radius of th circular portion of the field:18
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.