Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;//import scanner
- import java.text.DecimalFormat; //import Decimal Format
- /*Name:Chris McGlynn
- Date:30/9/19
- Program to calculate area of grass in a garden with a circular pond in it
- */
- public class Garden {
- public static void main (String []args){
- //initalise the decimal format
- DecimalFormat df = new DecimalFormat ("0.00");
- //initialise the scanner
- Scanner keyboard=new Scanner (System.in);
- System.out.println("What is the length of the lawn?");//user to input length
- double lawnLength=(keyboard.nextDouble());
- System.out.println("What is the radius of the pond?");//user to input radius of pond
- double radiusOfGardenPond=(keyboard.nextDouble());
- double areaOfGardenLawn= Math.pow(lawnLength, 2);//formula for area of lawn
- double areaOfPond= Math.PI * Math.pow(radiusOfGardenPond, 2); //formula for area of pond
- double areaOfGrass=areaOfGardenLawn-areaOfPond;
- System.out.println ("The area of the garden is "+df.format(areaOfGardenLawn));
- System.out.println ("The area of the pond is "+df.format (areaOfPond));
- System.out.println ("The area of grass in the garden is "+df.format(areaOfGrass));
- }//main
- }//class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement