Campus store program,help!

Hi Folks,
I have a probem with the following code. I am new to Java Programmimg. Can anybody help me please!
This application launches a window where the sales person can enter the items purchased. At the click of Next Item( b1), the screen is cleared to enter the next item and the transaction is processed. when receipt i(b2)s clicked, the details of the transactions are displayed. When summary button is clicked(b3) the details of the day's total transactions are displays. I have the following problems.
The title of the receipt is not displayed once the receipt textarea is cleared, but the transaction is displayed. I also stored the cost in a variable called Tcost (Tcost = Tcost + cost). I initilized Tcost = 0.0 It either displays the cost or 0.0 value but not the total cost. I am able to display the summary but when i click the 2nd time, it displays twice.
How do I calculate the total tax for the summary report and Cost and tax in receipt?
Please help!
Thanks.
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class ProductFrame1 extends JFrame implements ActionListener
     private JLabel label;
     private JLabel label1;
     private JLabel label2;
     private JTextField text1;
     private JTextField text2;
     private JTextArea receipt;
     private JTextArea sum;
     private JButton b1;
     private JButton b2;
     private JButton b3;
     double summary[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
     int prdcode[] = {100,200,300,400,500,600};
     String item[] = {"White Bandana ", "Green License Plate",
"Green Sweat Shirt ", "Low Profile hat ", "Gym Shorts ",
"Printed Golf Balls "};
     double unitprice[] = {4.98, 5.99, 24.99,17.98,16.98,8.99};
     double salestax [] = {0.0,3.5,7.2,4.0,4.2,0.0};
     public ProductFrame1()
          super( "CAMPUS STORE");
          setLayout( new FlowLayout
FlowLayout.CENTER,200,10));
          label = new JLabel("CAMPUS STORE");
          add(label);
          label1 = new JLabel("Product code:");
          add(label1);
          text1 = new JTextField( 3 );
          add(text1);
     label2 = new JLabel(" Quantity: ");
          add(label2);
          text2 = new JTextField( 4 );
          add(text2);
          b1 = new JButton("Next Item");
          add(b1);
          b2 = new JButton("Receipt");
          add(b2);
          b3 = new JButton("Summary");
          add(b3);     
          receipt = new JTextArea(20,35);
     receipt.append(" Campus Store Sales Receipt \n\n");
          receipt.append(" ItemName\t\tQuantity\tUnitPrice\tCost \n");
          sum = new JTextArea(20,35);
          sum.append(" Campus shop Daily Sales Summary \n\n");
          sum.append(" Items\t\t\tSales \n");
          //register event handlers
          text1.addActionListener( this );
          text2.addActionListener( this );
          b1.addActionListener( this );
          b2.addActionListener( this );
          b3.addActionListener( this );
     public int Search( int arr[], int key)
          for(int c=0; c<arr.length;c++)
               if(arr[c] == key)
               return c;
          return -1;
     public void actionPerformed( ActionEvent event )
          String string = "";     
          int row,qty1;     
          String rectotal;
          String output;
          double Tcost = 0.0;          
          double cost;
          double tax = 0.0;
          double total = 0.0;     
          if (event.getSource() == b1)
          row = Search( prdcode, Integer.parseInt(text1.getText()));
          qty1 = Integer.parseInt( text2.getText());
     cost = qty1* unitprice[row];
          //Tcost = Tcost + cost;
// accumulate receipt totals as well as summary total
     summary[row] = summary[row] + cost;
               //tax[row] = tax[row]
     receipt.append( item[row] + "\t" + qty1 + "\t" + unitprice[row] + "\t" + cost + "\n");
     //receipt.append("\t\t\t\t" + Double.toString(Tcost) + "\n");
          //tax = tax + salestax[row];
          text1.setText("");
          text2.setText("");     
          else
          if(event.getSource() == b2)
          receipt.append( "\t\t\t\t-----------\n");
          receipt.append( "\t\t\tTotal Tax \n");
          receipt.append( "\t\t\t\t-----------\n");
          receipt.append( "\t\t\tTotal \n");
// display receipt in JOptionPane
          JOptionPane.showMessageDialog(null, add(receipt));     
// clear textarea as well reset receiptotals = 0
          receipt.setText("");
          else
          if(event.getSource() == b3)
          // write the content of summary array to sum     
          for (int i=0;i<summary.length;i++)
          sum.append(item[i] + "\t" + "\t" + "%summary[i] + "\n");
          for (int j=0; j<summary.length;j++)
          total = total + summary[j];
          sum.append("--------------------------------------------------------------------------------\n");
          sum.append("Total Sales\t\t\t" + total +"\n");
          sum.append("Total Tax \t\t\t\n");
          sum.append("\t\t\t---------------\n");
          sum.append("Total \n");
          JOptionPane.showMessageDialog(null, add(sum));     }               
}

can you please repost your code withing code tags

