In: Computer Science
write a java program. 10-20 lines of code
You are a landscaper, one of your first tasks is to determine the cost of landscaping a yard. You charge a flat fee of $40 to landscape a yard, and an extra $10 a bag for raking leaves. Not all yards you work on have leaves that need to be raked. Houses without any leaves will be discounted $5. Using your program, use the JOption Pane to ask the homeowner to enter their name, address, and whether they have leaves in their yard. If they have leaves, fill one bag, then check the yard for more leaves. If there are more leaves, fill one bag at a time, until all leaves are gone. When all leaves are gone, calculate how many bags worth were collected. Then calculate the total cost of landscaping that yard, and print a receipt for the homeowner with the total, as well as display either a discount or surcharge for bags of leaves raked.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== import javax.swing.*; public class LandscapingCostCalculator { public static void main(String[] args) { final int FLAT_FEES = 40; final int DISCOUNT = 5; final int COST_PER_BAG = 10; int counter = 0; // track # of bags of leave collected String hasMoreLeaves = ""; String name = JOptionPane.showInputDialog("Enter name: "); String address = JOptionPane.showInputDialog("Enter address: "); while (true) { hasMoreLeaves = JOptionPane.showInputDialog("Do you have leaves in thier yard (yes/no): "); if (hasMoreLeaves.equalsIgnoreCase("yes")) { counter += 1; } else if (hasMoreLeaves.equalsIgnoreCase("no")) { break; } else { JOptionPane.showMessageDialog(null, "Invalid input. Enter yes or no only."); } } System.out.println("Receipt:\n"+"Owner: " + name+"\n"+"Address: " + address); System.out.printf("Flat Fees: $%5d\n" , FLAT_FEES); if (counter == 0) { System.out.printf("Discount Availed: $%5d\n", DISCOUNT); System.out.printf("Amount to Pay: $%5d\n", (FLAT_FEES - DISCOUNT)); } else { System.out.printf("Bags Collected : %5d\n" , counter); System.out.printf("Amount to Pay: $ %5d" , (FLAT_FEES + counter * COST_PER_BAG)); } } }
===============================================================