Objects as parameters?

Hello I have a question. I have 2 classes: a simpleInterest and compoundInterest. Now they pretty much do the same thing except calculate differently. Now my problem is that depending on what type of interest a person wants, I should do this somehow by passing an object simpleInterest or compoundInterest instead of having two seperate methods. Heres an example:
public void promptSetInterestRate(i dont know what thecrap to put here)
double inputValue;
String input;
input = JOptionPane.showInputDialog
("Please enter in an interest rate.");
inputValue = Double.parseDouble(input);
//confused here also
interestClass.setInterestRate((double)inputValue);
both interest classes have the same method names and parameters

Both the interest classes should implement the same interface, or subclass the same (probably abstract) class. The method names of the classes are determined in that interface or superclass (or at least, the method names that are called by the method you showed).
So in the parameter list of that method, put in that interface or superclass name as the type of the parameter.
Given your example, the name of the parameter would be "interestClass".
This is basic polymorphism.

Similar Messages

  • Non-string objects as parameters to an applet

    how can i pass non-string objects as parameters to an applet?
    thanks in advance...

    those are some objects that i wroteThen, you could use Class.forName() method for your string parameters.
    If you get the classes, then you can call newInstance() method on them to get objects.
    Alternative way could be using your string parameter as index or keys for some
    data structures that contains ready-made objects.

  • Contract-automatic display sub screen in 'object info parameters' config.

    Dear Sir,
    What is the utility of 'contract-automatic display' sub screen in 'object info parameters' config.
    Where and how we can view it?
    For kind help please.
    Thanks and Regards,
    R N Sabat.

    Hi,
    Go to tcode OIMD see tick mark to AUTOMATICALLY & carryout following changes
    tick mark to if contract under tab contract automatic display
    even if you want to see how many contracts are created and completed then speciefy
    value in
    NotifsCreated -  50            CompletedNotif - 50
    50 if you created 50 contracts for object it will display but not more than 50,so you can assign number between 1 to 99
    kapil

  • Objects as parameters in IDL????

    When I write my IDL files I have methods that will take objects (other remote corba object references) as parameters.
    How do I state that the parameter is going to be an object reference?
    Any help in this would be greatly appreciated...
    Best Regards,
    George Darragh
    **********One of my many errors (:-) is**********
    CORBAServer.java:206: DBClientServant should be declared abstract; it does not define getInsertClientSQL(java.lang.String) in DBClientApp._DBClientImplBase
    class DBClientServant extends _DBClientImplBase {
    ^
    **********The IDL I have relevant to this is**********
    module DBClientApp{
         interface DBClient {
              string getInsertClientSQL(in string InClient ); <-- objects as parameters
              string getUpdateClientSQL(in string InClient); <-- objects as parameters
              string getDeleteClientSQL(in long ClientID);
              string getClientUsingID(in long ClientID);
              string getallClients();
              string getallClientIDs();
    };

    hi,
    check this code out..i am using objects and callback clients..
    typedef sequence<double> value;
    /* these are the methods availbale to server to invike on client*/
    interface frequencies{
    value freq(in value num,in long f);
    void shutdown();
    /* once client starts up, it registers the object with server */
    interface Eigen{
    void addClient(in frequencies obj);
    this should help you out..
    ls

  • Java and COM Object out parameters

    I have a COM object written in C++ that can't be modified. It has several methods with output parameters.
    Can java create an instance of the COM object and pass a reference to a Variant in this case or any objects to be filled by the COM object? My output parameter keeps coming back null, but I know that the COM object is working.
    Bill

    You didn't say anything about how you are bridging java <-> COM.
    If it's via JNI, one way you could deal with this is to write a "wrapper" dll that can speak COM, but which can turn the output data into something more palatable to java - say an object that the wrapper can return.

  • OLE object -Properties/Parameters of a method

    HI,
      Sample code,
    CREATE OBJECT application 'excel.application'.
    SET PROPERTY OF application 'visible' = '1'.
    CALL METHOD OF application 'Workbooks' = workbook.
    CALL METHOD OF workbook 'Add'.
    CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = index.
    GET PROPERTY OF cells 'Font' = gs_font .
    SET PROPERTY OF gs_font  'Bold' = 1.
    SET PROPERTY OF gs_font 'ColorIndex' = 5.
    SET PROPERTY OF cells 'Value' = 'Server name'.
    In this sample code , properties Visible, Bold, Colorindex, Value are set to some values.
    How to find these properties ?
    In which DB Table they are stored ?
    How to get all the properties/parameters of a method ?
    All are concerned with ABAP OLE Objects .
    Pls help regarding this .

    Hi
    Try make in Excel a macro, which do what you need  and analyse than the code of the macro.
    It is very helpfull to find the properites.
    JS

  • Callable object Output parameters does not show up if I use VC

    I have a VC view. Finally the output of a form is fed as input to a stored procedure data service. The stored procedure data mode has 2 output ports:
    OUTPUT
    RESULT
    The value of the result of the stored procedure is present only in the RESULT port.
    When I make a Callable object pointing to the Portal iView of thois VC view, I do not get the output parameter that comes in RESULT in the Output Parameters of the Callable object
    Any help ?

    Hi,
    Hope the below link will help you:
    [Modeling Visual Composer iViews for Guided Procedures|http://help.sap.com/saphelp_nw04s/helpdata/en/44/429bbd709914bce10000000a155369/content.htm]
    [Defining Output Parameters and Result States|http://help.sap.com/saphelp_nw04s/helpdata/en/44/429f01709914bce10000000a155369/content.htm]

  • How to create web services with complex objects as parameters

    Hi,
    Not sure if this is the right place, but...
    I'm using Netbeans 5.5 and trying to learn web services.
    Creating a simple web service with simple parameters like strings and integers is nice and easy. I'm now trying to take the next step, and create a web service with a more complex schema as a parameter.
    I've tried two approaches, and hit dead ends on both:
    (1) Define my complex schema as an xsd file, and then create a WSDL file. Creating the schema and saving it in my EFB project works fine; when I try to create a new WSDL file, the IDE gives me a button to import external schemas - which is where the problem is: the Browse simply won't find my newly created schema file.
    (2) Define a Java class (in this case, it's a fairly simple example containing a single ArrayList), and then use the IDE to generate a web service from Java. The IDE does this fine, but I now have no idea how to consume or test the web service - I don't know where to look for the WSDL that has presumably been generated, and I'm also a bit iffy over what answers to give the WSDL creator about port names etc.
    Ideally, I'd prefer to get approach 1 to work - can someone point me in the direction of a sensible tutorial for these things?
    (Happy to carry on using Netbeans 5.5 or to revert to Sun Studio Enterprise, which I was playing with before.)
    All help appreciated, Thanks

    - For NetBeans related questions, nbusers mailing list is more suited. It is often visited by NetBeans experts.
    http://www.netbeans.org/community/lists/top.html
    ...[email protected]
    The NetBeans users mailing list. General discussion of NetBeans use, this is the place to ask for help and to help others.... (There is a 'Subscribe' button next to the above that you can use to subscribe to the list).
    Can you try posting this question on nbusers list?
    - SJSE 8.1 is based on an older version of NB (NB5.0).
    You should definitely continue with NetBeans, since all development is now being done in NetBeans; all the major JSE modules have been moved to opensource at netbeans.org and are all being developed there. There are as yet no future plans to work on further releases for JSE.
    Please check out http://www.netbeans.org for more details.

  • Java object XSLT parameters problem. JDK vs Xalan.

    Hello all,
    I need to create a small application which requires to run some transformation interacting with a number of Java classes.
    Small example is below: I have a Java class, which I'm going to use within transformation.
    package com.example;
    public class Document
      private String filename=null;
      public String getFilename() {
        return this.filename;
    }and transformation which extracts some information from the passed parameter object
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:document="com.example.Document">
        <xsl:param name="theDocument"/>
        <xsl:template match="/">
            <example>
                <xsl:value-of select="document:getFilename($theDocument)"/>
            </example>
        </xsl:template>
    </xsl:stylesheet>The code which launches transformation is following:
            try {
                TransformerFactory factory = TransformerFactory.newInstance();
                Templates template = factory.newTemplates(new StreamSource(new FileInputStream(transformationFilename)));
                Source source = new StreamSource(new FileInputStream(theSourceFilename));
                Result result = new StreamResult(new FileOutputStream(theTargetFilename));
                Transformer transformer = template.newTransformer();
                transformer.setParameter("theDocument", theDocument);
                transformer.transform(source, result);
            } catch (TransformerConfigurationException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
        }When I run it I get
    ERROR:  'Cannot find external method 'com.example.Document.getFilename' (must be public).'
    FATAL ERROR:  'Could not compile stylesheet'at this line
      Templates template = factory.newTemplates(new StreamSource(new FileInputStream(transformationFilename)));I made a test with a variable, when Document instance is not a parameter but an instance created within transformation and assigned to an XSLT variable. Everything works fine in variable case, but not with parameter.
    Once I've added Xalan-2.7.1 .jars to the classpath it had been fixed. I guess the issue is described here (yep, I'm using 1.5).
    XSLTC does not support all the extensions that Xalan does. These extensions are beyond the definition of the JAXP and XSLT specifications. For those users impacted by this, the work around of downloading the Xalan classes from Apache is still available. Also, going forward we expect to be supporting more and more extensions in XSLTC.
    However, I'd like to find Xalan free solution. Could someone explain what is the difference and how implement the same behaviour without using Xalan?
    Thank you in advance.

    georgemc, your answer may not have helped the original poster, but it just helped me out. So, thank you very much.
    To clarify, for the benefit of anyone else who encounters this issue, it looks as if a possible cause of the 'Cannot find external method' error is that the transformer is defaulting to something - possibly XSLTC - that does not support certain extension methods. Ensuring that a recent Xalan JAR is in the classpath may resolve the problem.
    Edited by: slamci on Mar 13, 2010 11:14 AM

  • Passing objects as parameters

    Hi folks,
    I've got a general rather than a specific query here, and just need a bit of clarification as to whether or not I'm doing things right (I'm relatively new to Java).
    Basically, I've set up several "sub classes" extending a parent class. In my code, I pass an object of a subclass into another class - this class then checks to see what subclass the object belongs to before doing some more fancy stuff. It's probably easier to explain if I show you basic code, so...
    public ClassMain extends JFrame // or something
    public  ClassMain(final ParentClass MyObject) // I have a question about this
    If (MyObject instanceof SubClassA)
    ((SubClassA) myObject).setName("I'm an object of SubClassA");  // I have a question about this
    If (MyObject instanceof SubClassB)
    ((SubClassB).setName("I'm an object of SubClassB");
    // Obviously, I've printed this to the console elsewhere!
    // etc. etc.
    }Very simple stuff up there, I hope it explains what I'm trying to do. Anyway, my specific questions are:
    (1) When I originally tried to compile my application, Eclipse threw an exception and advised that I add the "final" keyword when passing the object in. To be honest, I'm at a loss why I would NEED to declare the object as "final"...I've checked out books/online resources, and I seem to be missing an explanation. Even if I'm using "gets" instead of "sets" (i.e. I'm making no modification to the object variables), I still get the same error.
    (2) While it works OK, this code:
    ((SubClassA) myObject).setName("I'm an object of SubClassA");  looks a bit wierd. It does work, but I'm convinced (I think I read it somewhere, but I've forgotten the source) there is a better way of writing this...can anyone let me know?
    That's it for now. My application works and all, so no worries there...

    Thanks all, that makes sense MLRon. Eclipse won't
    compile your app AT ALL if you don't use "final" here
    though.Yep, that's what the comment in my code said. It also stops you from saying:
    public class MyClass
        int myVariable;
        public MyClass(int myVariable)
            myVariable = myVariable; // assigns it to itself.
    }With "final", the above wouldn't compile. What is most likely intended by the above constructor is:
        public MyClass(int myVariable)
            this.myVariable = myVariable; // assigns instance variable
        }This second constructor WOULD compile with "final", and is most likely correct, where as the original is almost definitely an error.

  • How to access parameters from an object stored in a shopping-cart vector?

    Hello;
    I am writing some code that will be part of a website that will have the
    ability to allow customers to place items into a shopping cart and then
    purchase them.
    The way that the shopping cart works is that a products page is displayed on the website that has 'add' buttons on it next to each product on the page.
    When the customer clicks the 'add' button next to a particular product to purchase it, the code performs a query of a products database table for the numeric product id linked to the 'add' button they clicked.
    When the product id is found, the query then loads the
    product information for it from the DB table columns into the shopping cart
    Vector as an object in the form of a result set string. This object contains
    the parameters that define the product, i.e. product_id, product_quantity,
    date_ordered, ship_status and so on.
    In the code, when the customer is done shopping and clicks on a button
    labelled 'place order', I want the code to access the shopping cart Vector
    and extract each item object from the cart. I then want the code to be able
    to get from each item object, the parameters that make up each item as
    described above and take the values stored in each of the parameters and
    store them in variables. Finally I want to take those variables and write
    them to an orders DB table in the proper columns via a query.
    I have tried researching information on Vectors to see if I could find out a way to do this but the little information that I located did not give me a clear idea
    of how to go about writing the code, it only seemed to suggest a vague,
    rough idea as to how it might be done. I am relatively new to Java
    programming and so don't have any experience working with Vectors.
    I have enclosed the code below that shows how the items are being stored in the shopping cart Vector. Can anybody tell me how I could go about writing the code that will extract the items from the shopping cart as described above in a servlet? Any assistance you can give me will be greatly appreciated.
    Thank you!
    String productID = request.getParameter("productID");
    String qty = request.getParameter("qty");
    Vector cartlist = new Vector();
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:odbc:website", "", "");
    java.sql.Statement st = conn.createStatement();
    String query = "SELECT productID, productName, productCategory,
    productPrice from Products WHERE productID ='" + productID + "'";
    java.sql.ResultSet rs = st.executeQuery(query);
    while(rs.next()){
    cartlist.addElement(rs.getString("productID") + " " +
    rs.getString("productName") + " " +
    rs.getString("productCategory") + " " +
    rs.getString("productPrice") + " " + qty);
    } catch(SQLException sqlex){
    } catch(Exception e){
    }

    //Try Changing your code this way.
    String productID = request.getParameter("productID");
    String qty = request.getParameter("qty");
    Vector cartlist = new Vector();
    try
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:odbc:website", "", "");
         java.sql.Statement st = conn.createStatement();
         String query = "SELECT productID, productName, productCategory, productPrice from Products WHERE productID ='" + productID + "'";
         java.sql.ResultSet rs = st.executeQuery(query);
         while(rs.next())
              String productID = rs.getString("productID");
              String productName = rs.getString("productName");
              String productCategory = rs.getString("productCategory");
              String productPrice = rs.getString("productPrice");
              String productID = rs.getString("productID");
              cartlist.addElement(new AddCardElement(productID, productName, productCategory, productPrice, productID, qty));
              //class AddCardElement should be there in your application
    catch(SQLException sqlex)
    catch(Exception e)
    //you have to add a new class AddCardElement like this
    class AddCardElement
        public String m_productID;
         public String m_productName;
         public String m_productCategory;
         public String m_productPrice;
         public String m_productID;
        public GenerateLocationData(String productID, String productName, String productCategory, String productPrice, String productID, String qty)
            m_productID = productID;
              m_productName = productName;
              m_productCategory = productCategory;
              m_productPrice = productPrice;
              m_productID = productID;
    }//-Achyuth B

  • How to create objects dynamically (with dynamic # of parameters)

    I need to create a set of objects based on a definition from an XML file (obtained from the server) and add them to my scene.
    I understand how to create the object using getDefinitionByName (and the limitations regarding classes needing to be referenced to be loaded into the SWF).
    But some objects require parameters for the constructor, and some don't. The XML can easily pass in the required parameter information, but I can't figure out how to create a new object with a dynamic set of arguments (something akin to using the Function.call(obj, argsArray) method.
    For example, I need something like this to work:
    var mc=new (getDefinitionByName(str) as Class).call(thisNewThing, argsArray)
    Currently this is as far as I can get:
    var mc=new (getDefinitionByName(str) as Class)(static, list, of, arguments)
    Thoughts?

    I think what Dave is asking is a bit different.
    He's wanting to know how to invoke the constructor of an object dynamically (when he only knows the # of constructor arguments at runtime).
    This class I know will do it but seems to be a hack:
    http://code.google.com/p/jsinterface/source/browse/trunk/source/core/aw/utils/ClassUtils.a s?spec=svn12&r=12
    See the 'call' method, which first counts the # of arguments then invokes one of 'n' construction methods based on the number of constructor args.
    I've yet to find a clean AS3 way of doing things ala 'call' though.
    -Corey

  • Web Services with complext objects as method parameters

    Can anyone point me to an example of web services that accept complex objects as parameters, using annotations?
    Appreciate it.

    - For NetBeans related questions, nbusers mailing list is more suited. It is often visited by NetBeans experts.
    http://www.netbeans.org/community/lists/top.html
    ...[email protected]
    The NetBeans users mailing list. General discussion of NetBeans use, this is the place to ask for help and to help others.... (There is a 'Subscribe' button next to the above that you can use to subscribe to the list).
    Can you try posting this question on nbusers list?
    - SJSE 8.1 is based on an older version of NB (NB5.0).
    You should definitely continue with NetBeans, since all development is now being done in NetBeans; all the major JSE modules have been moved to opensource at netbeans.org and are all being developed there. There are as yet no future plans to work on further releases for JSE.
    Please check out http://www.netbeans.org for more details.

  • Object parameters with include tag

    Hello,
    I have a problem with JSP. What I wanna do is to call a JSP file with an object parameter. But all I can do is passing strings to the page.
    Since I need to iterate on the object string parameters isn't enough for me.
    Any ideas, like putting the parameter on session or build the page servlet based?
    I am confused and any help would be great.
    Thanks.
    Mehmet

    Reposted to fix syntax:
    I'm using the book "Web Development with JavaServer Pages" as a reference for writing my code. In it there is some code for iterating through an indexed JavaBean property. I am doing the exact same thing but it won't work for me. I have included the code at the end.
    If I use project.getCode() this works but when using the getProperty tag I get a null value. If I change the line
    project = projectList[a];
    to
    pageContext.setAttribute("project", projectList[a]);
    the project.getCode() doesn't work but the getProperty tag does.
    According to the book, I should be able to declare the Project object reference using a Bean tag then change the reference later.
    Is this a JRun bug or am I doing something wrong?
    <%@ page import="com.ncs.es.shrserv.v32.mtp.*" %>
    <jsp:useBean id="projects" class="ProjectList"/>
    <jsp:useBean id="project" class="Project"/>
    <%
    Project[] projectList = projects.getList();
    int size = projectList.length;
    System.out.println("size " + size);
    %>
    <% for (int a=0; a<size; a++)
    project = projectList[a];
    %>
    <TR>
    <TD WIDTH="6%">
    <a href="ProjectSetup.jsp?index=<%=project.getCode()%>"><jsp:getProperty name="project" property="code"/></a>
    </TD>
    <TD WIDTH="75%">
    <jsp:getProperty name="project" property="description"/>
    </TD>
    <TD WIDTH="11%">
    <jsp:getProperty name="project" property="version"/>
    <TD ALIGN='center' WIDTH="8%">
    <INPUT TYPE='checkbox' NAME='CbProjExport'
    VALUE='<jsp:getProperty name="project" property="id"/>'>
    </TD>
    </TR>
    <% } %>

  • Reset Text Wrap and Object Placement defaults?

    Using Pages 5.5.2 (w Yosemite).
    Wondering if there's any way to set a default preference for the Text Wrap and Object Placement parameters in the Format > Arrange tab? 
    For example, more often than not I need to have Text Wrap set to "None", rather than "Automatic".  I was at least hoping that once I'd set a particular object to "None", any new objects I created or which were dragged into that same document would inherit that same Text Wrap setting (in much the same way that any new drop shadow setting becomes the new default when applying the drop shadow effect to subsequent selections). But even THAT doesn't seem to be the case with the Text Wrap & Object Placement options -- much less being able to reset a new global preference.
    Any suggestions (which still involve using Pages 5.5.2) appreciated.
    Thanks,
    John B

    just discovered a related topic: when importing images in Pages, how do I set the default object placement to "stay on page" and "no text wrap"?
    But that thread ends up going in a slightly different direction, since having to create placeholder shapes, and then duplicating (+ individually repositioning) same, for almost every time I dragged an image into a Pages doc would actually be MORE work than the current annoyance of having to reset the Text Wrap setting for most new objects.
    I just want a way to set a global preference for that adjustment -- or at least a preference to have all new objects start off with the same Text Wrap (and Object Placement) settings as the last ones used.
    Possibility?  Or Feature Request?

Maybe you are looking for

  • White boarders around artboard when creating pdf in CS4

    Hi, have been trying to find solution for this issue for 4 hours now and im loosing my mind:)) ... so decided to ask some help from you guys. Problem: im trying to create pdf file with black background in Illustrator cs4 and white thin boarders keep

  • HP Monitor going to sleep on start up

    Ok, I've dealt with this problem long enough. I have an HP pavilion Elite, hpe 400f. Monitor worked great on it, then one night while I was checking my email, the picture went scrabled, and ever since I am faced with a "Monitor Going to sleep" error

  • Apple TV - no audio

    I have a grewt picture but no audio, I'm on Mountain Lion, Hoem Sharing is on but nothing coming from my HDMI connection from Apple TV to my television. Any thoughts

  • My mac wont power up

    My emac has suddenly stopped working. It worked fine one day and then nada. I have tried different power cables from other emacs with different sockets and still no joy. It is a 1.25ghz emac and I am puzzled as to why it has just stopped. Does anyone

  • Graph Chart settings

    Dear people, I have a chart in my code, I need to set beginning time externally ( I read it from a sting ). I need to set the first Chart Plotting point to this time , The samples/sec is also read from a txt file and has to be set extra. When code fi