105k views
0 votes
Write an application for a lawn-mowing service. The lawn-mowing season lasts for 20 weeks. The weekly fee for mowing a lot less than 400 square feet is $25. The fee for a lot that is 400 square feet or more, but fewer than 600 square feet, is $35 per week. The fee for a lot that is 600 square feet or over is $50 per week. Prompt the user for the length and width of a lawn, and then print the weekly mowing fee, as well as the 20-week seasonal fee. Save the class as Lawn.java.

User Gray
by
7.9k points

1 Answer

5 votes

Answer:

// library

import java.util.*;

// class definition

class Main

{// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

try{

// object to read inputs

Scanner scr=new Scanner(System.in);

System.out.print("Enter length of lawn:");

// read the length of lawn

int length=scr.nextInt();

System.out.print("Enter width of lawn:");

// read the width of lawn

int width=scr.nextInt();

// find area of lawn

int area=length*width;

//if area is less than 400

if(area<400)

{// Weekly mowing fee

System.out.println("Weekly mowing fee is:$25");

// seasonal fee

System.out.println("20-week seasonal fee is:$"+(25*20));

}

// if area >=400 and area <600

else if(area>=400 && area<600)

{

// Weekly mowing fee

System.out.println("Weekly mowing fee is:$35");

// seasonal fee

System.out.println("20-week seasonal fee is:$"+(35*20));

}

// if area >=600

else if(area>=600)

{

// Weekly mowing fee

System.out.println("Weekly mowing fee is:$50");

// seasonal fee

System.out.println("20-week seasonal fee is:$"+(50*20));

}

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Read the length and width of lawn from user with the help of scanner object. Find the area of the lawn.If the area if less than 400 then Weekly mowing fee is $25 and find the 20-week seasonal fee by multiply 25 with 20.If the area is greater than 400 and less than 600 then Weekly fee is $35 and seasonal fee will be 35*20.if the area is greater than 600 then Weekly fee is $50 and seasonal fee will be 50*20.

Output:

Enter length of lawn:15

Enter width of lawn:12

Weekly mowing fee is:$25

20-week seasonal fee is:$500

User Amit Visodiya
by
8.1k points