Created
November 2, 2012 07:21
-
-
Save TabsPH/3999227 to your computer and use it in GitHub Desktop.
Simple Cashiering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import javax.swing.*; | |
import java.awt.event.*; | |
public class simpleCashiering extends JFrame implements ActionListener { | |
private String[] strItems = { "SBW Huawei E1550 $ 850", | |
"SmartBro ZTE MF627 $ 800", | |
"HP Deskjet D2360 $ 2000", | |
"Flash Drive (2GB) $ 300", | |
"PSU 600watts $ 800", | |
"HDD Enclosure $ 3000 ", | |
"HardDisk (600GB) $ 4500", | |
"Computer Casing $ 5000", | |
"LCD Monitor 17inch $ 3500", | |
"Extension Cable $ 400" }; | |
private double[] itemPrice = { 850, 800, 2000, 300, 800, | |
3000, 4500, 5000, 3500, 400 }; | |
private JList<String> lstItems = new JList<String>( strItems ); | |
private Container container = getContentPane(); | |
private JTextArea billTA = new JTextArea( 10,41 ); | |
private JButton resetB, computeB; | |
private JPanel panel = new JPanel(); | |
private JLabel lblHeader; | |
public simpleCashiering(){ | |
setPane(); | |
setJFrame(); | |
} | |
public void setPane(){ | |
lblHeader = new JLabel( "Simple Cashiering" ); | |
lblHeader.setFont( new Font( "Dialog", Font.BOLD, 20) ); | |
lblHeader.setHorizontalAlignment( JLabel.CENTER ); | |
container.add( lblHeader, BorderLayout.NORTH ); | |
lstItems.setFont( new Font("Courier", Font.PLAIN, 12) ); | |
container.add( new JScrollPane(lstItems), BorderLayout.WEST ); | |
billTA.setFont( new Font("Courier", Font.PLAIN, 12) ); | |
container.add( new JScrollPane(billTA), BorderLayout.EAST ); | |
computeB = new JButton( "Compute" ); | |
resetB = new JButton( " Reset " ); | |
computeB.addActionListener(this); | |
resetB.addActionListener(this); | |
panel.add(computeB); | |
panel.add(resetB); | |
container.add( panel, BorderLayout.SOUTH ); | |
} | |
public void actionPerformed(ActionEvent ae){ | |
if( ae.getSource() == computeB) | |
displayBill(); | |
else{ | |
lstItems.clearSelection(); | |
billTA.setEditable( true ); | |
billTA.setText( "" ); | |
repaint(); | |
} | |
} | |
public void setJFrame(){ | |
setTitle( "Simple Cashiering by Tabs" ); | |
setSize( 500, 360 ); | |
setResizable( false ); | |
setVisible( true ); | |
setDefaultCloseOperation( EXIT_ON_CLOSE ); | |
setLocationRelativeTo( null ); | |
} | |
public void displayBill(){ | |
int[] selectedItems = lstItems.getSelectedIndices(); | |
final double localTax = 0.065; | |
double subTotal = 0.0; | |
double tax = 0.0; | |
double total = 0.0; | |
billTA.setText( "" ); | |
billTA.append( " SIMPLE CASHIERING BY TABS\n\n"); | |
billTA.append( "---------------- WELCOME ----------------\n\n" ); | |
for(int i=0; i<selectedItems.length; i++){ | |
billTA.append( strItems[ selectedItems[i] ] + "\n"); | |
subTotal += itemPrice[ selectedItems[i] ] ; | |
} | |
tax = localTax * subTotal; | |
total = tax + subTotal; | |
billTA.append( String.format( "%nSUB TOTAL\t\t $ %.2f", subTotal ) ); | |
billTA.append( String.format( "%nTAX \t\t $ %.2f", tax ) ); | |
billTA.append( String.format( "%nTOTAL \t\t $ %.2f", total ) ); | |
billTA.append( "\n\n\nThank You -- Have a Nice Day"); | |
billTA.setEditable( false ); | |
} | |
public static void main(String[] args) { | |
new simpleCashiering(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment