Problem passing arguments by reference

Okay, so I'm trying to pass two variables to a function by reference, but when I go to arithmetically manipulate the variables in the function that's receiving the arguments, it's multiplying their values by four, for what reason I cannot understand. Here's my code (the relevant parts of it) -- it's a casino game:
void BuyChips(int *, int *);
int main()
    int money = 5000;
    int chips = 0;
    BuyChips(money, chips);
void BuyChips(int *mny, int *chps)
    int numChipsBought;
    printf("How many chips would you like to buy? ");
    scanf("%d", &numChipsBought);
    chps += numChipsBought;
    mny -= numChipsBought;
    printf("\nYou purchase $%d in chips. You now have $%d in chips
            and $%d remaining in cash.", numChipsBought, chps, mny);
If I type in "20" for the input for how many chips I want to buy, here's the output I get:
You purchase $20 in chips. You now have $80 in chips and $4920 remaining in cash.
For the life of me I can not figure this out. I can't figure out why it has multiplied the values by four. I know it has something to do with passing the arguments to the function by reference, though, because (for debugging's sake) I tried creating regular variables for chips and money within the BuyChips() function itself instead of passing them to the function from main(), and it worked fine. But for some reason, when I pass the variables there by reference, it multiplies them by four.
Can someone please help me with this? Thanks!

