You are on page 1of 8

HOLY CROSS OF DAVAO COLLEGE, INC.

Sta. Ana Ave., Davao City


1st Semester 2015-2016
IT2 Computer Programming 1

INFORMATION TECHNOLOGY EDUCATION

Plate No. 4
LAWN

Submitted by:
May Ann C. Lareno
Student

Submitted to:
Engr. Roneil I. Enumerables, MIT
Instructor

September 22, 2015

PROBLEM

Write an application for a lawn-mowing service. The lawn-mowing season lasts 20


weeks. The weekly fee for mowing a lot under 4,000 square feet is $25. The fee for
a lot that is 4,000 square feet or more, but under 6,000 square feet, is $35 per
week. The fee for a lot that is 6,000 square feet or over is $50 per week. Prompt the
user for the length and width of a lawn.
Add a prompt that asks the user whether the customer wants to pay (1) once, (2)
twice, or (3) 20 times per year. If the user enters 1 for once, the fee for the season
is simply the seasonal total. If the customer requests two payments, each payment
is half the seasonal fee plus a $5 service charge. If the user requests 20 separate
payments, add a $3 service charge per week. Display the number of payments the
customer must make, each payment amount, and the total for the season.

VARIABLES, OBJECTS, METHODS, AND MESSAGES


Variables:
area

double, area of a lawn

lengthwidth

double, length of a lawn


-

double, width of a lawn

weekFee

- double, weekly fee for a lawn

totalFee -

double, price for 20 weeks

choice

int, times of payment

msg1

prompts the user to input thelength of a lawn

msg2

prompts the user to input forwidth of a lawn

Messages:

msg3

prompts the user to input a number from the given choices

msg4

displays fee of a lawn

msg5

displays an error message

\
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;

JOptionPane.showMessageDialog(null,"Your payment is once\nAnd is $" +


totalFee);
}
else if(choice == 2){
eachPayment = ((weeklyFee*20)/2)+5;
totalFee = eachPayment*2;
JOptionPane.showMessageDialog(null,"You must make 2 payments\nEach
payment is $" + eachPayment +"\nAnd your total fee is $" + totalFee);
}
else if(choice == 3){
eachPayment = weeklyFee+3;
totalFee = eachPayment*20;
JOptionPane.showMessageDialog(null,"You must make 20 payments\nEach
payment is $" + eachPayment + "\nAnd your total fee is $" + totalFee);
}
else{
JOptionPane.showMessageDialog(null,"Error: Invalid input!");
}
}
}

You might also like