Beruflich Dokumente
Kultur Dokumente
Plate No. 4
LAWN
Submitted by:
May Ann C. Lareno
Student
Submitted to:
Engr. Roneil I. Enumerables, MIT
Instructor
PROBLEM
lengthwidth
weekFee
totalFee -
choice
msg1
msg2
Messages:
msg3
msg4
msg5
\
ALGORITHM
1. Prompts the user to input for length and width of a lawn.
2. Calculate the value of area which is length times width.
3. Add an if else statement: if area is less than 4000, then amount is equal to 25, if
area is greater than or equal to 4000 and area is less than 6000, then amount is
equal to 35, and if area is greater than or equal 6000, then amount is equal to 50.
4. Prompt the user to input the number of the selected payment: 1, 2 and 3 which
are stored in the variable choice.
5. If choice is equal to 1, then totalFee is equal to weekFee(weekly fee) times 20 and
displays a message regarding the result of totalFee, if choice is equal to 2, then
totalFee is equal to weekFee(weekly fee) times 20 divided by 2 plus 5 and displays
a message regarding the result of totalFee, if choice is equal to 3, then totalFee is
equal to weekFee(weekly fee) times 20 divided by 20 plus 3 and displays a message
regarding the result of totalFee.
6. Add an error message if the users input is invalid.
FLOW CHART
SOURCE CODE
package lawn;
import javax.swing.JOptionPane;
public class Lawn {
public static void main(String[] args) {
double length,width,area,totalFee,eachPayment,weeklyFee;
String l = JOptionPane.showInputDialog(null,"Input the length of a lawn:");
length = Double.parseDouble(l);
String w = JOptionPane.showInputDialog(null,"Input the width of a lawn:");
width = Double.parseDouble(w);
area = length*width;
if(area < 4000){
weeklyFee = 25;
}
else if(area >= 4000 && area < 6000){
weeklyFee = 35;
}
else if(area >= 6000){
weeklyFee = 50;
}
int choice;
String c = JOptionPane.showInputDialog(null,"Choose payment 1,2 or 3\n1.
once\n2. twice\n3. 20 times per year");
choice = Integer.parseInt(c);
if(choice == 1){
totalFee = weeklyFee*20;