nt main()
    int money = 5000;
    int chips = 0;
     BuyChips( &money, &chips);
     (send the address of the variables)
     *chps += numChipsBought;
     *mny -= numChipsBought;
    printf("\nYou purchase $%d in chips. You now have $%d in chips
            and $%d remaining in cash.", numChipsBought, *chps, *mny);
(access the variable through the address)

Similar Messages

  • Problem passing arguments with air.swf

    I'm attempting to launch my AIR application using
    launchApplication() in air.swf. I'm having problems passing
    arguments to my application due to what appears to be some
    restriction in allowed characters. To get around this, I've even
    tried URL encoding and Base-64 encoding my arguments to make them
    more friendly, but it's still failing:
    Error: Invalid argument: PG5vIGlkZW50aWZpZXI+
    at AIR$/escapeArguments()
    at AIR/launchApplication()
    at
    adlm_launcher/onDownloadClick()[E:\adlm\launcher\src\adlm_launcher.mxml:181]
    It seems that any kind of punctuation is not allowed in
    arguments. URL encoding them doesn't work either because the % is
    rejected. Is there any other way around this?

    Yes; it's a security restriction. Browser invocation require
    process creation, and many process creation APIs giving special
    meanings to certain characters. Letting those characters through
    has in the past been a source of security vulnerabilities. While we
    also try to avoid using APIs with this behavior, extra layers of
    defense are also good.
    I think + and / may actually be safe choices; you make a good
    point that they're useful for Base64. If you could submit a feature
    request at www.adobe.com/go/wish, we'll definitely consider it.
    Another option, btw, is to use the LocalConnection API to
    pass data between the web page and your application once your app
    is launched. LocalConnection has fewer restrictions on the data
    passed.

  • Pass Arguments By Reference

    Hello Everyone,
    I have this problem the native method that I want call from my JAva program accepts a long value by reference. How do I pass it from my Java code. Here is the JAva code:
    long ulRecSize;
    bRet = this.GetRecordingSizePtr(szEventName, ulRecSize,1);
    and here is the C++ native method:
    BOOL GetRecordingSize(char* pszEventFileName, unsigned long* pulRecSize, unsigned char ucDevice)
    /* ALL NOT Required code is omitted*/
    HeaderSize = sizeof(Recording) - sizeof(RecordedFrame);     // size of recording header
    VehicleDataSize = recSpec.numDEIDs * sizeof(DE_RetVal);     // size of Vehicle Data (1 frame)
    RecordedFrameSize = VehicleDataSize + sizeof(unsigned long);     // size of RecordedFrame
    VehRecordingSize = RecordedFrameSize * eventData.wNumOfFrames;// size of VehRecording (all frames)
    *pulRecSize = HeaderSize + VehRecordingSize;     // total size
    NOW ulRecSiz is supposed to be passed by reference which becomes *pulRecSize
    Any help?????

    I am assuming that you want to pass the long via refrence so that when the C code changes it the java value has also been changed
    I don't think it is possible to pass a reference to a primative such as long with the JNI. Java doesn't allow you to get a reference to a primitive. I think you will have place the long inside a wrapper class that contains a long which allows you to set and get that long value. Then pass that class as an object and use the get and set methods to change the long value inside.
    But I could be wrong.
    Hello Everyone,
    I have this problem the native method that I want call
    from my JAva program accepts a long value by
    reference. How do I pass it from my Java code. Here is
    the JAva code:
    long ulRecSize;
    bRet = this.GetRecordingSizePtr(szEventName,
    ulRecSize,1);
    and here is the C++ native method:
    BOOL GetRecordingSize(char* pszEventFileName, unsigned
    long* pulRecSize, unsigned char ucDevice)
    /* ALL NOT Required code is omitted*/
    HeaderSize = sizeof(Recording) -
    sizeof(RecordedFrame);     // size of recording header
    VehicleDataSize = recSpec.numDEIDs *
    sizeof(DE_RetVal);     // size of Vehicle Data (1 frame)
    RecordedFrameSize = VehicleDataSize + sizeof(unsigned
    long);     // size of RecordedFrame
    VehRecordingSize = RecordedFrameSize *
    eventData.wNumOfFrames;// size of VehRecording (all
    frames)
    *pulRecSize = HeaderSize + VehRecordingSize;     // total
    size
    NOW ulRecSiz is supposed to be passed by reference
    which becomes *pulRecSize
    Any help?????

  • Problems with passing arguments to app

    Hi.
    I have a litle problem with passing arguments. I create a dynamic jnlp file using jsp. This is my code:
    <%
    response.setContentType("application/x-java-jnlp-file");
    String l = request.getParameter("login");
    String p = request.getParameter("pass");
    out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.println("<jnlp spec=\"1.0+\" codebase=\"http://212.244.104.27:8080/PzP_INSTALL/\" href=\"pzp.jsp\">");
    out.println("<information>");
    out.println("<title>xxx</title>");
    out.println("<vendor>xxxx</vendor>");
    out.println("<homepage href=\"main.jsp\"/>");
    out.println("<description>text</description>");
    out.println("<offline-allowed/>");
    out.println("</information>");
    out.println("<security>");
    out.println("<all-permissions/>");
    out.println("</security>");
    out.println("<resources>");
    out.println("<j2se version=\"1.4+\"/>");
    out.println("<jar href=\"jars/pzp.jar\" main=\"true\" download=\"eager\"/>");
    out.println("<jar href=\"jars/config.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/commons-beanutils.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/commons-collections.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/commons-digester.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/commons-logging.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/commons-validator.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/easclient.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/easj2ee.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/jakarta-oro-2.0.7.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/jbcl.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/log4j-1.2.7.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/jdom.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jars/xercesImpl.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<property name =\"javaws.login \"  " + "value=" + "\"" + l + "\"" + "/>");
    out.println("<property name =\"javaws.pass \"  " + "value=" + "\"" + p + "\"" + "/>");
    out.println("</resources>");
    out.println("<application-desc main-class=\"aaa.bbb.ccc.MyClass\"/>");
    out.println("</jnlp>");
    %>My problem is when i have the href tag filled, the arguments that i passed equlas null, when i remove the href everything is ok besides that the app doesnt show in application manager and doesnt create an icon on the desktop.
    out.println("<jnlp spec=\"1.0+\" codebase=\"http://62.89.104.27:8080/PzP_INSTALL/\" href=\"pzp.jsp\">");
    Any help would be appreciated.

    Hello again.
    Thanks for your replay but unfortunetly it doesnt work too :-(
    I've tried to use the out.println statemants in the servlet instead of using a jsp page but the error is the same. Please look at my code and tell me if you can what could be wrong.
    This is the error message:
    An error occurred while launching/running the application.
    Title: PZP
    Vendor: SPEED
    Category: Download Error
    Unable to load resource: http://212.89.104.27:8080/PzP_INSTALL/ServletPZP
    Servlet code.
    package pzp_install;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import pzp_install.LoginBean;
    import javax.swing.JOptionPane;
    public class ServletPZP extends HttpServlet {
      public void init(ServletConfig config) throws ServletException {
      super.init(config);
      config.getServletContext().setAttribute("ServletPZP", this);
      public void doPost(HttpServletRequest request, HttpServletResponse resp)
      throws IOException {
      PrintWriter out = resp.getWriter();
    // Get the value of the request parameter
      String login = request.getParameter("login");
      String pass = request.getParameter("pass");
    resp.setContentType("application/x-java-jnlp-file");
    out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.println("<jnlp spec=\"1.0+\" codebase=\"http://212.89.104.27:8080/PzP_INSTALL/\" href=\"/servletpzp\">");
    out.println("<information>");
    out.println("<title>PZP</title>");
    out.println("<vendor>SPEED</vendor>");
    out.println("<homepage href=\"main.jsp\"/>");
    out.println("<description>Aplikacja wspomagajaca zarzadzanie zleceniami</description>");
    out.println("<offline-allowed/>");
    out.println("</information>");
    out.println("<security>");
    out.println("<all-permissions/>");
    out.println("</security>");
    out.println("<resources>");
    out.println("<j2se version=\"1.4+\"/>");
    out.println("<jar href=\"pzp.jar\" main=\"true\" download=\"eager\"/>");
    out.println("<jar href=\"config.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"commons-beanutils.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"commons-collections.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"commons-digester.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"commons-logging.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"commons-validator.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"easclient.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"easj2ee.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jakarta-oro-2.0.7.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jbcl.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"log4j-1.2.7.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"jdom.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<jar href=\"xercesImpl.jar\" main=\"false\" download=\"eager\"/>");
    out.println("<property name =\"javaws.login \"  " + "value=" + "\"" + login + "\"" + "/>");
    out.println("<property name =\"javaws.pass \"  " + "value=" + "\"" + pass + "\"" + "/>");
    out.println("</resources>");
    out.println("<application-desc main-class=\"pl.speednet.pzp.PzP\"/>");
    out.println("</jnlp>");
      public void destroy() {
      super.destroy();
    This is the brief of code which starts the servlet
    <form action="http://212.89.104.27:8080/PzP_INSTALL/servletpzp" method="post">
      <input type="hide" name="login" value=<%=l%>>
      <input type="hide" name="pass" value=<%=p%>>
      <input type=submit value=Start PZP>
    </form>
    This is the web.xml file code.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
      <servlet>
        <servlet-name>ServletPZP</servlet-name>
        <servlet-class>pzp_install.ServletPZP</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>ServletPZP</servlet-name>
        <url-pattern>/servletpzp</url-pattern>
      </servlet-mapping>
      <mime-mapping>
        <extension>jar</extension>
        <mime-type>application/x-java-archive</mime-type>
      </mime-mapping>
      <mime-mapping>
        <extension>jnlp</extension>
        <mime-type>application/x-java-jnlp-file</mime-type>
      </mime-mapping>
    </web-app>

  • Hi, i am facing problem as to how to pass arguments received by my swf file to an .exe that i have c

    hi, i am facing problem as to how to pass arguments received by my swf file to an .exe that i have created from a C++ project...do i need to tweak the code in the C++ project in some way that it accepts the input from the .swf file?

    Hi there and welcome to our community
    What you need to do is click the link below, then choose the forum most appropriate to the product you are using. In this forum we discuss the operation of the forums themselves.
    http://forums.adobe.com/index.jspa
    Best of luck to you in solving your issue! Rick

  • Problems passing std::vector char by reference

    I'm currently developing an InDesign Server plug-in off the CS5 SDK (Build 335).
    I've written some code that attempts to return the image bytes of a JPEG via a function
         bool CJPEGImage::Copy( std::vector<char>& Data );
    The typical usage is...
         std::vector<char> ImageData;
         if (ptrJPEGImage->Copy( ImageData ))
              // Do something with the data
    Having created the vector, the debugger shows the value to be [0x00000000](), which is correct as it is empty. On passing it to the function, vector now has a value of [0xffd55784](0xfd,0xff,0xff,0xff,0x01,0x00,0x00,0x00,0x6a ..................). I resize the vector to the number of bytes in the file, create a read stream and then use XferByte( (uchar *)&Data[0], FileSize ) to copy the image data into the vector.
    The contents of the vector are not changed and any attempt to use the buffer will lead to a crash elsewhere in the code. It's clearly wrong, as it is a reference and the value should be [0x00000000](0). It's as if the vector is pointing at some random memory. If you pass by copy the new vector is set up correctly.
    The same error occurs for <unsigned char>. But switch to <int> and everything behaves as expected. So what is it about std::vector<char>& that InDesign SDK has changed?
    I know that InDesign has its own K2Vector implementation. However I have a number of static libs that expect a std::vector<char>& and if so I'd like to use that.
    Has anyone seen this before and know a way to work around it?
    Thanks in advance,
    Andrew

    You cannot pass anything "by reference".
    no you are wrong. While invoking remote methods, RMI passes primitive types and abject types by value and remote objects by reference. "Pass by value" is implemented by deep copy. Pass by reference for remote objects is implemented by remote references- remote stubs. So to be more excat they are passed by remote reference. Thats why u extend unicastRemoteObject, remoteServer or remoteObject etc.
    Both the Client and the Server are two separate Java
    Virtual Machines. In order to pass anything, the RMI
    Runtime must serialize the data into a byte stream and
    pass the byte stream to the other machine using a
    network. This is why everything you need to pass
    either way must implement Serializable. Yes I agree with this part.

  • Passing objects by reference in PL/SQL

    Hi,
    I have come across an unexpected problem using object types in PL/SQL that is causing me some grief. I'm from a Java background and am relatively new to Oracle Objects but what I'm trying to do is fairly trivial, I think. The code below illustrates the problem.
    --- cut here ---
    CREATE OR REPLACE TYPE test_obj_t AS OBJECT
    num INTEGER,
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT
    CREATE OR REPLACE TYPE BODY test_obj_t IS
    CONSTRUCTOR FUNCTION test_obj_t RETURN SELF AS RESULT IS
    BEGIN
    num := 0;
    RETURN;
    END;
    END;
    CREATE OR REPLACE PACKAGE test_obj_ref AS
    PROCEDURE init(o IN test_obj_t);
    PROCEDURE inc;
    FUNCTION get_num RETURN INTEGER;
    END;
    CREATE OR REPLACE PACKAGE BODY test_obj_ref IS
    obj test_obj_t;
    PROCEDURE init(o IN test_obj_t) IS
    BEGIN
    obj := o;
    END;
    PROCEDURE inc IS
    BEGIN
    obj.num := obj.num + 1;
    END;
    FUNCTION get_num RETURN INTEGER IS
    BEGIN
    RETURN obj.num;
    END;
    END;
    --- cut here ---
    The object type test_obj_t holds a integer and the test_obj_ref package holds a 'reference' to an instance of the object.
    To test the above code I run this PL/SQL block:
    declare
    obj test_obj_t;
    begin
    obj := test_obj_t;
    test_obj_ref.init(obj);
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    test_obj_ref.inc;
    dbms_output.put_line('obj.num='||obj.num);
    dbms_output.put_line('test_obj_ref.get_num='||test_obj_ref.get_num);
    end;
    giving the output:
    obj.num=0
    test_obj_ref.get_num=0
    obj.num=0
    test_obj_ref.get_num=1
    obj.num=0
    test_obj_ref.get_num=2
    It appears that the object held by the test_obj_ref package is being incremented as expected, but I would have expected the object declared in the PL/SQL block to be pointing to the same object and so should report the same incremented values.
    I suspect that the object is copied in the call to test_obj_ref.init() so I end up with two object instances, one that is held by the test_obj_ref package and one in the anonymous block. Although, I thought that all IN parameters in PL/SQL are passed by reference and not copied!
    Am I right?
    Is passing objects by reference possible in PL/SQL, if so how?
    I'm using Oracle 10.2.0.3.
    Cheers,
    Andy.

    the object being passed to the test_obj_ref.init+ procedure is passed by reference; however, when you assign it to your package variable obj it is being copied to a new instance. you can pass object instances as parameters to procedures using the +IN OUT [NOCOPY]+ *calling mode, in which case modifications to the attributes of the passed object will be reflected in the calling scope's instance variable.
    oracle's only other notion of an object reference is the +"REF &lt;object-type&gt;"+ datatype, which holds a reference to an object instance stored in an object table or constructed by an object view.
    hope this helps...
    gerard

  • How to pass argument to the Java Plugin JVM w/o using the Control Panel?

    I want to deploy an applet to be loaded by the Java Plug In
    and fix some settings of its Java Virtual Machine.
    The JPI Control Panel offers two ways to pass arguments to the JVM,
    none satisfactory.
    1. while interactive via the Control Panel Window.
    This cannot be a solution for a deployed applet.
    or
    2. by editing the system generated file that stores
    the settings of the Plugin Control Panel, using a property
    named javaplugin.jre.params.
    The problem with this method is that if forces to access
    and edit this property file which is stored at various locations
    depending the client platform. Then, it may collide with other
    settings for other applets.
    Is there a way to pass the arguments to the JVM
    from within the html file?
    Has anyone found a solution to this question?
    JPS

    I am interested in this issue as well.
    Did anyone find a reliable way to specify the runtime parameters that should be used by the Java Plug-in in order to execute a given Java applet?
    I believe a good place to specify these runtime parameters would be the applet's JAR manifest: only digitally signed applets should be able to set the desired runtime parameters...
    Any comments / suggestion would be greatly appreciated.
    Regards,
    Marco.

  • How can I pass arguments to a TestStand sequence with LabWindows 6 ?

    Hi
    I have created sequences in a TestStand file.
    I want to program a sequence with Labwindows 6 which would call all these existing sequences (containing parameters).
    I don't have any problems to create the steps "SequenceCall" but i don't know how to pass arguments to the sequences with the TS API.
    I have used the look-up strings "TS.SData.SFPath", "TS.SData.SeqName", "TS.SData.ThreadOpt" to program the sequence file / sequence and the multithread option. But now how to program the arguments passing ? I think there is something with the lookup string "ST.SData.ActualArgs"...
    Thank u very much for any help

    I'm not sure if you want to pass values from TestStand to LabWindows or if you want to pass values in TestStand from a sequence call step to a called sequence.
    To get TestStand variables from LabWIndows, use the following function:
    tsErrChk (TS_PropertyGetValNumber(testData->seqContextCVI, &errorInfo, "Locals.StartPoint", 0, &dStartPt));
    iStartPt = (int)dStartPt;
    The TS_PropertyGetValNumber gets the TestStand variable Locals.StartPoint and puts it into the LabWindows variable called dStartPoint. Numbers to and from Test Stand are always a double type. The next line converts it to an integer.
    To put a LabWindows value to TestStand, use TS_PropertyPutValNumber.
    To pass values from a sequence call step to a called sequence, create variables in the Parameters t
    ab on your main sequence. Create same variables on the Parameters tab of the called sequence. In main, specify module to be called in calling step. There is a paramters section on the Edit Sequence Call dialog box which appears. Check the Use Prototype of the Selected Sequence box. You can then list all the parameter variables in the parameters section.
    Hope this is what you want.
    - tbob
    Inventor of the WORM Global

  • How can we pass argument to static block of code????

    hi ,
    My question is we can use static initialization block for having functionality like constructors for initializing static variable ,but we cannot pass arguments to static initialization block then how can I create functionality like parametrized constructors.Whats the alternative shall I use a static method to perform this functionality,since all methods in given class are static and
    there is no need of creating instance of class.

    jduprez wrote:
    Hello Jussi,Salut Jérôme
    That's probably a more maintenable design.
    However what do you base your remark on - I'm struck by the word obviously?
    Is there some design principle from which this advice so naturally ensues that it is obvious ?Yes I read my posting later on and thought about changing it, since it's not necessarily an obvious solution. I was making assumptions that I didn't clarify from the OP.
    In the OP's case, the "state" on which those methods operate is apparently fixed, presumably at the beginning of the program, so what's wrong with all this staticness?
    I can list:
    - threading issues (a non-issue after some initialization phase), that you wouldn't have with immutable instances
    - harder unit-testing (that's not an OO design problem, more a methodology problem)
    - mix and confusion between static and non-static state if the class ever happens to have both, in future maintenance. All good points, I see all-static classes as a "code smell" and especially in this case when there's parametrization involved.
    Now we just need to have the OP explain his situation a bit better.

  • Passing arguments

    Our teacher just taught us about methods and passing arguments, etc. I have been over our text book and I don't quite understand how it works. Any help?
    PROBLEM:
    ?     Write a program with four methods. One is the main method. The other three are named startMessage, message, and finishMessage.
    ?     Within the startMessage method, place code to print out the message ?The program has started.?
    ?     Within the message method, place code to print out any message that is passed, as a String, into the method using a String parameter named output.
    ?     Within the finishMessage method, place code to print out the message ?The program is done.?
    ?     When the program begins call the startMessage method.
    ?     Then display the following dialog box:
    "Enter a message:"
    ?     Using a While loop, respond to the user?s input appropriately:
         If the user presses OK display whatever the user has entered by calling the message method with the user?s input as the argument. Continue to display the dialog box and display the user?s input until they press Cancel.
         When the user presses Cancel stop showing the dialog box, and do not display what the user has entered.
    ?     After the user presses Cancel, and before the program terminates, call the finishMessage method.
    ?     Terminate the program.
    here is what I have so far:
    public static void main(String[] args) {
              startMessage();
              String userMessage = JOptionPane.showInputDialog("Enter a message:");
              while (userMessage != null){
                   message(userMessage);
                   JOptionPane.showMessageDialog(null, "Here is message" + message());
                   userMessage = JOptionPane.showInputDialog("Enter a message:");
              finishMessage();
              System.exit(0);
         public static void startMessage(){
              JOptionPane.showMessageDialog(null, "The program has started.");
         public static String message (String output){
              output = userMessage;
              return(output);
         public static void finishMessage(){
              JOptionPane.showMessageDialog(null, "The program is done.");
    }what's giving me the problem is the message method; I can't figure out how to pass whatever they put in the userMessage variable to the message method

    I am stuck here
    PROBLEM:
    ?     Change your C6E2 class by adding a new method called getNumberInput. This method will be used to get a number input from the user, replacing the lines of code in the main method that were previously used. You will need to call this method twice from the main method, prompting for the first and second numbers in turn.
    ?     Write the method so that the prompt displayed in the input dialog box is passed through an argument.
    ?     The return type of this new method will be a double.
    I can't figure out how to pass the input paramater correctly, any help?
    public static void main(String[] args) {
              double num1 = 0;
              double num2 = 0;
              double addResult = 0;
              double subtractResult = 0;
              double multiplyResult = 0;
              double divideResult = 0;
              double input1 = getNumberInput(num1);//this is where I am stuck
              double input2 = getNumberInput(num2);
              addResult = add(num1, num2);
              subtractResult = subtract(num1, num2);
              multiplyResult = multiply(num1, num2);
              divideResult = divide(num1, num2);
              JOptionPane.showMessageDialog(null, addResult);
              JOptionPane.showMessageDialog(null, subtractResult);
              JOptionPane.showMessageDialog(null, multiplyResult);
              JOptionPane.showMessageDialog(null, divideResult);
              System.exit(0);
         }//main
         public static double getNumberInput (double input){
              double output = 0;
              Double.parseDouble(JOptionPane.showInputDialog("Enter a number:"));
              return output;
         public static double add (double term1, double term2){
              double result = term1 + term2;
              return result;
         }//add
         public static double subtract (double term1, double term2){
              double result = term1 - term2;
              return result;
         }//subtract
         public static double multiply (double term1, double term2){
              double result = term1 * term2;
              return result;
         }//multiply
         public static double divide (double term1, double term2){
              double result = term1 / term2;
              return result;
         }//divide
    }//class

  • Passing arguments in Visitor Pattern

    Does anybody have a nice solution to passing arguments in Visitor pattern?
    The Visitor pattern is used to process an object structure (such as an abstract syntax tree) in many different ways without cluttering definitions of the objects with methods needed for all different kinds of processing. Instead, each object has only one method, "void accept(Visitor v)". The method calls back a method in the Visitor that is appropriate for the object. Different kinds of processing use different Visitors, each with its own set of object-processing methods.
    My problem is that I need to pass arguments or receive results from the object-processing methods, different for different kinds of processing.
    One solution is to have many "accept" methods with different signatures. This beats the idea that we do not need to modify definitions of the objects if we want to introduce new kind of processing.
    Another is to provide "accept" with an Object result and a sufficient number of Object arguments, to be used as necessary by different Visitors. It results in clumsy and unreadable code. Detestable.
    Alternatively, one could provide fields in the objects to pass the information when needed. This frees the invocations of "accept" from dummy arguments/results, but does not seem nice.
    One can also forget all about Visitor pattern, and let the processing method test the object class using "instanceof" and call the right method. But this is a pure blasphemy against everything called OO.
    Is there any better way that I am too blind to see?

    Sounds to me like you've got a case of combining different concerns into the same design. I think you're looking at multiple problems, all of which require you to process an object structure.
    I'd make a general framework for processing my structure, and then use a specific interface for each problem. I would avoid re-using the Visitor pattern for multiple concerns as it leads to exactly the problems you're facing.
    If you're dead-set on using the Visitor; how about having a mediator or adapter between the visited class and the Visitor that deals with the specifics of each invocation?
    Personally, I think the Visitor pattern violates basic encapsulation and polymorphism - but that's just my opinion. I try to avoid using it unless I'm stuck with NO other solution.
    Good luck.

  • Passing arguments to a Global Activity with Instance Access

    I'm passing arguments to a Global Activity which has Instance access and then I need to assign agrument values to Instance variables. But, somehow arguments not being passed when I enable "Has Instance Access". If I turn instance access off then arguments pass but unfortunately I cannot assign due to instance not being available. Fyi, I'm using WAPI and argument names in HTML form are prefixed with "arg_" as per WAPI documentation.
    I would appreciate any help in resolving the issue.
    Thanks in advance.
    MK

    Same problem ...
    I tested with JSP.parameters["arg_myArg"] ... no result

  • Passing Arguments to MIDlets

    Is there a means for passing arguments to MIDlets when they are launched? Here's my situation. I'm using a Palm VII with Palm OS3.5. It does not support MIDlet http connections using the onboard wireless antenna. A workaround is to create a pqa for the web stuff, and launch the midlet from within the pqa to do the on-board stuff, like persistant storage. Problem is this is no use unless there is a way to pass arguments similar to to passing command line arguments in J2SE. Anyone have any ideas?

    Is there a means for passing arguments to MIDlets when
    they are launched? Here's my situation. I'm using a
    Palm VII with Palm OS3.5. It does not support MIDlet
    http connections using the onboard wireless antenna.
    A workaround is to create a pqa for the web stuff,
    and launch the midlet from within the pqa to do the
    on-board stuff, like persistant storage. Problem is
    this is no use unless there is a way to pass
    arguments similar to to passing command line
    arguments in J2SE. Anyone have any ideas?Hi,
    There is a way to work which is similar to command line arguments as in J2SE in J2ME. There is a method in MIDlet class getAppProperty(String key). This method tries to get the value from jar or jad file using the key. In the jad file you can keep an attrribute like "myatt1" whose value can be set to "testing".
    i.e., myatt1: testing
    Then if you use getAppProperty("myatt1"), it will return you a string which is nothing but "testing".
    Have a good day.
    S.M.Reddy

  • Pass arguments to class constructor

    Hello,
    Please who can help me to solve my problem? I dynamic
    creating class and I want to pass arguments.
    I know how can I do creating Function (apply), but I coulnd
    find constructor - apply.
    var c:Class = Class(getDefinition(className));
    var instance:Object;
    if(obj){
    var args:Array = deserialize(obj);
    if(args.length == 1)
    instance = new c(args[0]);
    else if(args.length == 2)
    instance = new c(args[0], args[1]);
    else if(args.length == 3)
    instance = new c(args[0], args[1], args[2]);
    else if(args.length == 4)
    instance = new c(args[0], args[1], args[2], args[3]);
    else if(args.length == 5)
    instance = new c(args[0], args[1], args[2], args[3],
    args[4]);
    else if(args.length == 6)
    instance = new c(args[0], args[1], args[2], args[3],
    args[4], args[5]);
    else if(args.length == 7)
    instance = new c(args[0], args[1], args[2], args[3],
    args[4], args[5], args[6]);
    else if(args.length == 8)
    instance = new c(args[0], args[1], args[2], args[3],
    args[4], args[5], args[6], args[7]);
    else
    return serialize("Unexpected number of arguments");
    }else{
    instance = new c();
    }

    Even more follow up advice. Once you have fixed the problem you will then face a new problem.
    Test.Inner i1 = t.new Inner();   // compile error
    Test.Inner i2 = t.new Inner(1); // okayThis is due to the default constructor not being provided as you have defined your own constructor.

Maybe you are looking for