Similar Messages

  • I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    Have you tried repairing disk permissions : iTunes download error -45054

  • The pass 4 days now my iTunes Store is not responding, when I reload it all that comes up is a blank white page that says iTunes Store. Help please!!!! Cannot load my gift card to buy music and such!!!

    The pass 4 days now my iTunes Store is not responding, when I reload it all that comes up is a blank white page that says iTunes Store. Help please!!!! Cannot load my gift card to buy music and such!!!

    I tookyour suggestion and SUCCESS!  I can now access the Itunes Store.  A simple fix, and thanks so much!!.
    Below is the advice you forwarded:
    I found a solution to my problem.
    > start menu
    > accessories,
    > right click on the command prompt icon and choose "run as administrator".
    Once it opens, type in the following command...
    netsh winsock reset
    hit enter
    You should get a message that the winsock reset successful and you will need to reboot your computer.
    Reboot and when I reloaded itunes the store loaded fine.
    Thanks again, -Dean Stoneburner

  • HT4859 The guy at the verizon store programmed my phone before I got the chance to restore my apps, etc. from icloud- therefore i did not get to go through the setup assistant..  How do i get my apps and app data back on my phone w/o having to go through

    The guy at the verizon store programmed my phone before I got the chance to restore my apps, etc. from icloud- therefore i did not get to go through the setup assistant..  How do i get my apps and app data back on my phone w/o having to go through and re-

    To restore from an iCloud backup you have to erase the phone and start over.  To do this, go to Settings>General>Reset, tap Erase All Content and Settings, then go through the setup assistant again and when given the option, choose Restore from iCloud Backup.  There is no other way to do this.
    Be sure you phone is connected to wifi and your charger as this is likely to take some time to finish.

  • When i open itunes its normal and then out of nowhere it says "itunes has stopped working" and i have to click 'close program'. help?

    when i open itunes its normal and then out of nowhere it says "itunes has stopped working" and i have to click 'close program'. help?

    Having the same issue here....a quick fix is to just minimize the window, and immediately maximize it.  It will now fit the screen.  Trouble is, after you close it, you'll have to do it again when you re-start itunes.  The good news is it takes all of about 2 seconds.  Apple should fix this.  Should.

  • I have a ipod touch 2nd generation 8gb 4.2.1 im new to itunes i made a itunes account but it says i need a payment method is there anyway i can use my paypal if not is there a way to not have to use a payment method for itunes store please help ty

    i have a ipod touch 2nd generation 8gb 4.2.1 im new to itunes i made a itunes account but it says i need a payment method is there anyway i can use my paypal if not is there a way to not have to use a payment method for itunes store please help ty

    Create a NEW account using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    Using those instructions you may also be able to select PayPal if that is allowed in your country.

  • Black background in Itunes Store and help

    Hello,
    I have a problem with Itunes on this Windows Vista pc. I get a black background on the store and help, and was unable to change payment information due to unvissible black list for creditcard dates. The help just does not display text.
    I have already tried  to reinstall multiple times.
    Also I tried another windows vista pc which was ok on the same apple id.
    Also Itunes crashes pretty often
    Now I am running out of ideas and i hope you can help me.
    Thanks in advance
    Ama

    With that one, perhaps try Drgoo's suggestion from the following post:
    Re: Itunes Store - ALL Text Black/Cant See Anything

  • Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?

    Programming help - how to get the read-only state of PDF file is windows explorer preview is ON?
    I'm developing an application where a file is need to be saved as pdf. But, if there is already a pdf file with same name in the specified directory, I wish to overwrite it. And in the overwrite case, read-only files should not be overwritten. If the duplicate(old) file is opened in windows (Win7) explorer preview, it is write protected. So, it should not be overwritten. I tried to get the '
    FILE_ATTRIBUTE_READONLY' using MS API 'GetFileAttributes', but it didn't succeed. How Adobe marks the file as read-only for preview? Do I need to check some other attribute of the file?
    Thanks!

    Divya - I have done it in the past following these documents. Please read it and try it it will work.
    Please read it in the following order since both are a continuation documents for the same purpose (it also contains how to change colors of row dynamically but I didnt do that part I just did the read_only part as your requirement) 
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b71393
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0155eb5-b6ce-2b10-3195-d9704982d69b?quicklink=index&overridelayout=true
    thanks!
    Jason PV

  • Blank screen in itunes store-please help im not very technical and when i click on my itunes app the screen is blank how can i fix this please?

    Blank screen in itunes store-please help im not very technical and when i click on my itunes app the screen is blank how can i fix this please?

    See if any of the following fix it.
    Try logging out of your account on your phone by tapping on your id in Settings > iTunes & App Store and tap 'Sign Out' on the popup and then log back in.
    If that doesn't fix it then try closing the iTunes store app via the phone's multitasking bar and see if it works properly when you open the app : double-click the home button to open the taskbar and then swipe or drag iTunes from there up and off the top of the screen to close it, and the click the home button to close the taskbar.
    A third thing to try is a soft-reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the equivalent of a reboot.

  • I recently purchased this 21.5 inch iMac in the month of February. The woman that helped me through the process of purchasing this told me that it comes with the latest Mountain Lion. which it did, but i cant write a review in the app store! Help...

    II recently purchased this 21.5 inch iMac in the month of February. The woman that helped me through the process of purchasing this told me that it comes with the latest Mountain Lion. which it did, but i cant write a review in the app store! Help...

    You want to write a review about Mountain Lion? I'm not sure that you can write about the OS at the app store - it's not an app. Or are you talking about the online Apple store? If you want to send feedback to Apple, you could use this:
    http://www.apple.com/feedback/macosx.html

  • I have an app in my app store that is requiring an update but I never purchased the app and when I click update, another apple ID pops up that is not mine.  Now i keep getting reminders to update the app and I cant get rid of it from the app store.  Help.

    I have an app in my app store that is requiring an update but I never purchased the app and when I click update, another apple ID pops up that is not mine.  Now i keep getting reminders to update the app and I cant get rid of it from the app store.  Help.

    You installed a hacked app, originally from the Mac App Store. It contains the receipt for a different app, downloaded using an account that you don't control. You need to identify and remove the hacked app.
    Important: The app you need to remove is not necessarily the one named in the App Store notice. For example, if the App Store says you need to update "Twitter," the hacked app may be "Angry Birds" or something else entirely. Don't make any assumptions about which app you're looking for. To find it, you have to carry out a systematic search.
    Triple-click anywhere in the line of text below on this page to select it:
    kMDItemAppStoreHasReceipt=1
    Copy the selected text to the Clipboard (command-C).
    In the Finder, press the key combination command-F to open a search window, or select
    File ▹ Find
    from the menu bar. In the search window, select
    Search: This Mac
    from the row of tokens below the toolbar. Below that is a popup menu initially showing Kind. From that menu, select  Other...
    A sheet will drop down. In that sheet, select Raw Query and click OK or press return.
    Now there will be a text box to the right of popup menu. Click in that box and paste (command-V).
    The search window will show all the App Store products you've installed. Compare those search results with the list of your purchases from the App Store. To see the complete list, you may need to unhide hidden purchases. If any apps were download from the App Store using other Apple ID accounts that you control, sign in to the store under each of those ID's and check the purchases.
    At least one of the items listed in the search window is not among your purchases in the App Store. Move each such item to the Trash. You may be prompted for your administrator password. Empty the Trash.
    Log out and log back in. Test.

  • I need to swich from us store to saudi arabian store, please help me to find solution.

    i need to swich from us store to saudi arabian store, please help me to find solution.

    See  >  Change your iTunes Store country
    Here  >  http://support.apple.com/kb/HT1311

  • Freely Programmed help in Pop Up Window

    Hi,
      Is it possible to display the data of freely programmed help in the pop up window.
    Thanks
    Raghavendra

    Hi Thomas,
       I agree that by using Freely Programmed help the data will be displayed in a seperate window. I want to display the data in a window( of type Pop Up) because i am displaying table control with 3 fields on clicking f4 and it has 2 buttons Ok and Cancel. But if there are 50 entries the user needs to scroll down to click on Ok. If the window is of type pop up Ok button will be embedded in the window instead of on view.
    Thanks
    Raghavendra

  • Freely programmed help in ALV

       HI:ALL
          How to achieve  Freely programmed help in ALV?

    Hi,
    On APPLY buttton action, write the below code
    *Fire the event to indicate that data selection is done
    wd_comp_controller->fire_vh_data_selected_evt( ).
    wd_comp_controller->value_help_listener->close_window( ).
    *Raise Event
       cl_fpm_factory=>get_instance( )->raise_event_by_id( EXPORTING   iv_event_id   = '<custom event name>').
    And in PROCESS_EVENT of your webdynpro component(where Freely Programmed search help is implemented) write the code as per your requirement to set the values back to the table.
    CASE IO_EVENT->MV_EVENT_ID.
              WHEN '<CUSTOM EVENT NAME>'.
                        write code as per your requirement.
    ENDCASE.
    Thanks
    KH

  • Why is it that I can't sign in on facetime, but I can sign in on app.store? With facetime,I'm getting an error, invalid username and password eventhough I have typed exactly the same when I'm signing in on the app.store. pls.help, thanks

    Why is it that I can't sign in on facetime, but I can sign in on app.store? With facetime,I'm getting an error, invalid username and password eventhough I have typed exactly the same when I'm signing in on the app.store. pls.help, thanks

    1. Make sure software is up to date
    2. Make sure FaceTime is enabled; Settings>FaceTime
    3. Make sure Date and Time is correctly set; Settings>General>Date and Time>Set Automatically>On
    4. Make sure Push Notification is enabled
    5. Make sure phone number or email address is correct
    6. Hold the Sleep and Home button down (together) until you see the Apple Logo

Maybe you are looking for