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 R25. The fee for a lot that is 4,000 square feet or more, but under 6,000 square feet, is R35 per week. The fee for a lot that is 6,000 square feet or over is R50 per week. Prompt the user for the length and width of a lawn USING JOPTIONPANE, and then display the weekly mowing fee USING JOPTIONPANE , as well as the 20-week seasonal fee. Save the file as Lawn.java.
Marks allocation
1. The use of class and object - 10
2. The use of JOption for input -10
3. The use of JOption for output-10
4. correct out -10
import javax.swing.JOptionPane;
public class Lawn {
public void Calcul(double leng, double wig){
double squad = leng * wig;
double weekCost, seasonCost;
if(squad < 4000){
weekCost = 25;
} else if(squad >= 4000 & squad < 6000){
weekCost = 35;
} else{
weekCost = 50;
}
seasonCost = weekCost * 20;
String rez = "The weekly lawn mowing fee is: " + weekCost + "\nThe seasonal lawn mowing fee is: " + seasonCost;
JOptionPane.showMessageDialog(null, rez);
}
public static void main(String[] args) {
Lawn law = new Lawn();
String lenghtS = JOptionPane.showInputDialog("Enter");
double lenght = Double.parseDouble(lenghtS);
String widthS = JOptionPane.showInputDialog("Enter");
double width = Double.parseDouble(widthS);
law.Calcul(lenght, width);
}
}
Comments
Leave a comment