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

(java)Fix the code in this program. Fix lines, add lines… Comment each line that you fixed...
(java)Fix the code in this program. Fix lines, add lines… Comment each line that you fixed … what you did to fix it. import java.util.Scanner; public static void main(String[] args) { // This program Converts grade Points into a Letter grade. int gradePoints == 00; // Declare variable and assign initial value System.out.printl("Enter Grade Points: "; //Input gradePoints; if ( gradePoints >= -42 ) { System.out.println("Grade = A"); } // if true, then ends here, if false drop to next...
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...
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
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.
In Java: Write a program that will count the number of characters, words, and lines in...
In Java: Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown below. c:\exercise>java Exercise12_13 Loan.java File loan.java has 1919 characters 210 words 71 lines c:\exercise> Class Name: Exercise12_13
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT