A CRY OF Help..To All Java Programmer

Iam desperate please help....I Have to finish this code until tommorrow...i have done some and its running but it doesnt show the right computation...
Prob:
Mail order house sells 5 different product..prod1-$2.98, prod2-$4.50, prod3- $9.98, prod4- $4.49 and prod 5- $6.87..Write an application that reads a series of pairs of numbers as follows:
a)Product number
b)Quantity sold for one day
Program should use a switch structure to help determine the retail price for each product.Your program should calculate and display total retail value of all product sold last week. Use a TextField to obtain the product number from the user. Use sentinel -controlled loop to determine when the product should stop looping and display final results.
Note: I change temporarily the product because I am not familiar with double data types..
this is the code i have currently done..Please.please.please i need all the help..
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class ProbMod {
     public static void main( String args[] )
          int quant,
               prodnum,
               Counter,total,input,lahatna,prodquan,
               gtotal;           
          double      
                    average;
          String
                    num1,
                    num2;
          total = 0;
          Counter = 0;
          gtotal = 1;
          input = 0;
          lahatna = 0;
          prodquan = 0;
               num1= JOptionPane.showInputDialog( "Enter Product Number, -1 to Quit");
               prodnum = Integer.parseInt(num1);
          while (prodnum != -1) {
          switch ( prodnum ) {
               case 1:
                    JOptionPane.showMessageDialog(null, "1 - $2.98");
                    break;
               case 2:
                    JOptionPane.showMessageDialog(null, "2 - $4.50");
                    break;
               case 3:
                    JOptionPane.showMessageDialog(null, "3 - $9.98");
                    break;
               case 4:
                    JOptionPane.showMessageDialog(null, "4 - $4.49");     
                    break;
               case 5:
                    JOptionPane.showMessageDialog(null, "5 - $6.87");     
                    break;
               default:
                    JOptionPane.showMessageDialog(null, "Invalid value entered" );     
                    break;
               }//end switch
               num2= JOptionPane.showInputDialog( "Enter Quantity, -1 to Quit");
               quant = Integer.parseInt(num2);
               num1= JOptionPane.showInputDialog( "Enter Product Number, -1 to Quit");
               prodnum = Integer.parseInt(num1);
               if (prodnum == 1) {
                    input = quant * 239;
               else if (prodnum == 2) {
                    input = quant * 129;     
               else if (prodnum == 3) {
                    input = quant * 99;
               else if (prodnum == 4) {
                    input = quant * 350;
               else if (prodnum == 5) {
                    input = quant * 350;
               }//endif
               gtotal = input + 0;
               Counter = Counter + 1;
          } //end while
          DecimalFormat twoDigits = new DecimalFormat( "0.00");
          if ( Counter != 0) {
          //     average = (double) total/ Counter;
               lahatna = lahatna + gtotal;
               JOptionPane.showMessageDialog(null, "Retail Total " + twoDigits.format( lahatna ),
               "Mail Order House",JOptionPane.INFORMATION_MESSAGE );
          else
          JOptionPane.showMessageDialog( null,"No Product number entered", " ",JOptionPane.INFORMATION_MESSAGE );
          System.exit( 0 );

Hi.
I hope the class below meets your needs. Please note that I didn't spend too much time testing it and that I cannot guarantee that it works perfectly. At least it should calculate the correct results for the input values.
public class ProbMod {
    public ProbMod() {
    public static void main(String[] args) {
        int productNumber = 0;
        int soldAmount = 0;
        double price = 0.0;
        int counter = 0;
        double total = 0.0;
        do {
            try {
                productNumber = Integer.parseInt(JOptionPane.showInputDialog("Enter product number (-1 to quit)"));
                switch( productNumber ) {
                    case -1:
                        break;
                    case 1:
                        price = 2.98;
                        break;
                    case 2:
                        price = 4.5;
                        break;
                    case 3:
                        price = 9.98;
                        break;
                    case 4:
                        price = 4.49;
                        break;
                    case 5:
                        price = 6.87;
                        break;
                    default:
                        JOptionPane.showMessageDialog(null, "You have entered an invalid product number. Please try again.");
                        throw new Exception("");
                if( productNumber != -1 ) {
                    soldAmount = Integer.parseInt(JOptionPane.showInputDialog("Enter quantity"));
                    total += (double)soldAmount * price;
                    counter++;
            } catch( NumberFormatException e1 ) {
                JOptionPane.showMessageDialog(null, "You have entered a non numeric value. Please try again.");
                productNumber = 0;
            } catch( Exception e2 ) {
                productNumber = 0;
        } while( productNumber != -1 );
        JOptionPane.showMessageDialog(null, "Retail total (" + String.valueOf(counter) + " product(s)): " + new DecimalFormat("0.00").format(total));
}Regards,
Kai

Similar Messages

  • Help needed - beginner Java programmer using SUN JDK1.5.0

    I have three intacting classes called CalculatorInterface.java which calls methods in Client.java and Account.java.
    CalculatorInterface-->Client (arrays of objects) c[ ]-->Account (arrays of objects a[ ] linked to c[ ]
    The problem description :
    I have in CalculatorInterface.java
    public class CalculatorInterface
    // reference to class Client
    private static final int maxClients = 4;
    // constructor for client[] object array
    private static client[] c = new client[maxClients];
    private static int total,atotal;
    private static int noClients;
    etc
    etc
    public static void main (String[] args)
    parameter definitions
    code lines
    c[noClients] = new client();
    / creates a new instance of client contained in c[]
    total = noClients;
    code lines
    method calls
    noClients++; // next c[]
    termination
    } // end of Main
    CalculatorInterface Methods including
    void WhatIsLeft()
    ... code ...
    ....code...
    c[total].getAccount(atotal).setAmount_IS_Surplus(c[total].calcWeeklySurplus(salaryYrly,weeklyExpenses,isRes));
    ... code...
    The line of code returns a NullPointerException and crashes the program !!! >_<
    is not successfully calling methods in Account.java ..... ?????
    === === === === === === > AND : I have in Client.java
    public class client
    // references to object Account a[]
    private static final int maxAccounts = 3;
    private Account[] a = new Account[maxAccounts]; //? This references a[] to client
    Client Methods including
    public Account getAccount(int num)
    return a[num]; // will be num = 0 or 1 or 2
    } // end client
    === === ==== ===> AND in Account.java
    public class Account
    Account methods
    SO ..... what's the fix ?

    Hi,
    This forum is exclusively related to discussions about creator .
    You may post this thread here
    http://forum.java.sun.com/forum.jspa?forumID=31
    MJ

  • How can I get a certified java programmer ???

    Hello to all Java Programmer out there!!
    Can somebody tell my what I must do to get a certified java programmer?
    You can send me an email to the adress [email protected]
    Thank you!

    Wow, 5 responses, only one of them valid! Then again, a statement like that begs to be picked on! Anyway, another good site would be www.jchq.net. Lots of good resources, but I also suggest going to B&N (or some other big book-seller), and get a certification book. My general rule of thumb is, the bigger the book, the better. That's not always true, but it's good to go on. I'm picking one up this weekend, hopefully. Study, study, study!!!
    James

  • News server not found!! news:comp.lang.java.programmer HELP

    I trying to join newsgroup comp.lang.java.programmer
    but keep getting news server not found.
    Please help.

    No it's the name of the news group. You may add news1.sinica.edu.tw as the news server and select the group from those listed.

  • Problem in executing Linux command from Java Programme.

    hi everybody,
    can anybody help me to solve one problem i have.
    i want to capture the output of linux command "grep" in my java programme.but it is not working properly .(maybe this sub-process doesn't have permission to read files)
    here is my code and corresponding outputs.
    import java.io.*;
    public class BSearch
    public static void main(String kj[])
    try
    Runtime rt=Runtime.getRuntime();
    String command="grep \"hello\" -r /usr/MyDir ";               
    Process rtProc=rt.exec(command);          
    InputStream is=rtProc.getInputStream();
    BufferedReader br =new BufferedReader(new InputStreamReader(is));     
    String line =null;
    while((line=br.readLine()) != null)
    System.out.println(br.readLine());
    br.close();
    catch(Exception e)
    System.err.println("Error in command "+e);               
    it finds "hello" pattern only in BSearch.class file although if i fire this command on LINUX prompt it
    shows all the files in /usr/MyDir which contain "hello" pattern.
    java programme output :
    Binary file /usr/MyDir/BSearch.class matches.
    linux command output :
    /usr/MyDir/one.txt: hello sdfs
    Binary file /usr/MyDir/BSearch.class matches.
    /usr/MyDir/two.txt: kjsdf hello sdfsdf
    will anybody help me solve this problem.

    It may be a Problem of Catching the Echoes back from the Processes...I have a Program which Captures the Echoes..see if it works
    import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.lang.ref.WeakReference;/** * Implements a proxy property change listener using a weak reference to avoid memory locking that would occur if it * was a strong reference. To understand this, we hve to understand that the property change listeners themselves are * hilding onto panels and other objects with strong java references. If the panel goes away while we are viewing an * object, we have a circular emory hold situation where the panel cant be collected because it has ahold of the * property and the property cannot because it has ahold of the pane. If we use weak references instead, then the hard * link between the listener and the producer is softened to almost nothing. */public class WeakPropertyChangeListener implements PropertyChangeListener {  /**   * A poperty change support object is included here so that the listener can remove   * himself from the listeners if the reference internally goes to null.   */  private PropertyChangeSupport pcs = null;  /** Holds the weak reference to the real listener. */  private WeakReference weakRef = null;  /**   * Constructs a new Proxy object for the given support and listener.   * @param pcs The property change support that this object will be using.   * @param pcl The real listener.   */  public WeakPropertyChangeListener(PropertyChangeSupport pcs, PropertyChangeListener pcl) {    if (pcs == null) throw new NullPointerException("pcs");    if (pcl == null) throw new NullPointerException("pcl");    this.pcs = pcs;    weakRef = new WeakReference(pcl);  } /** @see <{PropertyChangeListener}> */ public void propertyChange(PropertyChangeEvent changeEvent) {    Object referrant = weakRef.get();    if (referrant == null) {      pcs.removePropertyChangeListener(this);    } else {      ((PropertyChangeListener)referrant).propertyChange(changeEvent);    } } /** Returns true for comparison to referrant or this. */ public boolean equals(Object obj) {    if (obj instanceof WeakPropertyChangeListener) return super.equals(obj);    else if (obj != null)return obj.equals(weakRef.get());    else return false;  }}// snipet public void addPropertyChangeListener(PropertyChangeListener listener) {    this.propertyChangeSupport.addPropertyChangeListener(      new WeakPropertyChangeListener(this.propertyChangeSupport, listener));  } public void removePropertyChangeListener(PropertyChangeListener listener) {    this.propertyChangeSupport.removePropertyChangeListener(listener);  }

  • Hello over there! How to become a best java programmer??

    I'm not bad in JAVA at all, I just want to move to the next level. Does anyone knows how i should take my skills to the higher level? Where can I buy java materials, I bought all java materials and projects from shopnewused.com I need something like that but more powerful now. The series was very very helpful if compared to my skills before getting to shopnewused.com. Thanks in advance!!

    About 10-15 years of working experience will do it.
    I hope you want to become a good software engineer by the way, getting really good at Java doesn't help you much specifically, its just a means to an end. What do you think is more important?
    a) writing epic code
    OR
    b) building something that works, is clean and user friendly, well documented, easy to maintain and does exactly what the users of the software need it to do
    I hope you pick b), and I hope you see that becoming a "best java programmer" does not help you to do all that. You need to be much, much more than that.

  • Cry for help is this usual

    Hi, this is really a cry for help in the vain hope there is somebody at bt who cares about my broadband issue. Returned from holiday to find dsl light off on modem, did all the resets / power cycles but initially told a week ago it was an issue in my area and would return next day, then told it was a fault on line, then told it was a fault at exchange, now told its an issue in my area. Saw a Open Reach guy in my road, he said its rubbish and there is signal in the cabinet. Just spent half an hour on hold to level 2 support but they put phone down on me REALLY FED UP!!!

    I have asked a moderator to provide assistance, they will post an invite on this thread.
    They are the only BT employees on this forum, and are a UK based team of people, who take personal ownership of your problem.
    Once you get a reply, make sure that you are logged into the forum, then click on their name, you will see a screen like this. Click on the link as shown below.
    Please do not send them a personal message, as they may not be on duty for a long time, and your message will not be tracked properly.
    For your own security, do not post any personal details, on this forum. That includes any tracking number you are give.
    They will respond either by phone or e-mail within 5-6 working days.
    Please use the tracked e-mail, to reply, not via the forum. Thanks
    This is the form you should see when you click on the link. If you do not see this form, then you have selected the wrong link.
    When you submit the form, you will receive an enquiry number, so please keep a note of it
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • Is it necessary to have an scjp certification to be a java programmer

    hi i have been programming in java for quite some time now , i have heard a lot about SCJP .
    Right now i am in college doing my grad. and java is not a part of our curriculum
    i am quite comfortable with java and want to make my career as a java programmer.
    i just want to know one thing from some professionals on the forum that is it very necessary to have an SCJP Certification if i want to apply in some big companies as a java programmer since i wont be having any other certifications that i have done java .
    please tell me if it would be good for me if i do an SCJP course
    Regards

    hi i have been programming in java for quite some
    time now , i have heard a lot about SCJP .
    In that case you should already know the answer to your stated question...
    i just want to know one thing from some professionals
    on the forum that is it very necessary to have an
    SCJP Certification if i want to apply in some big
    companies as a java programmer since i wont be having
    any other certifications that i have done java .
    Can't hurt, probably won't help either.
    please tell me if it would be good for me if i do an
    SCJP course
    Formal training never hurts.

  • What are the key points of a job nterview as a java programmer ?

    Hi,
    I would like to know what to expect from a job interview as an entry level java programmer ?
    Do you have recommendations ?
    Thank you in advance,
    Grazia

    Primarily, be honest. That is true only if you are going to be
    be interviewed by technical people. RH people don't
    care for honesty or how good you are. More than once
    I was asked in an interview:
    "Are you an Expert in java? You would say from 0%
    0% to 100% how much do you know java?"
    My usual answer is: "No. I have still a lot to
    to learn, java is a vast subject and its is very
    unlikely someone know it all, I have a good grasp of
    the sintax and of OO design but I would say I know
    just 5% to 10%". Then they make a "face" pass a
    crappy test that only deals with the simplest of the
    java concepts(usually it is clear the person who
    designed the test does not even grasp the basic), the
    last one took me 8min to answer and I leave knowing
    that one more time I did not got the job.
    As it is I never go any job if the RH is the
    he responsible for the hiring, I only get the job
    when I talk directly with technical people.
    May the code be with you.'RH'? You mean 'HR'?

  • How to create context sensitive help and call the role based help from my Java Project?

    Hello All,
    I am new to Robo Help. I have created a Robo help for my Java Web Applicaion. My application is role base i.e some user's will not see some of the pages of the application. So I want to hide those pages in Robo help as well. I tried creating multiple TOC for different Roles.
    My Question is
    How to call robo Help from my application?(I will be calling using java script. If it is with RoboHelp_CSH.js where can I get that and How to implement it in my project)
    How to implement role based help?
    Thanks,
    Siva.

    I answered that. My point in asking whether it matters was that if it does, then you cannot use content categories and point different users to different categories and not allow them to see the others.
    The alternative, as I said, would be to produce different outputs for each role.
    As it does matter, then using webhelp you will have to use your RoboHelp project to produce a number of outputs, one for each category. Your app would install each webhelp into different folders and when your app determines the user role, you will link to the appropriate help.
    There is another thread running where it has been explained by Willam van Weelden that you can achieve what you want using browser based AIR help. If that form of help can be considered, then the thread is at http://forums.adobe.com/message/4914753?tstart=0#4914753
    Browser based AIR help must be run from a web server. It cannot be installed locally.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • How to create trigger through Java programm?

    I write a Java programm to create a trigger(through JDBC connection). After I run the programm, a trigger was created in Oracle 10g.But the trigger is invalid. After Compiling the trigger , a error "PLS-00103 " occured .But if I excute the SQL in SQL developer,the trigger was created successfully.
    If there is some special considerations should be taken when using programm to create trigger?
    My Java programm fragment as follows:
         public void createTrigger() throws SQLException{
              Statement stmt = conn.createStatement();
              stmt.executeUpdate(getCreateTriggerSql());
    Edited by: jerry on 2010-6-29 下午6:42

    Yes the special consideration is you shouldn't perform DDL on the fly, as it has all kinds of unwanted side effects like implicit commits.
    If I would start a company, and I discover one of my developers is writing this kind of program, I would fire him, on the spot.
    Sybrand Bakker
    Senior Oracle DBA

  • How to become a good java programmer

    Hi guys
    I have been in touch with java for 3 years but I have not learned it from basic and fundamentally, so I started to learn it from very basic. but how can I become a good java programmer? can we put the answer of this question in steps ?
    Thanks

    Alex_Haze wrote:
    Hi guys
    I have been in touch with java for 3 years but I have not learned it from basic and fundamentally, so I started to learn it from very basic. but how can I become a good java programmer? can we put the answer of this question in steps ?
    Thanks1) Get a good java book and read it from start to finish. Understand and then use every technique demonstrated in the book before moving onto the next.
    2) Develop good programming practices in general. Use resources like Code Complete and software engineering books to improve the quality of your code and development practices. This is a typical programmer's bookshelf:
    [http://www.codinghorror.com/blog/images/my-programming-bookshelf-small.jpg|http://www.codinghorror.com/blog/images/my-programming-bookshelf-small.jpg]
    3) Learn new things, always. Start witing things in J2EE. Start writing things in Swing. Even pick up a new language. Different perspectives help you see things in different ways and let you think in new directions.
    4) Pay attention to detail. Strive to write the very best code you can every time. Think constantly about how you can do it better.
    5) Solicit feedback from peers, coworkers, and quality online communities. Ask them how you can do it better. Post code examples and trust your gut if you suspect that something could be done a better way.
    6) Accept that it won't happen overnight. The road to being a "good" programmer is a long one.

  • Get Data from SAP over the Business Connector into a Java Programm

    Hallo dear community,
    i would like to receive data from the sap over the application business connector into a java programm. i work with the german book "SAP Business Connector 4.8 - Administration und Entwicklung".
    Now i hand on the routing rule.
    [Screenshot|http://h-2.abload.de/img/routingruleuyt9.png]
    i don't know what i should configure here for receiving data, which i need for an java programm.
    i will be very happy, when somebody got a tip or an source (tutorial) where i can find such a configuration  :wink:

    I think u r writing BDC for Uploading the data from excel flile to sap. for this is the code I am sending u can use then for Uploading data from excel to sap.
    DATA: lv_filename TYPE rlgrap-filename.
    FIELD-SYMBOLS : <fs>.
    DATA : l_intern TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
    DATA : l_index TYPE i.
    PARAMETERS : startcol TYPE i ,
          startrow TYPE i ,
          endcol TYPE i ,
          endrow TYPE i .
    PARAMETERS: p_flnam LIKE rlgrap-filename.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flnam.
      CALL FUNCTION 'F4_FILENAME'
    EXPORTING
       program_name        = sy-repid
      FIELD_NAME          = ' '
       IMPORTING
         file_name           = p_flnam .
      MOVE p_flnam TO lv_filename.
    Uploading the flat file from the desktop
    START-OF-SELECTION.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename                      = lv_filename
          i_begin_col                   = startcol
          i_begin_row                   = startrow
          i_end_col                     = endcol
          i_end_row                     = endrow
        TABLES
          intern                        = l_intern
    EXCEPTIONS
      INCONSISTENT_PARAMETERS       = 1
      UPLOAD_OLE                    = 2
      OTHERS                        = 3
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      SORT l_intern BY row col.
      LOOP AT l_intern.
        MOVE l_intern-col TO l_index.
        ASSIGN COMPONENT l_index OF STRUCTURE itab TO <fs>.
        MOVE l_intern-value TO <fs>.
        AT END OF row.
          APPEND itab.
          CLEAR itab.
        ENDAT.
      ENDLOOP.
    I hope it will help u.
    Regards
    Nayan

  • Java Programmer/Analyst - Houston, TX

    Hi! My name is Dharti; I need your help finding people qualified for the position listed below, be it you or someone you know! I work for ROI Staffing, an established IT Professional Service Firm headquartered in Houston, TX, dedicated to finding superior Information Technology Talent. We provide sourcing solutions to our nationally established Private and Public sector Fortune 500 clients. Our services are flexible by design and span a wide spectrum of industries and technologies.
    JOB DESCRIPTION
    JOB TITLE: Java Programmer/Analyst
    WORK LOCATION: Houston, TX
    INTERVIEWS: ASAP
    START DATE: ASAP
    DURATION : 6 months contract to hire
    MUST BE U.S.CITIZEN/GC HOLDER/ EAD HOLDER
    PAY RATE: W-2 Hourly Rate with benefits during contract & then transition to permanent employee with salary d.o.e + full comprehensive corporate benefits to include medical, dental, 401K, bonus & more!)
    Our Client is seeking a resource with strong technical skills to participate in numerous development projects involving our Client Application Team applications. These applications provide a number of critical business functions including integration of external exchanges, position, price management, and straight thru processing. Client has identified a number of projects that will expand the scope of the applications and propagate them through more areas of the business. The team is in need of a programmer to design, develop, and implement the proposed solutions in the trading organization.
    The tasks and activities expected of the position are as follows:
    * Development, support and maintenance for custom developed trading applications.
    * Analyze and devise solutions for production related issues.
    * Develop technical design and architecture specifications based on application requirements.
    * Perform unit testing and assist with integration testing of applications.
    Skill/Role Level Years Preference
    Enterprise Systems Development Intermediate 5.0 Required
    Oracle Intermediate 3.0 Required
    TIBCO Intermediate 2.0 Preferred
    Programmer Intermediate 5.0 Required
    IBM WebSphere Intermediate 2.0 Required
    J2EE (Java 2 Enterprise Edition) Intermediate 3.0 Required
    Java Swing Required
    If you are not the correct person to talk with in regards to this position, please feel free to forward this job requirement to any friends or colleagues you know that might be interested in this opportunity, whether they are currently looking or know someone that is.
    Thanks for your assistance in advance and taking the time to read over my e-mail. I hope to hear back from you soon.
    Dharti Singh
    ROI Staffing, LP
    713.600.3201 direct
    Toll Free Number: 888.884.6200
    [email protected]

    -

  • Help in translating JAVA code into CF

    Hi all!  I'm at the end of integrating an in-house calendar with Google calendars and all is working, however, I am stumped as to how implement callback functions.  Here's what I'm trying to do as outlined on http://code.google.com/p/google-api-java-client/source/browse/Batch.wiki?repo=wiki
    What I need to do is this section right here:
    JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() {
      public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) {
        printCalendar(calendar);
        addedCalendarsUsingBatch.add(calendar);
      public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
        System.out.println("Error Message: " + e.getMessage());
    And then later pass it to:
    client.calendars().insert(entry1).queue(batch, callback);
    I believe I can pass one function by passing just the name of the function, but BatchCallback has two functions.  Is this impossible to do in CF?
    Thanks,
    Ross.

    1. In the future, please use a meaningful subject line, like "loop not performing last iteration." Just saying "Help in my java code" is useless. We know you need help with your Java code, else you wouldn't be posting here.
    2. Repost your code without those annoying superfluous asterisks, and with proper indentation in the section that they are currently polluting. It's too hard to read as-is.

Maybe you are looking for