Validate_Money_Class
1| /*
2| NTC Java Programming 152-116
3| Instructor: John Heckendorf
4| Student: Jan Young & Keith Gallistel
5| Lab ID:
6| Project:pepsi.java
7| */
8|
9| import javax.swing.*;
10| import java.util.*;
11| import java.awt.*;
12|
13| public class Validate_Money_Class
14| {
15| final static long serialVersionUID = 5;
16|
17| Control_Class oC;
18|
19| int iBinIndex = 0;
20| double dPrice = 0;
21| int iQty = 0;
22|
23| //Instantiated Class
24| public Validate_Money_Class(Control_Class oControl)
25| {
26| oC = oControl;
27| }
28|
29| //Validate Money Method
30| public boolean Validate_Money()
31| {
32| boolean bGood = true;
33|
34| boolean bValid = false;
35| boolean bLEFive = false;
36| boolean bExactChange = false;
37| boolean bChangeBinNoOdd = false;
38| boolean bInvalid = false;
39|
40| double dMoneyConvert = 0;
41| double dTotAcum = 0;
42|
43| Formatter oF = new Formatter();
44|
45| bValid = Valid_Money(oC.jtxtMoney);
46| bLEFive = LT_EQ_Five(oC.jtxtMoney);
47| bExactChange = Exact_Change(iBinIndex, oC.jtxtMoney, oC.jrbnExactChange);
48| bChangeBinNoOdd = Change_No_Odd(oC.jbtnChangeBin);
49| bInvalid = Change_Full_Money_Odd(oC.jtxtMoney, oC.jbtnChangeBin);
50|
51|
52| if(bValid && bLEFive && bExactChange)
53| {
54| dMoneyConvert = Double.parseDouble(oC.jtxtMoney.getText());
55| dTotAcum = Accumulate_Money(dMoneyConvert, oC.oMoney);
56| oF.format("%,.2f", dTotAcum);
57| oC.jtxtMoneyDisplay.setText(oF.toString());
58| oC.jtxtMoney.setText(null);
59| }
60| else
61| {
62| if(bChangeBinNoOdd && bInvalid)
63| {
64| bGood = false;
65| oC.jbtnChangeBin.setText(oC.jtxtMoney.getText());
66| oC.jtxtMoney.setText(null);
67| }
68| else
69| {
70| bGood = false;
71| oC.jbtnChangeBin.setBackground(Color.RED);
72| }
73| }
74|
75|
76| return bGood;
77|
78| }
79|
80| //Validate whether money is good
81| private boolean Valid_Money(JTextField JTF)
82| {
83| boolean bVM = false;
84| double dData = 0;
85|
86| try
87| {
88| dData = Double.parseDouble(JTF.getText());
89| bVM = true;
90| }
91| catch(NumberFormatException e)
92| {
93| bVM = false;
94| }
95|
96| return bVM;
97| }
98|
99| //Validate if money is less than or equal to $5.00
100| private boolean LT_EQ_Five(JTextField JTF)
101| {
102| boolean bLEF = false;
103| double dData = 0;
104|
105| try
106| {
107| dData = Double.parseDouble(JTF.getText());
108| }
109| catch(NumberFormatException e)
110| {
111| bLEF = false;
112| }
113|
114| if(dData <= 5)
115| {
116| bLEF = true;
117| }
118|
119| return bLEF;
120| }
//Validate whether you need to use exact change
123| private boolean Exact_Change(int iBI, JTextField JTF, JRadioButton JRB)
124| {
125| boolean bEC = false;
126| double dData = 0;
127| double dPrice = 0;
128|
129| String sBI = "";
130| String sQ = "";
131|
132| sBI = Integer.toString(iBI);
133| sQ ="SELECT * FROM Products WHERE pm_bin_number = " + sBI + ";";
134|
135| DB_Interface oDBI = new DB_Interface();
136| oDBI.Query(sQ);
137|
138| dPrice = oDBI.dPrice;
139|
140| try
141| {
142| dData = Double.parseDouble(JTF.getText());
143| }
144| catch(NumberFormatException e)
145| {
146|
147| }
148|
149| if(JRB.isSelected() == true)
150| {
151| if(dPrice == dData)
152| {
153| bEC = true;
154| }
155| }
156| else
157| {
158| bEC = true;
159| }
160|
161| return bEC;
162| }
163|
164| //Validate if change is money or garbage
165| private boolean Change_No_Odd(JButton jbtnChangeBin)
166| {
167| boolean bVM = false;
168| double dData = 0;
169|
170| if(jbtnChangeBin.getText() != "Change")
171| {
172| try
173| {
174| dData = Double.parseDouble(jbtnChangeBin.getText());
175| bVM = true;
176| }
177| catch(NumberFormatException e)
178| {
179| bVM = false;
180| }
181| }
182| else
183| {
184| bVM = true;
185| }
186|
187| return bVM;
188| }
189|
190| //Validate if change bin is full and money is garbage
191| private boolean Change_Full_Money_Odd (JTextField JTF, JButton JBTN)
192| {
193| boolean bOdd = false;
194| double dData = 0;
195|
196| if(JBTN.getText() != "Change")
197| {
198| try
199| {
200| dData = Double.parseDouble(JTF.getText());
201| bOdd = true;
202| }
203| catch(NumberFormatException e)
204| {
205| bOdd = false;
206| }
207| }
208| else
209| {
210| bOdd = true;
211| }
212|
213| return bOdd;
214| }
215|
216| //Accumulate the money in the bank
217| private double Accumulate_Money(double dMoney, Money_Class oMoney)
218| {
219| double dReturn = 0;
220|
221| oMoney.Accumulate_Current(dMoney);
222|
223| dReturn = oMoney.Get_Current();
224|
225| return dReturn;
226| }
227| }