(Modified Fuzzy Dice Order Form Application) Modify the Fuzzy Dice Order Form application to determine whether a customer should receive a 7% dis- count for ordering more than $50 (before tax) in fuzzy dice. The discount amount should be displayed as a negative value, because the amount will be subtracted from the user’s total (Fig. 7.31).
a) Copying the template to your working directory. Copy the C:Examples Tutorial07ExercisesFuzzyDiceOrderFormModified directory to your C:Sim- plyJava directory.
b) Opening the template file. Open the FuzzyDiceOrderForm.java file in your text editor.
c) Determining whether the total cost is over $50. In the calculateJButton- ActionPerformed method, add an if statement to determine if the amount ordered is greater than $50. [Hint: This if statement can be added after the code that calcu- lates the subtotal cost and before the code that calculates the tax.]
d) Displaying the discount and subtracting the discount from the total. If a customer orders more than $50, display a message dialog as shown in Fig. 7.31 that informs the user that the customer is entitled to a 7% discount. The message dialog should contain an INFORMATION_MESSAGE icon. Calculate 7% of the total amount, and display the discount amount as a negative value in discountJTextField, which is unedit- able. Subtract
```
1 // FuzzyDiceOrderForm.java
2 // This application calculates the total cost of a
3 // purchase order for different colored fuzzy dice.
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.text.*;
7 import javax.swing.*;
8
9 public class FuzzyDiceOrderForm extends JFrame
10 {
11 // JLabel that displays header on application window
12 private JLabel fuzzyDiceJLabel;
13
14 // JLabel and JTextField for order number
15 private JLabel orderNumberJLabel;
16 private JTextField orderNumberJTextField;
17
18 // JLabel and JTextField for user's name
19 private JLabel nameJLabel;
20 private JTextField nameJTextField;
21
22 // JLabel and JTextFields for user's address
23 private JLabel addressJLabel;
24 private JTextField addressJTextField1;
25 private JTextField addressJTextField2;
26
27 // JLabel and JCheckBoxes for die types
28 private JLabel typeJLabel;
29 private JCheckBox whiteTypeJCheckBox;
30 private JCheckBox redTypeJCheckBox;
31
32 // JLabel and JTextFields for die quantities
33 private JLabel quantityJLabel;
34 private JTextField whiteQuantityJTextField
35 private JTextField redQuantityJTextField;
36
37 // JLabels for die prices
38 private JLabel priceJLabel;
39 private JLabel whitePriceJLabel;
40 private JLabel redPriceJLabel;
41
42 // JLabel and JTextFields for die subtotals
43 private JLabel totalsJLabel;
44 private JTextField whiteTotalsJTextField;
45 private JTextField redTotalsJTextField;
46
47 // JLabel and JTextField for total before tax
48 private JLabel subtotalJLabel;
49 private JTextField subtotalJTextField;
50
51 // JLabel and JTextField for tax
52 private JLabel taxJLabel;
53 private JTextField taxJTextField;
54
55 // JLabel and JTextField for discount
56 private JLabel discountJLabel;
57 private JTextField discountJTextField;
58
59 // JLabel and JTextField for final total
60 private JLabel totalJLabel;
61 private JTextField totalJTextField;
62
63 // JButton to initiate calculate of user's bill
64 private JButton calculateJButton;
65
66 // no-argument constructor
67 public FuzzyDiceOrderForm()
68 {
69 createUserInterface();
70 }
71
72 // create and position GUI components; register event handlers
73 private void createUserInterface()
74 {
75 // get content pane for attaching GUI components
76 Container contentPane = getContentPane();
77
78 // enable explicit positioning of GUI components
79 contentPane.setLayout( null );
80
81 // set up fuzzyDiceJLabel
82 fuzzyDiceJLabel = new JLabel();
83 fuzzyDiceJLabel.setBounds( 137, 16, 235, 24 );
84 fuzzyDiceJLabel.setText( "Fuzzy Dice" );
85 fuzzyDiceJLabel.setFont(
86 new Font( "Default", Font.PLAIN, 22 ) );
87 contentPane.add( fuzzyDiceJLabel );
88
89 // set up orderNumberJLabel
90 orderNumberJLabel = new JLabel();
91 orderNumberJLabel.setBounds( 15, 65, 100, 16 );
92 orderNumberJLabel.setText( "Order Number:" );
93 contentPane.add( orderNumberJLabel );
94
95 // set up orderNumberJTextField
96 orderNumberJTextField = new JTextField();
97 orderNumberJTextField.setBounds( 111, 65, 48, 21 );
98 orderNumberJTextField.setText( "0" );
99 orderNumberJTextField.setHorizontalAlignment(
100 JTextField.RIGHT );
101 contentPane.add( orderNumberJTextField );
102
103 // set up nameJLabel
104 nameJLabel = new JLabel();
105 nameJLabel.setBounds( 15, 105, 40, 16 );
106 nameJLabel.setText( "Name:" );
107 contentPane.add( nameJLabel );
108
109 // set up nameJTextField
110 nameJTextField = new JTextField();
111 nameJTextField.setBounds( 111, 105, 245, 21 );
112 nameJTextField.setText( "Enter name here" );
113 contentPane.add( nameJTextField );
114
115 // set up addressJLabel
116 addressJLabel = new JLabel();
117 addressJLabel.setBounds( 15, 129, 56, 16 );
118 addressJLabel.setText( "Address:" );
119 contentPane.add( addressJLabel );
120
121 // set up addressJTextField1
122 addressJTextField1 = new JTextField();
123 addressJTextField1.setBounds( 111, 129, 245, 21 );
124 addressJTextField1.setText( "Address Line 1" );
125 contentPane.add( addressJTextField1 );
126
127 // set up addressJTextField2
128 addressJTextField2 = new JTextField();
129 addressJTextField2.setBounds( 111, 153, 245, 21 );
130 addressJTextField2.setText( "City, State, Zip" );
131 contentPane.add( addressJTextField2 );
132
133 // set up typeJLabel
134 typeJLabel = new JLabel();
135 typeJLabel.setBounds( 15, 204, 40, 16 );
136 typeJLabel.setText( "Type:" );
137 contentPane.add( typeJLabel );
138
139 // set up whiteTypeJCheckBox
140 whiteTypeJCheckBox = new JCheckBox();
141 whiteTypeJCheckBox.setBounds( 10, 227, 93, 21 );
142 whiteTypeJCheckBox.setText( "White/Black" );
143 contentPane.add( whiteTypeJCheckBox );
144
145 // set up redTypeJCheckBox
146 redTypeJCheckBox = new JCheckBox();
147 redTypeJCheckBox.setBounds( 10, 252, 88, 21 );
148 redTypeJCheckBox.setText( "Red/Black" );
149 contentPane.add( redTypeJCheckBox );
150
151 // set up quantityJLabel
152 quantityJLabel = new JLabel();
153 quantityJLabel.setBounds( 111, 204, 72, 16 );
154 quantityJLabel.setText( "Quantity:" );
155 contentPane.add( quantityJLabel );
156
157 // set up whiteQuantityJTextField
158 whiteQuantityJTextField = new JTextField();
159 whiteQuantityJTextField.setBounds( 111, 228, 64, 21 );
160 whiteQuantityJTextField.setText( "0" );
161 whiteQuantityJTextField.setHorizontalAlignment(
162 JTextField.RIGHT );
163 contentPane.add( whiteQuantityJTextField );
164
165 // set up redQuantityJTextField
166 redQuantityJTextField = new JTextField();
167 redQuantityJTextField.setBounds( 111, 252, 64, 21 );
168 redQuantityJTextField.setText( "0" );
169 redQuantityJTextField.setHorizontalAlignment(
170 JTextField.RIGHT );
171 contentPane.add( redQuantityJTextField );
172
173 // set up priceJLabel
174 priceJLabel = new JLabel();
175 priceJLabel.setBounds( 196, 204, 72, 16 );
176 priceJLabel.setText( "Price:" );
177 contentPane.add( priceJLabel );
178
179 // set up whitePriceJLabel
180 whitePriceJLabel = new JLabel();
181 whitePriceJLabel.setBounds( 196, 228, 80, 21 );
182 whitePriceJLabel.setText( "$6.25" );
183 contentPane.add( whitePriceJLabel );
184
185 // set up redPriceJLabel
186 redPriceJLabel = new JLabel();
187 redPriceJLabel.setBounds( 196, 252, 80, 21 );
188 redPriceJLabel.setText( "$5.00" );
189 contentPane.add( redPriceJLabel );
190
191 // set up totalsJLabel
192 totalsJLabel = new JLabel();
193 totalsJLabel.setBounds( 267, 204, 72, 16 );
194 totalsJLabel.setText( "Totals:" );
195 contentPane.add( totalsJLabel );
196
197 // set up whiteTotalsJTextField
198 whiteTotalsJTextField = new JTextField();
199 whiteTotalsJTextField.setBounds( 267, 228, 87, 16 );
200 whiteTotalsJTextField.setText( "$0.00" );
201 whiteTotalsJTextField.setEditable( false );
202 whiteTotalsJTextField.setHorizontalAlignment(
203 JTextField.RIGHT );
204 contentPane.add( whiteTotalsJTextField );
205
206 // set up redTotalsJTextField
207 redTotalsJTextField = new JTextField();
208 redTotalsJTextField.setBounds( 267, 252, 87, 16 );
209 redTotalsJTextField.setText( "$0.00" );
210 redTotalsJTextField.setEditable( false );
211 redTotalsJTextField.setHorizontalAlignment(
212 JTextField.RIGHT );
213 contentPane.add( redTotalsJTextField );
214
215 // set up subtotalJLabel
216 subtotalJLabel = new JLabel();
217 subtotalJLabel.setBounds( 196, 293, 72, 16 );
218 subtotalJLabel.setText( "Subtotal:" );
219 contentPane.add( subtotalJLabel );
220
221 // set up subtotalJTextField
222 subtotalJTextField = new JTextField();
223 subtotalJTextField.setBounds( 267, 293, 87, 16 );
224 subtotalJTextField.setText( "$0.00" );
225 subtotalJTextField.setEditable( false );
226 subtotalJTextField.setHorizontalAlignment(
227 JTextField.RIGHT );
228 contentPane.add( subtotalJTextField );
229
230 // set up taxJLabel
231 taxJLabel = new JLabel();
232 taxJLabel.setBounds( 196, 317, 72, 16 );
233 taxJLabel.setText( "Tax:" );
234 contentPane.add( taxJLabel );
235
236 // set up taxJTextField
237 taxJTextField = new JTextField();
238 taxJTextField.setBounds( 267, 317, 87, 16 );
239 taxJTextField.setText( "$0.00" );
240 taxJTextField.setEditable( false );
241 taxJTextField.setHorizontalAlignment(
242 JTextField.RIGHT );
243 contentPane.add( taxJTextField );
244
245 // set up discountJLabel
246 discountJLabel = new JLabel();
247 discountJLabel.setBounds( 196, 341, 72, 16 );
248 discountJLabel.setText( "Discount:" );
249 contentPane.add( discountJLabel );
250
251 // set up discountJTextField
252 discountJTextField = new JTextField();
253 di
You might also like to view...
Which of the following is used to interconnect locations inside a packet switching network?
a. a PAD b. a Node c. an IXC d. none of the above
Which of the following does not need to have a description clearly defining its purpose.
(a) A movie. (b) A sound file. (c) An ALT element. (d) An OBJECT element.
The standard copy/move commands can work on only one _______________ at a time.
A. directory B. file C. program D. prompt
To retrieve data from more than one table, you must ____________________ the tables together by finding rows in the two tables that have identical values in matching columns.
Fill in the blank(s) with the appropriate word(s).