Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//java gui //1. class AgileWaterFallProgram package agile_waterfall; /** * * For this lab, you probably don't need to modify this class. */ public class AgileWaterfallProgram

//java gui

//1. class AgileWaterFallProgram

package agile_waterfall;

/**  
 *  * For this lab, you probably don't need to modify this class.  */  public class AgileWaterfallProgram { public static void main(String[] args) { AgileWaterfallGUI gui = new AgileWaterfallGUI(); } } 

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

//2.class AgileWaterfallGUI

package agile_waterfall; import javax.swing.*; public class AgileWaterfallGUI extends JFrame { private JPanel mainPanel; public final static String AGILE = "Agile"; public final static String WATERFALL = "Waterfall"; public final static String EITHER = "either"; public final static String RECOMMENDATION_TEMPLATE = "%s could use %s"; AgileWaterfallGUI() { setContentPane(mainPanel); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); //TODO any GUI configuration needed  //TODO add event handler to read the data entered, and selections made,  //TODO recommend a methodology, display in JLabel.  // Use the recommendationTemplate to display a String like "Android App should use Agile"  }} 

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

//3. class DonorProgram

package blood_donor; /**  * Main method to start the GUI.  * Can do other non-gui-specific app setup here if needed.  * For this lab, you probably don't need to modify this class.  */ public class DonorProgram { public static void main(String[] args) { DonorGUI gui = new DonorGUI(); } } 

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

// 4. class donorGui

package blood_donor; import javax.swing.*; public class DonorGUI extends JFrame { public static final String ELIGIBLE = "Eligible!"; public static final String NOT_ELIGIBLE = "Sorry, not eligible."; public static final String INPUT_ERROR = "Error - enter positive numbers"; private JPanel mainPanel; DonorGUI() { this.setContentPane(mainPanel); pack(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); // TODO add a listener for the checkEligibilityButton  // This should verify that the user has entered a positive number  // in both the weightTextField and ageTextField JTextField  // If either or both are not valid, the resultLable should  // display the INPUT_ERROR text.   // If both weight and age are positive numbers, use the data  // to decide if the user is eligible to be a blood donor.  // To be eligible, a person must be 17 or older,  // AND weigh 110 lbs or more.   // Display the ELIGIBLE text if they are eligible.  // Display the NOT_ELIGIBLE text if they are not eligible.   } } 

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

// class Garden

package garden; /* * For this lab, you probably don't need to modify this class. * */ class GardenProgram { public static void main(String[] args) { GardenGUI gui = new GardenGUI(); } } 

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

//6.class GardenServiceData

package garden; /**  * Constants to represent price of each service.  * A future program would read these from a data store, and/or permit modification  */ public class GardenServiceData { static String[] gardenSizes = {"Small", "Medium", "Large"}; // Prices of services   static final double MOWING = 15; static final double LEAF_RAKING = 12; static final double MEDIUM_PRICE_MULTIPLY = 2; static final double LARGE_PRICE_MULTIPLY = 3; // Example gardener contact String, used when generating invoices   static final String gardenerContactString = "Rose the Gardener, 123 Main Street, Minneapolis. Telephone 000-000-000"; } 

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

//6. class InvoiceGenerator

package garden; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StrSubstitutor; import java.util.HashMap; /**  * You should not need to modify this file,  * but you will need to call the methods here.  */  public class InvoiceGenerator { static final String GARDENER_CONTACT = "GARDENER_CONTACT"; static final String NAME = "NAME"; static final String ADDRESS = "ADDRESS"; static final String DATE = "DATE"; static final String GARDEN_SIZE = "GARDEN_SIZE"; static final String MOWING = "MOWING"; static final String LEAVES = "LEAVES"; static final String TOTAL = "TOTAL"; static String invoiceTemplate; /* Provide a HashMap with the following keys, and String values.   NAME  ADDRESS  DATE  GARDEN_SIZE  MOWING  LEAVES  TOTAL   Notice these Strings are provided as constants in this class.   For a price, the value should be a String number with 2 decimal places,  and no & or other currency symbol, e.g. "28.00" or "14.00"    */    public static String generate(HashMap data) { // Add in the gardener info String  data.put(GARDENER_CONTACT, GardenServiceData.gardenerContactString); // Create a String Substitutor with the HashMap  StrSubstitutor sub = new StrSubstitutor(data); //Use our own template prefix  sub.setVariablePrefix("&{"); String invoice = sub.replace(invoiceTemplate); return invoice; } static int width = 80; static String lines[] = { StringUtils.center("************ Garden Services Invoice ************", width), "", "&{GARDENER_CONTACT}", "", "Customer Name: &{NAME}", "Address of garden: &{ADDRESS}", "", "Date of service: &{DATE}", "Size of garden: &{GARDEN_SIZE}", "", "Lawn mowing service charge: $ &{MOWING}", "Leaf raking service charge: $ &{LEAVES}", "", "Total: $ &{TOTAL}", "", "Please send payment to the address above.", "Thank you for your business."  } ; static { // Center the lines and concatenate together  StringBuilder builder = new StringBuilder(); for (String line: lines) { builder.append(line); builder.append(" "); } invoiceTemplate = builder.toString(); }} 

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

//7. class InvoiceWriter

package garden; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; /**  * Handles writing invoices to disk. Invoices are saved in the  * directory given by INVOICE_DIRECTORY.  *  * You should not need to modify this file, but you will need to call methods.  */  public class InvoiceWriter { static final String INVOICE_DIRECTORY = "GardeningInvoices"; private static String dateFormatString = "MMM_dd_yyyy"; // e.g. "sep_09_2017"  private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatString); static { File invoiceDir = new File(INVOICE_DIRECTORY); try { invoiceDir.mkdir(); } catch (SecurityException e) { if (!invoiceDir.exists()) { System.out.println("ERROR - could not create Invoice Directory. " + INVOICE_DIRECTORY); } // Otherwise, if it exists, presumably it has already been created, so no problem.  } } /*  Create a valid filename from a date, and the customer's name.  Names may have characters that are not permitted in filenames, these must be removed or replaced.  This is a very basic solution: remove all characters from customer name that are not A-Z or a-z.  This could definitely be improved. There are many names that would be distorted by this method.  This would perform poorly on names with characters outside A-Z and a-z. What if a customer has several characters removed from their name?  Many characters outside A-Z and a-z range are valid filename characters.   A more exhaustive solution to preserve names and create valid filenames would be more work, and more testing.  Looking into a 3rd party library to handle this would be recommended in a real program; it's a fairly common problem.  You are not required to improve this method; but you are welcome to contribute an improved version if you like :)  */   public static String createFileName(String customer, Date date) { String name = removeBannedCharacters(customer); if (name.length() == 0) { name = "Customer"; // Something, if there are no valid filename characters. Can you think of a better solution? Ask the user for a name?  } // Format the date into a String  String dateString = simpleDateFormat.format(date); String filename = String.format("%s_%s_invoice.txt", name, dateString); return filename; } protected static String removeBannedCharacters(String st) { return st.replaceAll("[^A-Za-z]", ""); } /* Warning! This method overwrites an existing file. A real program  * should warn the user that a file with the proposed name exists, and offer them  * the choice to overwrite or give a new name. */   public static boolean writeToFile(String filename, String text) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(new File(INVOICE_DIRECTORY, filename)))) { writer.write(text); writer.close(); return true; } catch (IOException e) { System.out.println("Unable to write to file " + filename + ". Error message: " + e.getMessage()); return false; } } } 

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

//INSTRUCTIONS

### Problem 1: Blood Donor Eligibility  Add these components to DonorGUI.form. Ensure that you use these names. **JButton checkEligibilityButton** User will click this to check eligibility **JTextField weightTextField** for the user's weight in pounds **JTextField ageTextField** For the user's age in years **JLabel resultLabel** Will display if the user is eligible to be a blood donor or not Note that there are three final Strings defined in DonorGUI.java. The autograder expects you to use these to generate text for the resultLabel. In DonorGUI, add a click listener for the checkEligibilityButton. In the listener's onClick method, verify that the user has entered a positive number in both the weightTextField and ageTextField JTextFields. If either or both inputs are not valid (negative or not a number), the `resultLabel` JLabrl should display the `INPUT_ERROR` text. If both weight and age are positive numbers, use the data to decide if the user is eligible to be a blood donor. To be eligible, a person must be 17 or older, AND weigh 110 lbs or more. Display the `ELIGIBLE` text in the `resultLabel` JLabel if they are eligible. Display the `NOT_ELIGIBLE` text in the `resultLabel` JLabel if they are not eligible. Run and test your application. Take a screenshot of your application running and add it to the **screenshots** directory in this project. ### Problem 2: Agile or Waterfall?  Create a GUI . Add these components to AgileWaterfallGUI.form. Again, use these names. **JTextField projectName** **JSlider peopleOnTeam** This should take values between 1 and 300. Add JLabels with the text "1" at the start, and "300" at the end, to indicate the start and end values. **JCheckBox firmDeadlines** **JCheckBox experienceAllPhases** **JCheckBox qualityControl** **JCheckBox earlyIntegration** **JCheckBox earlyWorkingModels** **JButton recommendMethodology** **JLabel recommendation**  Add more JLabels as appropriate, for example, to label the JTextField and JSlider name and max and min values. . Add a click event listener to the `recommendMethodology` button. When clicked, this button will read the data entered, and recommend Waterfall or Agile or Either for a development method for the project. Display the recommendation in the `recommendation` JLabel. Use the provided Strings `AGILE`, `WATERFALL` and `EITHER` and `RECOMMENDATION_TEMPLATE` to display the result. Your GUI program should use a JLabel and the recommendationTemplate format String provided to display something like Big IBM Project could use Waterfall or My assignment could use Agile or "Banking App could use either" Take a screenshot of your application running and add it to the **screenshots** directory in this project. ### Problem 3: Gardener Invoices  You have been hired by a gardener to write a program to generate invoices. For this program, your program will generate text file invoices for some sample gardening services. The gardener offers two services: mowing, and leaf raking. The price structure is based on the size of the garden. To keep it simple, gardens may be small, medium, or large. The prices for a small garden are mowing = $15 ; leaf raking = $12 The price for each service for a medium garden is 2x that of a small garden. (So leaf raking in a medium garden is $24). The price for each service for a large garden is 3x that of a small garden. (So leaf pulling pulling in a large garden is $36) The invoices need to have:  * The customer name  * Address  * Date of service  * The size of the garden  * The mowing charge  * The leaf raking charge  * The total for all services  * Contact information for the gardener Build a GUI that allows the gardener to enter data about a customer and garden services performed. The program will generate a preview on an invoice. The gardener can review this, and then save it to a file. The GUI needs these components. Things you need to create and work with are in **bold**. A JPanel dataEntryPanel, containing the following components: * JTextField, customerNameTextField. This has been created for you. * JTextField, customerAddressTextField. This has been created for you. * JSpinner, serviceDateSpinner, to select date the garden service was done. This has been created and configured for you * **JComboBox** to select small, medium, large. Populate this from GardenServiceData's `size` array. Call it `gardenSizeComboBox` JCheckBox mowingServiceCheckBox - if mowing was done. This has been created. JLabel mowingServiceCost - to display the total cost for mowing services. * **JCheckBox** - if leaf raking was done. You need to create this. Call it `leafRakingCheckBox`. * **JLabel** - to display the total cost for leaf raking services. Call it `leafRakingCost`. * **JLabel** displays the total cost of all services. You need to create this. Call it `invoiceTotal` * JButton, generateInvoicePreviewButton, to generate invoice preview. This has been created for you. Another JPanel, invoicePreviewPanel, containing the following components * JTextArea, invoicePreviewTextArea, to display the invoice preview. This has been created for you. * JButton, saveInvoiceButton, to save invoice to disk. This has been created for you. You will not need to work with the JScrollPanel or JLabel in this JPanel. The user should be able to enter all information. Your program will calculate the totals based on what services are selected, and the size of the garden. As the user modifies the garden size JComboBox, and/or checks and unchecks CheckBoxes, the price for each service, and the total, should update automatically. If a service is not selected, the GUI should show "0.00" for the cost for that service. If no services are selected, the GUI should show "0.00" for the total cost. Totals should be displayed as numbers with 2 decimal places, you may add a $ if desired. So "$14.00" and "14.00" are both acceptable in the GUI. Dates in the invoice should be displayed as MM-dd-YYYY, for example, May 30 2017 would be "05-30-2017". On clicking the Invoice Preview button, use the methods in the Invoice Generator class to create a String, with the entire invoice. Display this in the JTextArea. The user will be able to make edits to this text. If the user does not select any services, and clicks the Invoice Preview button, show an error dialog. Clear the invoicePreviewTextArea. If the user does not enter a customer name or customer address, show an error dialog. Clear the invoicePreviewTextArea. On clicking the Save Invoice button, check to see if an invoice preview has been generated. If not, display an error dialog. If an invoice preview has been generated in invoicePreviewTextArea, use the methods in InvoiceWriter to write the invoice to disk. Usually, you'd warn the user that they are about to overwrite an existing file, but for this program, you can create the file if it does not exist, or overwrite it if if does exist. Use the InvoiceWriter.createFileName method to generate an appropriate invoice file name from the customer's name and the service date. Use the InvoiceWriter.writeToFile method to write the invoice. **If you need to show an alert dialog, or a String input dialog**, use the showMessageDialog and getStringWithDialog methods in GardenGUI. Take some example screenshots of your application running and add them to the **screenshots** directory in this project. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions

Question

=+2. Imagine you are working for one of the following:

Answered: 1 week ago