/* Tony Antony * CSIT 210 - Apple IIc cashier program * Gets orders by clicking on child, medium, large or extra large buttons * Shows the total of each order * Gets money from the user * Shows how much change to give * Close out button have password 'Google' to show the totals for the day * If the password is wrong, show message to try again * Apple IIc Cashier Version 1.0, updated: 12/2/2013 */ package cashier; import java.text.NumberFormat; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPasswordField; public class main extends javax.swing.JFrame { public main() { initComponents(); childQuantity.setText(String.valueOf(childCounter)); mediumQuantity.setText(String.valueOf(mediumCounter)); largeQuantity.setText(String.valueOf(largeCounter)); exLargeQuantity.setText(String.valueOf(exLargeCounter)); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton3 = new javax.swing.JButton(); titleOne = new javax.swing.JLabel(); titleTwo = new javax.swing.JLabel(); sizeLabel = new javax.swing.JLabel(); quantityLabel = new javax.swing.JLabel(); paymentPanel = new java.awt.Panel(); subTotalLabel = new java.awt.Label(); taxLabel = new java.awt.Label(); totalLabel = new java.awt.Label(); paymentLabel = new java.awt.Label(); changeLabel = new java.awt.Label(); paymentTextField = new java.awt.TextField(); subTotal = new java.awt.Label(); tax = new java.awt.Label(); total = new java.awt.Label(); change = new java.awt.Label(); dollarLabel = new javax.swing.JLabel(); closeOutButton = new java.awt.Button(); saleCompleteButton = new java.awt.Button(); childButton = new javax.swing.JButton(); largeButton = new javax.swing.JButton(); mediumButton = new javax.swing.JButton(); exLargeButton = new javax.swing.JButton(); childQuantity = new javax.swing.JLabel(); largeQuantity = new javax.swing.JLabel(); mediumQuantity = new javax.swing.JLabel(); exLargeQuantity = new javax.swing.JLabel(); changeTitle = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); changeTextArea = new javax.swing.JTextArea(); jButton3.setText("Medium"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Apple IIc - POS System"); setBackground(new java.awt.Color(227, 227, 227)); setForeground(new java.awt.Color(105, 105, 105)); setResizable(false); titleOne.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N titleOne.setForeground(new java.awt.Color(0, 51, 153)); titleOne.setText("Apple IIc - POS System"); titleTwo.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N titleTwo.setForeground(new java.awt.Color(153, 0, 255)); titleTwo.setText("By: Tony Antony"); sizeLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N sizeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); sizeLabel.setText("Sizes"); quantityLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N quantityLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); quantityLabel.setText("Quantity"); paymentPanel.setBackground(new java.awt.Color(240, 240, 240)); subTotalLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N subTotalLabel.setText("Sub - Total"); taxLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N taxLabel.setText("Tax"); totalLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N totalLabel.setText("Total"); paymentLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N paymentLabel.setText("Payment"); changeLabel.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N changeLabel.setText("Change"); paymentTextField.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N paymentTextField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { paymentTextFieldActionPerformed(evt); } }); subTotal.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N tax.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N total.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N change.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N dollarLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N dollarLabel.setText("$"); javax.swing.GroupLayout paymentPanelLayout = new javax.swing.GroupLayout(paymentPanel); paymentPanel.setLayout(paymentPanelLayout); paymentPanelLayout.setHorizontalGroup( paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(paymentPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(paymentLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(subTotalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(taxLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(totalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(changeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(dollarLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(change, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(subTotal, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(tax, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(total, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(paymentTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))) .addGap(29, 29, 29)) ); paymentPanelLayout.setVerticalGroup( paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(paymentPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(subTotalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(subTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(taxLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(tax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(19, 19, 19) .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(totalLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(dollarLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(paymentLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(paymentTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) .addGroup(paymentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(changeLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(change, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(21, 21, 21)) ); closeOutButton.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N closeOutButton.setLabel("Close Out"); closeOutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeOutButtonActionPerformed(evt); } }); saleCompleteButton.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N saleCompleteButton.setLabel("Sale Complete"); saleCompleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saleCompleteButtonActionPerformed(evt); } }); childButton.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N childButton.setText("Child"); childButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { childButtonMouseClicked(evt); } }); largeButton.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N largeButton.setText("Large"); largeButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { largeButtonMouseClicked(evt); } }); mediumButton.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N mediumButton.setText("Medium"); mediumButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { mediumButtonMouseClicked(evt); } }); exLargeButton.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N exLargeButton.setText("Ex Large"); exLargeButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { exLargeButtonMouseClicked(evt); } }); childQuantity.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N childQuantity.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); childQuantity.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); largeQuantity.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N largeQuantity.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); largeQuantity.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); mediumQuantity.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N mediumQuantity.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); mediumQuantity.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); exLargeQuantity.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N exLargeQuantity.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); exLargeQuantity.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); changeTitle.setFont(new java.awt.Font("Dialog", 0, 14)); // NOI18N changeTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); changeTitle.setText("Change"); changeTextArea.setEditable(false); changeTextArea.setColumns(20); changeTextArea.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N changeTextArea.setRows(5); changeTextArea.setBorder(null); jScrollPane1.setViewportView(changeTextArea); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(mediumButton, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(largeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(exLargeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(childQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE) .addComponent(largeQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(exLargeQuantity, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(mediumQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(paymentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(sizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(childButton, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)) .addGap(18, 18, 18) .addComponent(quantityLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(titleOne) .addGroup(layout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(titleTwo))) .addGap(50, 50, 50) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(saleCompleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(27, 27, 27) .addComponent(closeOutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(67, 67, 67) .addComponent(changeTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))) .addContainerGap(14, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(titleOne) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(titleTwo)) .addComponent(closeOutButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(saleCompleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(sizeLabel) .addComponent(quantityLabel) .addComponent(changeTitle)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(childQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(childButton, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(mediumButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(mediumQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(largeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE) .addComponent(largeQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE) .addComponent(exLargeQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(19, 19, 19) .addComponent(jScrollPane1)))) .addComponent(exLargeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(paymentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(15, Short.MAX_VALUE)) ); pack(); }// </editor-fold> // things to do when the user enters amount on the payment text field private void paymentTextFieldActionPerformed(java.awt.event.ActionEvent evt) { double payment = Double.parseDouble(paymentTextField.getText()); paymentTextField.setText(fmt.format(payment)); finalChange = payment - allTotal; change.setText(String.valueOf(fmt.format(finalChange))); // calculation for getting dollars and cents separate int dollar, cent; double getCent; dollar = (int)finalChange % 1000000; getCent = Math.round((finalChange - dollar) * 100); cent = (int)(getCent); String text = ""; // number of 100 dollar if((dollar / 100) >= 1) { text = text + (dollar / 100 + "\t$100\n"); dollar = dollar - 100 * (dollar / 100); } // number of 50 dollar if((dollar / 50) >= 1) { text = text + (dollar / 50 + "\t$50\n"); dollar = dollar - 50 * (dollar / 50); } // number of 20 dollar if((dollar / 20) >= 1) { text = text + (dollar / 20 + "\t$20\n"); dollar = dollar - 20 * (dollar / 20); } // number of 10 dollar if((dollar / 10) >= 1) { text = text + (dollar / 10 + "\t$10\n"); dollar = dollar - 10 * (dollar / 10); } // number of 5 dollar if((dollar / 5) >= 1) { text = text + (dollar / 5 + "\t$5\n"); dollar = dollar - 5 * (dollar / 5); } // number of 2 dollar if((dollar / 2) >= 1) { text = text + (dollar / 2 + "\t$2\n"); dollar = dollar - 2 * (dollar / 2); } // number of 1 dollar if((dollar / 1) >= 1) { text = text + (dollar / 1 + "\t$1\n"); } // number of quarter if((cent / 25) >= 1) { text = text + (cent / 25 + "\t$0.25\n"); cent = cent - 25 * (cent / 25); } // number of dime if((cent / 10) >= 1) { text = text + (cent / 10 + "\t$0.10\n"); cent = cent - 10 * (cent / 10); } // number of nickel if((cent / 5) >= 1) { text = text + (cent / 5 + "\t$0.05\n"); cent = cent - 5 * (cent / 5); } // number of penny if((cent / 1) >= 1) { text = text + (cent / 1 + "\t$0.01\n"); } changeTextArea.setText(text); } // things to do when the sale complete button is clicked private void saleCompleteButtonActionPerformed(java.awt.event.ActionEvent evt) { // totaling the counts after each sale complete childFinalCount = childFinalCount + childCounter; mediumFinalCount = mediumFinalCount + mediumCounter; largeFinalCount = largeFinalCount + largeCounter; exLargeFinalCount = exLargeFinalCount + exLargeCounter; subTotalFinal = subTotalFinal + allSubTotal; taxFinal = taxFinal + allTax; totalFinal = totalFinal + allTotal; // resetting all values after each sale complete childCounter = 0; mediumCounter = 0; largeCounter = 0; exLargeCounter = 0; childQuantity.setText(String.valueOf(childCounter)); mediumQuantity.setText(String.valueOf(mediumCounter)); largeQuantity.setText(String.valueOf(largeCounter)); exLargeQuantity.setText(String.valueOf(exLargeCounter)); allSubTotal = 0; allTax = 0; allTotal = 0; subTotal.setText(String.valueOf(allSubTotal)); tax.setText(String.valueOf(allTax)); total.setText(String.valueOf(allTotal)); subTotal.setText(""); tax.setText(""); total.setText(""); change.setText(""); paymentTextField.setText(""); changeTextArea.setText(""); } // things to do when the child button is clicked private void childButtonMouseClicked(java.awt.event.MouseEvent evt) { childCounter++; childQuantity.setText(String.valueOf(childCounter)); int child; child = Integer.parseInt(childQuantity.getText()); allSubTotal = allSubTotal + CHILD_RATE; allTax=0; allTax = allTax + (allSubTotal * MD_STATE_TAX); allTotal = allSubTotal + allTax; subTotal.setText(String.valueOf(fmt.format(allSubTotal))); tax.setText(String.valueOf(fmt.format(allTax))); total.setText(String.valueOf(fmt.format(allTotal))); } // things to do when the medium button is clicked private void mediumButtonMouseClicked(java.awt.event.MouseEvent evt) { mediumCounter++; mediumQuantity.setText(String.valueOf(mediumCounter)); int medium; medium = Integer.parseInt(mediumQuantity.getText()); allSubTotal = allSubTotal + MEDIUM_RATE; allTax=0; allTax = allTax + (allSubTotal * MD_STATE_TAX); allTotal = allSubTotal + allTax; subTotal.setText(String.valueOf(fmt.format(allSubTotal))); tax.setText(String.valueOf(fmt.format(allTax))); total.setText(String.valueOf(fmt.format(allTotal))); } // things to do when the large button is clicked private void largeButtonMouseClicked(java.awt.event.MouseEvent evt) { largeCounter++; largeQuantity.setText(String.valueOf(largeCounter)); int large; large = Integer.parseInt(largeQuantity.getText()); allSubTotal = allSubTotal + LARGE_RATE; allTax=0; allTax = allTax + (allSubTotal * MD_STATE_TAX); allTotal = allSubTotal + allTax; subTotal.setText(String.valueOf(fmt.format(allSubTotal))); tax.setText(String.valueOf(fmt.format(allTax))); total.setText(String.valueOf(fmt.format(allTotal))); } // things to do when the extra large button is clicked private void exLargeButtonMouseClicked(java.awt.event.MouseEvent evt) { exLargeCounter++; exLargeQuantity.setText(String.valueOf(exLargeCounter)); int exLarge; exLarge = Integer.parseInt(exLargeQuantity.getText()); allSubTotal = allSubTotal + EX_LARGE_RATE; allTax=0; allTax = allTax + (allSubTotal * MD_STATE_TAX); allTotal = allSubTotal + allTax; subTotal.setText(String.valueOf(fmt.format(allSubTotal))); tax.setText(String.valueOf(fmt.format(allTax))); total.setText(String.valueOf(fmt.format(allTotal))); } // things to do when the user click the close out button private void closeOutButtonActionPerformed(java.awt.event.ActionEvent evt) { // creates a panel, and password field and puts inside the message dialog JPanel passwordPanel = new JPanel(); JPasswordField password = new JPasswordField(10); passwordPanel.add(password); JOptionPane.showMessageDialog(null,passwordPanel,"Enter password",JOptionPane.QUESTION_MESSAGE); // thigs to do if the password is 'Google' if(password.getText().equals("Google")) { changeTitle.setVisible(false); changeTextArea.setVisible(false); paymentLabel.setVisible(false); changeLabel.setVisible(false); dollarLabel.setVisible(false); paymentTextField.setVisible(false); childQuantity.setText(String.valueOf(childFinalCount)); mediumQuantity.setText(String.valueOf(mediumFinalCount)); largeQuantity.setText(String.valueOf(largeFinalCount)); exLargeQuantity.setText(String.valueOf(exLargeFinalCount)); subTotal.setText(String.valueOf(fmt.format(subTotalFinal))); tax.setText(String.valueOf(fmt.format(taxFinal))); total.setText(String.valueOf(fmt.format(totalFinal))); } // if the password is not 'Google' show message saying incorrect password else { JOptionPane.showMessageDialog(null, "Incorrect password, try again!"); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new main().setVisible(true); } }); } // currency format NumberFormat fmt = NumberFormat.getCurrencyInstance(); // setting initial values final double MD_STATE_TAX = 0.06; final double CHILD_RATE = 0.90; final double MEDIUM_RATE = 1.40; final double LARGE_RATE = 1.75; final double EX_LARGE_RATE = 2.00; private double allSubTotal = 0; private double allTax = 0; private double allTotal = 0; private double finalChange; private int childCounter = 0; private int mediumCounter = 0; private int largeCounter = 0; private int exLargeCounter = 0; private int childFinalCount = 0; private int mediumFinalCount = 0; private int largeFinalCount = 0; private int exLargeFinalCount = 0; private double subTotalFinal = 0; private double taxFinal = 0; private double totalFinal = 0; // Variables declaration - do not modify private java.awt.Label change; private java.awt.Label changeLabel; private javax.swing.JTextArea changeTextArea; private javax.swing.JLabel changeTitle; private javax.swing.JButton childButton; private javax.swing.JLabel childQuantity; private java.awt.Button closeOutButton; private javax.swing.JLabel dollarLabel; private javax.swing.JButton exLargeButton; private javax.swing.JLabel exLargeQuantity; private javax.swing.JButton jButton3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton largeButton; private javax.swing.JLabel largeQuantity; private javax.swing.JButton mediumButton; private javax.swing.JLabel mediumQuantity; private java.awt.Label paymentLabel; private java.awt.Panel paymentPanel; private java.awt.TextField paymentTextField; private javax.swing.JLabel quantityLabel; private java.awt.Button saleCompleteButton; private javax.swing.JLabel sizeLabel; private java.awt.Label subTotal; private java.awt.Label subTotalLabel; private java.awt.Label tax; private java.awt.Label taxLabel; private javax.swing.JLabel titleOne; private javax.swing.JLabel titleTwo; private java.awt.Label total; private java.awt.Label totalLabel; // End of variables declaration }
Monday, December 9, 2013
Apple IIc Point of Sale GUI
Subscribe to:
Posts (Atom)