Question

In: Computer Science

write a java program. 10-20 lines of code You are a landscaper, one of your first...

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.

Solutions

Expert Solution

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));
        }

    }
}

===============================================================


Related Solutions

WRITE CODE IN JAVA it is now your turn to create a program of your choosing....
WRITE CODE IN JAVA it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless. The program must include instructions for the user. Be...
Write a Java program that will test lines of text to see if they are palindromes....
Write a Java program that will test lines of text to see if they are palindromes. The program should prompt the user for the name of a file to process, then open and read the file of possible palindromes (one per line of text). The program should then print the total number of lines read, and total number of palindromes.
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
Write a Java program to do the following: Ask the user to enter 10 first names...
Write a Java program to do the following: Ask the user to enter 10 first names (one word - no hyphen or apostrophe) using the keyboard. 1) Display the list of names one per line on the Console. 2) Display the names again, after eliminating duplicates using a HashSet (Your code MUST use HashSet).
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
Program in Java code Write a program with total change amount in pennies as an integer...
Program in Java code Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. .Ex1: If the input is: 0 the output is:    No change            Ex2: If the input is:    45   the output is:   1 Quarter 2 Dimes
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
write a java code Write a generic program to compute the sum of 30 terms of...
write a java code Write a generic program to compute the sum of 30 terms of the following series. (181 - 5)/31 + (186 + 9)/34 - (191 - 13)/37 + (196 + 17)/40 + . . . . . 1 5 11 Note: the 3rd, 6th, 9th term etc, has a negative sign in front of parenthesis. User Input: None Expected output: Term Ratio Sum 1 5.677 5.677 2 5.735 11.413 3 -4.811 6.602
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT