Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.util.Scanner;//import scanner
  2. import java.text.DecimalFormat; //import Decimal Format
  3.  
  4. /*Name:Chris McGlynn
  5. Date:30/9/19
  6. Program to calculate area of grass in a garden with a circular pond in it
  7. */
  8.  
  9.  
  10. public class Garden {
  11.  
  12. public static void main (String []args){
  13.  
  14. //initalise the decimal format
  15. DecimalFormat df = new DecimalFormat ("0.00");
  16.  
  17. //initialise the scanner
  18. Scanner keyboard=new Scanner (System.in);
  19.  
  20.  
  21. System.out.println("What is the length of the lawn?");//user to input length
  22. double lawnLength=(keyboard.nextDouble());
  23.  
  24. System.out.println("What is the radius of the pond?");//user to input radius of pond
  25. double radiusOfGardenPond=(keyboard.nextDouble());
  26.  
  27.  
  28. double areaOfGardenLawn= Math.pow(lawnLength, 2);//formula for area of lawn
  29. double areaOfPond= Math.PI * Math.pow(radiusOfGardenPond, 2); //formula for area of pond
  30.  
  31. double areaOfGrass=areaOfGardenLawn-areaOfPond;
  32.  
  33. System.out.println ("The area of the garden is "+df.format(areaOfGardenLawn));
  34. System.out.println ("The area of the pond is "+df.format (areaOfPond));
  35. System.out.println ("The area of grass in the garden is "+df.format(areaOfGrass));
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. }//main
  43. }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement