Question

In: Computer Science

CandleLine is a business that sells designer candles via the Internet and has the order delivered...

CandleLine is a business that sells designer candles via the Internet and has the order delivered Below ts the code fora GUI Study the code and answer the questions that follow import java awt *, import java applet *, import java awt event *, import java text DecimalFormat, public class CandleApplet extends Applet amplements ItemListener { //Create components for applet Label companyNameLabel = new Label ("CandleLine--Candles On-line"), Label priceLabel=new Label ("Please enter the total amount of your order "), TextField priceField = new TextField(35), Labei deliveryLabel=new Label ("Please choose your method of delivery "), CheckboxGroup deliveryGroup = new CheckboxGroup (), Checkbox oneDayBox = new Checkbox("Priority (Overnight)",false,deliveryGroup) , Checkbox twoDayBox = new Checkbox("Express (2 business days)", false,deliveryGroup), Checkbox moreDaysBox = new Checkbox("Standard (3 to 7 business days)", false,deliveryGroup) , Checkbox hiddenBox = new Checkbox ("",true,deliveryGroup}) , Label outputLabel = new Label("We guarantee on time delivery, or your money back "”)}, public void init () { //Add components to window and set colors setBackground (Color cyan}, add (companyNameLabel) , add (priceLabel) , add (priceField), priceField requestFocus(), add (delaveryLabel), add (oneDayBox) , oneDayBox addItemListener (this), add (twoDayBox) , twoDayBox additemListener (this), add (moreDaysBox) , MoreDaysBox addItemListener(this), add(outputLabel), public void itemStateChanged(ItemEvent choice) { try { double delivery, double price = Double parseDouble(priceField getText()), QUESTION 5. 2 ENTER YOUR CODE HERE //Display output outputLabel setForeground(Color black}, DecimalFormat twoDigits = new DecimalFormat ("RH#,### 00"), outputLabel setText ("Your total cost is " + twoDigits format (price + delivery)), catch {NumberFormatException e) { outputLabel setText ("You must enter an amount greater than zero"), outputLabel setForeground(Color red), hiddenBox setState (true), priceField setText(""), priceField requestFocus({), } } }

5.1 Draw the output that is created when the above applet ts ran ?

5.2 After the user entered an amount, the program must calculate the delivery charges If a customer wants pnority delivery (overnight), then the delivery charge is R120 00 If | the customer prefers express delivery (2 business days), then the delivery charge ts R90 00 If the customer wants standard delivery (3 to 7 business days) and the total | cost of the order is more than R75 00, then CandleLine delivers the items to the customer free, If the order is less than R75 00, then CandileLine charges R20 00 for the standard delivery .

Write the code needed to calculate the delivery cost ?

Solutions

Expert Solution

Here is the completed code for this problem. Your code was a mess. Took a lot of time to format it, I’m guessing it is transcribed from an image. In the future when you are pasting a code, please make sure that it is in proper format. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// CandleApplet.java

import java.applet.Applet;

import java.awt.CheckboxGroup;

import java.awt.Color;

import java.awt.Label;

import java.awt.TextField;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.Checkbox;

import java.text.DecimalFormat;

public class CandleApplet extends Applet implements ItemListener {

      // Create components for applet

      Label companyNameLabel = new Label("CandleLine--Candles On-line");

      Label priceLabel = new Label("Please enter the total amount of your order ");

      TextField priceField = new TextField(35);

      Label deliveryLabel = new Label("Please choose your method of delivery ");

      CheckboxGroup deliveryGroup = new CheckboxGroup();

      Checkbox oneDayBox = new Checkbox("Priority (Overnight)", false,

                  deliveryGroup);

      Checkbox twoDayBox = new Checkbox("Express (2 business days)", false,

                  deliveryGroup);

      Checkbox moreDaysBox = new Checkbox("Standard (3 to 7 business days)",

                  false, deliveryGroup);

      Checkbox hiddenBox = new Checkbox("", true, deliveryGroup);

      Label outputLabel = new Label(

                  "We guarantee on time delivery, or your money back ");

      public void init() { // Add components to window and set colors

            setBackground(Color.cyan);

            add(companyNameLabel);

            add(priceLabel);

            add(priceField);

            priceField.requestFocus();

            add(deliveryLabel);

            add(oneDayBox);

            oneDayBox.addItemListener(this);

            add(twoDayBox);

            twoDayBox.addItemListener(this);

            add(moreDaysBox);

            moreDaysBox.addItemListener(this);

            add(outputLabel);

      }

      public void itemStateChanged(ItemEvent choice) {

            try {

                  double delivery = 0;

                  double price = Double.parseDouble(priceField.getText());

                  // code for QUESTION 5. 2

                  // checking if oneDayBox is selected

                  if (oneDayBox.getState()) {

                        // delivery charge = R120

                        delivery = 120;

                  } else if (twoDayBox.getState()) {

                        // delivery charge = R90 for two day delivery

                        delivery = 90;

                  } else if (moreDaysBox.getState()) {

                        // standard delivery

                        if (price >= 75) {

                              // free delivery for products with price>=75

                              delivery = 0;

                        } else {

                              // delivery charge = R20 for products with price<75

                              delivery = 20;

                        }

                  }

                  // Display output

                  outputLabel.setForeground(Color.black);

                  DecimalFormat twoDigits = new DecimalFormat("RH#,### 00");

                  outputLabel.setText("Your total cost is "

                              + twoDigits.format(price + delivery));

            } catch (NumberFormatException e) {

                  outputLabel.setText("You must enter an amount greater than zero");

                  outputLabel.setForeground(Color.red);

                  hiddenBox.setState(true);

                  priceField.setText("");

                  priceField.requestFocus();

            }

      }

}

/*OUTPUT screenshots*/



Related Solutions

An article predicts that "spit," spam that is delivered via internet phone lines and cell phones,...
An article predicts that "spit," spam that is delivered via internet phone lines and cell phones, will be a growing problem as more people turn to web-based phone services. In a poll of 5500 cell phone users, 25% indicated that they had received commercial messages and ads on their cell phones. Is there sufficient evidence that the proportion of cell phone users who have received commercial messages or ads in 2004 was greater than the proportion of 0.13 reported for...
A business maintains a centralized warehouse for the distribution of products ordered via the internet.  Management is...
A business maintains a centralized warehouse for the distribution of products ordered via the internet.  Management is examining the relation between distribution costs and the number of orders processed in a month.  The goal is to estimate monthly cost from the number of orders.  Here is the data for the past twelve months, with Cost given in thousands of dollars and Orders given in the thousands.  Orders are the explanatory variable and Cost is the dependent variable. Cost 52.9 71.7 85.6 63.7 72.8 68.4...
Lexi operates a booming business which sells fruits and vegetables delivered door to door to residential...
Lexi operates a booming business which sells fruits and vegetables delivered door to door to residential customers each morning. Her business invests its excess working capital whenever it is convenient. The business makes regular contributions to local charities to maintain a good business reputation. Lexi started the business and operated as a sole proprietorship during the last 7 months of 2016. When she met with an attorney in December of 2016, the attorney advised Lexi to set up a Limited...
imagine you have been reduced to the size of an enzyme and delivered via a capsule...
imagine you have been reduced to the size of an enzyme and delivered via a capsule by mouth into 82-year old Mary to find out why she has a loss of appetite. The goal is for the capsule to begin dissolving in the upper GI tract and for you to use your ship to explore Mary’s GI system for signs of disease. In a 500-word paper, describe what you see as you move through the GI tract and be sure...
What are the advantages and disadvantages of radiation delivered through radiopharmaceutical or via an external source
What are the advantages and disadvantages of radiation delivered through radiopharmaceutical or via an external source
A customer’s order is delivered (received by the customer) on September 10, 2019. This order was...
A customer’s order is delivered (received by the customer) on September 10, 2019. This order was placed with the company on June 5, 2019, and received by the manufacturing department on June 20, 2019. Actual production on the order began on July 10, 2019, and was completed August 10, 2019. Based on this information, calculate the following for this order: (a) total customer-response time (CRT), (b) order receipt time, (c) manufacturing lead (cycle) time, (d) manufacturing wait time, (e) manufacturing...
How is network data delivered on the Internet versus the World Wide Web?
How is network data delivered on the Internet versus the World Wide Web?
Abby’s candle shop sells candles. Abby would like to estimate her income and sales, she has...
Abby’s candle shop sells candles. Abby would like to estimate her income and sales, she has collected data from the last two months. The cost of each candle is $1 and she sells them for $2.50 each. She receives her candles every day from her supplier, the supplier brings in 500 candles a day for Abby to sell. If Abby runs out of candles she estimates that an unhappy customer will cost her $0.50. If Abby has to keep the...
In the case, Jamie put together a total cost for the first order of specialty candles...
In the case, Jamie put together a total cost for the first order of specialty candles by adding up all of the direct material, direct labor, and allocated MOH; in other words, he used absorption costing. This is the method commonly discussed in textbooks because it is also the method required by GAAP for financial reporting purposes. However, there are several other methods for allocating costs to a product or order: Variable Manufacturing Cost. This method of tracking costs includes...
Conduct a literature search to locate a nursing intervention delivered via telehealth.(use reference) Summarize the findings...
Conduct a literature search to locate a nursing intervention delivered via telehealth.(use reference) Summarize the findings of the literature review in the form of a table. This table should include the article title, database used, summarize the key points of article, summarize findings, Is this applicable to patient population
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT