Passing rational number as parameter??

Hi i need to write a rational number class that adds/subtracts etc two rational numbers when i run the program i can enter one rational number but when i go to add subtract or whatever an try to enter another rational number as a parameter i get found int but expected Rational. I am trying to enter like 1/100 but it says its an int? How do i enter a rational as a parameter.
A code template was provided and i completed it as seen below. What is the problem?
public class Rational
    private int num;
    private int denom;
    public Rational()
    public Rational(int n, int d)
        num = n;
        denom = d;
    public Rational add(Rational rhs)
        return new Rational(num*rhs.denom+rhs.num*denom, denom*rhs.denom);
    public Rational subtract(Rational rhs)
        return new Rational(num*rhs.denom-rhs.num*denom, denom*rhs.denom);
    public Rational multiply(Rational rhs)
        return new Rational((num*rhs.num), denom*rhs.denom);
    public Rational divide(Rational rhs)
        return new Rational((num*rhs.denom), denom*rhs.num);
    public String toString()
        return (num +  "/" + denom);    
    public static void main(String[] args)
        Rational r1 = new Rational(1, 2); 
        Rational r2 = new Rational(3, 4);
        Rational result = r1.add(r2);
        System.out.println(result);
}Any help appreciated!

C00kie_m0nster wrote:
Hi i need to write a rational number class that adds/subtracts etc two rational numbers when i run the program i can enter one rational number but when i go to add subtract or whatever an try to enter another rational number as a parameter i get found int but expected Rational. I am trying to enter like 1/100 but it says its an int? How do i enter a rational as a parameter.You're literally trying to pass "1/100" as an argument? How should Java know that you want it to use your Rational class in this case? Hint: it doesn't.
If you want to pass a Rational as the argument, then you need to construct one. Try using "new Rational(1, 100)" (without the quotes, obviously) as the parameter.
A code template was provided and i completed it as seen below. What is the problem?There's nothing wrong with the code.

Similar Messages

  • How to pass any number of parameter in a sequence call

    Hi,
    I have a sequence that aims to do the same job for one or several same elements typed. eg:
    subsequenceA : 
    foreach element in (all elements array)
     //do the job
    endfor
    now in my caller I would like to call subsequenceA in several ways :
    subsequenceA(firstElement)
    subsequenceA(firstElement, secondElement)
    subsequenceA(firstElement, secondElement, .... , lastElement)
    Is it possible ?
    Another question : is it possible to do a call of subsequence in a pre-expression ?
    Solved!
    Go to Solution.

    Yes, build an array of strings and pass them as string-array. Maybe you want to add a numeric parameter "array size", but that is optional as the subsequence can easily get that information from the array itself.
    Norbert
    PS: Don't mark an answer as solution as long as you have questions left on that topic.
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Can not pass Number type parameter to a portlet.

    I created a portal applicaiton with a jspx page.
    when click on a row of the table , a portlet will get the id of the row, and portlet will be refreshed.
    The id type is Number.
    when running, logs contains a error:
    "PortletModelImpl> <setParameterValue> Cannot set parameter Param1 on PortletBinding OmniPortlet4_1 with a value that is not a String or String Array."
    if you change the id type to String, everything will be OK.
    but the id type should be number, how to solve this problem.

    You should pass the value as a string to your portal and in your portlet convert it back to a number.
    If you really want to pass the Number object instead of a string, you can always use events instead of just passing parameters. When you use events, you can attach a payload to the event which can be any type as long as it is serializable.

  • Can a url referencing an Application Process pass more than one parameter?

    Hello,
    I have a page in an application that uses pl/sql to generate a list of links.
    The purpose of each link is to call another pl/sql procedure which in turn opens/runs a report external to the APEX application (either a call to Oralce Application Server generate live or pull clob stored in database). If the URL calls the pl/sql procedure directly I lose session state and no longer know who the user is. To maintain session state the URL references an APPLICATION_PROCESS. I would like to pass a number of parameters, but can only seem to pass one, using javascript to pass the value to a hidden item which is then accessed in the procedure called by the APPLICATION_PROCESS.
    Can I pass more than one parameter?
    My URL:
    https://<server>/pls/apex/f?p=V('APP_ID'):0:V('APP_SESSION'):APPLICATION_PROCESS=MY_PROCESS:NO::P1NAME:P1VALUE
    I could pass all the parameters in P1VALUE and using a special character delimiter break it up again in the javascript, but would prefer not to.
    Thanks for any help,
    Jock

    Did you mean something like this?
    https://<server>/pls/apex/f?p=V('APP_ID'):0:V('APP_SESSION'):APPLICATION_PROCESS=MY_PROCESS:NO::P1NAME,P2NAME,P3NAME:P1VALUE,P2VALUE,P3VALUE
    Best Regards, Kostya Proskudin

  • How do I pass the exact datetime parameter in a procedure.

    How do I pass the exact datetime parameter in a procedure.
    Hi All,
    I have a datetime problem which is driving me crazy.
    I need pass a datetime field as a parameter in an oracle procedure exactly as below with timestamp.
    Example: '6/01/2005 5:25:24 AM'
    SQL > exec myprod(‘value1’,’value2’,’value3’, to_date('6/01/2005 5:25:24 AM','dd-mm-yyyy hh24:mi:ss'));
    I get an error “INVALID MONTH”
    Next Changed to_date to to_char
    SQL > exec myprod(‘value1’,’value2’,’value3’, to_char('6/01/2005 5:25:24 AM','dd-mm-yyyy hh24:mi:ss'));
    I get a different error, “INVALID NUMBER”
    Next pass the datetime as it is.
    SQL > exec myprod(‘value1’,’value2’,’value3’, '6/01/2005 5:25:24 AM');
    I get an error “INVALID MONTH”
    Here is the my procedure.
    CREATE OR REPLACE PROCEDURE myprod (
    p_value1 varchar2,
    p_value2 varchar2,
    p_value3 varchar2 ,
    p_value4 date )
    IS
    filehandler UTL_FILE.FILE_TYPE;
    va_currentdate DATE;
    BEGIN
    SELECT sysdate
         INTO va_currentdate
    FROM dual;
    END;
    Do you know any solutions for this problem.
    Thanks

    What is your NLS_DATE_FORMAT value?
    There seem to be some implicit data conversions in your arguments.
    SQL> select parameter,value from nls_session_parameters where parameter like '%DATE%';
    PARAMETER                                                    VALUE
    NLS_DATE_FORMAT                                              YYYY-MM-DD HH24:MI:SS
    NLS_DATE_LANGUAGE                                            AMERICAN
    SQL> select to_date('6/01/2005 5:25:24 AM','dd-mm-yyyy hh24:mi:ss') from dual;
    select to_date('6/01/2005 5:25:24 AM','dd-mm-yyyy hh24:mi:ss') from dual
    ERROR at line 1:
    ORA-01830: date format picture ends before converting entire input string
    SQL> select to_date('6/01/2005 5:25:24 AM','dd-mm-yyyy hh:mi:ss am') from dual;
    TO_DATE('6/01/20055
    2005-01-06 05:25:24

  • How to Pass personal number(pernr) to the ESS Webdynpro ABAP Application

    Hi,
    How to pass personal number of employee to the standard ESS webdynpro ABAP application as application parameter of iview.
    Thanks
    Srikanth

    Hi
    For WebDynpro application in iView there is a property to set Parameter for WebDynpro application.
    Handel these passed parameters in Default plug of Interface Controller.
    Note string passed as parameter in iview is case sensitive.
    Try this code to get URl of Deployed application
    String appURL = null;
    try {
         WDDeployableObjectPart currentAppPart =wdThis
                                  .wdGetAPI()
                                  .getComponent()
                                  .getApplication()
                                  .getDeployableObjectPart();
    appURL = WDURLGenerator.getApplicationURL(currentAppPart);
    } catch (final WDURLException ex) {
    wdComponentAPI.getMessageManager().reportException(
                             new WDNonFatalException(ex),
                             false);
    Mandeep Virk

  • Oracle 9i - passing a string as parameter when integer is required yet

    Dear all;
    I am trying to fix this problem with a limited amount effort and also prevent redesigning it as well. I know it is completely wrong but it was done by a past developer and I am just trying to make a simple twick to it. I will try to explain my current problem so please bear with me
    I have a table with a field called SN which is number type field, I have a select statement similar to this below
    select stype from tbl_one where sn = 1ok, the select statement works for numbers and numbers with dash(e.g 03-2). In the case of numbers with dash, it returns null which is okay now, I am having a bit of problems where sometimes the user entry is a an actual string like this (cat). Now the select statement isnt going to work for this case because I am going to get a Ora-00904 - invalid identifier error.
    The solution I had in mind is first use a regular expression to determine whether the parameter is a string or a numeric value and if it is a numer value pass it as a parameter to the select statment if not, then just return null in the select statement. However, since I am using oracle 9i I cant use regualr expression is there any suitable sql statment i can use in replacement of a regular expression or any other ideas.
    All help is appreciated. Thank you.

    Hi,
    user13328581 wrote:
    ... the select statement works for numbers and numbers with dash(e.g 03-2). That's actually not a number with a dash. That's a subtraction operation involving two numbers, 03 (which is the same as 3) and 2. 3 - 2 = 1, so it's the same as typing 1.
    The solution I had in mind is first use a regular expression to determine whether the parameter is a string or a numeric value and if it is a numer value pass it as a parameter to the select statment if not, then just return null in the select statement. However, since I am using oracle 9i I cant use regualr expression is there any suitable sql statment i can use in replacement of a regular expression or any other ideas.If you just want to see if the string s contains anything other than a digit, use
    LTRIM ( s
          , '0123456789'
          )  IS NOT NULLThe condition above will be TRUE when s contains anything other than a digit.
    If you want to check for signs, decimal points, and scientific notation, then see this thread:
    How to identify if a Varchar2 string has a-z characters?
    for a user-defined function.
    Edited by: Frank Kulash on Apr 21, 2011 11:28 AM

  • How to pass variable number of parameters to a FORM.

    Hi,
    What is the correct syntax to pass variable number of parameters to a subroutine?
    PERFORM TEST TABLES BRETURN USING TEST_NAME CHANGING MY_OUTPUT.
    FORM TEST TABLES RETURN STRUCTURE BAPIRET2
              ITAB STRUCTURE ITABLE_LINE OPTIONAL
              USING VALUE(NAME) TYPE STRING
              CHANGING VALUE(OUTPUT) TYPE STRING.
    The above code does not work. How can we specify an optional parameter?
    Thanks and Regards,
    Sheetal
    Message was edited by: Sheetal Pisolkar

    Hi,
    I am trying to use a subroutine instead of function.A FUNCTION understands optional keyword.
    How can this work for a FORM?
    CALL FUNCTION 'TEST'
         EXPORTING
              MY_OUTPUT = 'output'
         IMPORTING
              TEST_NAME = 'mytest'.     
    FUNCTION TEST
    *     EXPORTING
    *          VALUE(OUTPUT) TYPE STRING
    *     IMPORTING
    *          VALUE(NAME) TYPE STRING
    *     TABLES
    *          RETURN STRUCTURE BAPIRET2 OPTIONAL
    *          ITAB STRUCTURE ITABLE_LINE OPTIONAL          
    ENDFUNCTION.
    PERFORM TEST USING TEST_NAME CHANGING MY_OUTPUT.
    FORM TEST TABLES RETURN STRUCTURE BAPIRET2 OPTIONAL
    ITAB STRUCTURE ITABLE_LINE OPTIONAL
    USING VALUE(NAME) TYPE STRING
    CHANGING VALUE(OUTPUT) TYPE STRING.
    ENDFORM.
    Is this be possible?
    Thanks
    Sheetal.

  • To find number of parameter from request

    Freinds,
    Is there any way to find out number of parameter submitted from request object. But the constraint will be with out going through loop.
    Example
    int count = 0;
              Enumeration list = request.getParameterNames();
              while (list.hasMoreElements())     {
                   count++;
                   list.nextElement();
              }

    Can some body help me to resolve the warning created by this line
    ArrayList paramList = null;
    paramList = new ArrayList(Collections.list(request.getParameterNames()));CheckFilter.java:96: warning: [unchecked] unchecked conversion
    found : java.util.Enumeration
    required: java.util.Enumeration<T>
    paramList = new ArrayList(Collections.list(request.getParameterNames()));
    ^
    CheckFilter.java:96: warning: [unchecked] unchecked method invocation: <T>list(java.util.Enumeration<T>) in java.util.Collections is applied to (java.util.Enumeration)
    paramList = new ArrayList(Collections.list(request.getParameterNames()));
    ^
    CheckFilter.java:96: warning: [unchecked] unchecked call to ArrayList(java.util.Collection<? extends E>) as a member of the raw type java.util.ArrayList
    paramList = new ArrayList(Collections.list(request.getParameterNames()));

  • Pass table name as parameter in prepared Statement

    Can I pass table name as parameter in prepared Statement
    for example
    select * from ? where name =?
    when i use setString method for passing parameters this method append single colon before and after of this parameter but table name should be send with out colon as SQL Spec.
    I have another way to make sql query in programing but i have a case where i have limitation of that thing so please tell me is it possible with prepared Statment SetXXx methods or not ?
    Thanks
    Haroon Idrees.

    haroonob wrote:
    I know ? is use for data only my question is this way to pass table name as parameterI assume you mean "how can I do it?" As I have already answered "is this the way?" with no.
    Well, I would say (ugly as it is) String concatenation, or stored procedures.

  • How to Pass a multi-select parameter in BI to a PL/SQL Program

    I am trying to pass a BI report parameter which is multi-select enabled in BI Enterprise Stand-Alone reporting tool. eg. it comes out in the data model like this: <P_CLASS_CODE>[DISABLED_VETERAN_OWNED, HUB_ZONE, LARGE_BUSINESS]</P_CLASS_CODE>
    to a pl/sql stored procedure. (this is some kind of record set)
    This works when passing the parameter as bind variable being passed to and IN CLAUSE. However, In my case I need a little bit more flexibilty with the programming so I need to get the value into PL/SQL so I can work with the individual values in the record set.
    I am trying to figure out which collection type or record type I can use in pl/sql to be able to parse out the elements in the collection from within a stored procedure so I can loop through the elements.
    I am trying to call the BI before report trigger in the data template like this:
    <dataTrigger name="beforeReportTrigger" source="XXAPRPT03_SUPPLIER_DIVERSITY.before_report_trigger(:p_class_code)"/>
    this call refers to the default package
    I get this error: 'Invalid column type'
    what type should I be using in my procedure definition to support the multi-selection record set which my parameter is passing from BI.

    Hi,
    Okie :) please feel free to post any problem :)
    Please apply the patch that has the fix for this issue:
    [Patch 9791839|https://updates.oracle.com/ARULink/PatchDetails/process_form?patch_num=9791839]
    The above link worked fine for me .
    Ideally, you should pick up the latest patch, which is [ Patch 11846804|https://updates.oracle.com/ARULink/PatchDetails/process_form?patch_num=11846804]
    Click on View Read me for install instructions. Let me know if you find any problem with patch install.
    Regards,
    Ajay Kumar

  • How to select data from a table by passing document number from another tab

    How to select data from a table by passing document number from another table.
    for eg:-
    I want to display name, adres, region from ADRC table
    by using field delivery document number
    Kind Regards,
    Shanbagavalli.S

    Hi Shanbagavalli,
    There are multiple solutions to this questions a few i will try to answer and then you can take the best required for your requirements.
    **Consider that you have a Internal table having document number from other table..
    SELECT NAME ADRES REGION FROM ADRC
           INTO IT_ADRC
           FOR ALL ENTRIES IN IT_DOC
           WHERE DOCUMENT_NO = IT_DOC-DOCUMENT_NO.
    **Consider that you have 1 document number then
    SELECT NAME ADRES REGION FROM ADRC
         INTO IT_ADRC
         WHERE DOCUMENT_NO = W_DOCUMENT_NO.
    Hope this solves your problem.
    Regards,
    Kunjal

  • Creation of an RFC to pass notification number from IOMS into SAP.

    hi sap,
    i have a  requirment to such as:
         Creation of an RFC to pass notification number from IOMS into SAP. The RFC containing notification number must access notification details via transaction IW23.
         Creation of an RFC to pass notification field specific information from SAP to IOMS. Upon accessing the notification inside SAP the following field information must be passed back to IOMS.
    can you please help me out with the RFC which would be much helpful to me.
    when i give the RFC then through the RFC the IOMS will pass the NOTIFICATION NUMBER. Based on the notication number i have to pass the data that belongs to that perticlar NUMBER.
    your help is much aprreicated and thanks in advance.
    regards,
    laya.

    I dont know what is IOMS and what platform they are using.
    If you want to access data from Non-SAP system or Insert from non SAP system, you need to develop remote enabled function modules, check for standard function modules.
    Check package IWOC, for standard function modules.
    Thanks and Regards,

  • How to pass more than one parameter using common...

    Hi,
    I am using ODP.NET with my 2005 VB
    I want to create function from where I can pass more than one parameter to execute SP, or query just like i created for SQL SERVER as below
    Public shared Function CreateParameter(ByVal paramname As String, ByVal paramvalue As Object) As DbParameter
    Dim param As DbParameter
    param = New SqlParameter
    param.ParameterName = paramname
    param.Value = paramvalue
    Return param
    End Function
    Public Shared Function ExecuteQuery(ByVal sql As String, ByVal commtype As CommandType, ByVal ParamArray parameter As DbParameter())
    Dim cmd As DbCommand = New SqlCommand()
    cmd.Connection = OpenConnection()
    cmd.CommandType = commtype
    cmd.CommandText = sql
    cmd.Parameters.AddRange(parameter)
    Dim RetVal As Integer = cmd.ExecuteNonQuery()
    Return RetVal
    End Function
    specially part is in bold to be converted
    I tried like but oracleCommand.parameters doesnt support AddRange
    please help me out
    Regards

    Hello,
    I used the following way:
    pCommand.CommandText = "Update " + sDataTable + " set "
    + sColumnName + " = :1 ";
    pCommand.Parameters.Add("ValueToDb",
    this.DefaultDbType,
    this.m_Value,
    System.Data.ParameterDirection.Input);
    Of course, you can add :2,... to your command text, too.
    The way back is:
    sEndOfTheClause += " RETURNING " + sDataTable + "." + sColName + " INTO :iNewValue";
    pCommand.CommandText = ... + sEndOfTheClause;
    pCommand.Parameters.Add("iNewValue", this.DefaultDbType,
    ParameterDirection.Output);
    bool bReturn = (pCommand.ExecuteNonQuery() != 0);
    if ((bReturn == true) && (pCommand.Parameters.Count > 0))
    this.Value = DataService.Convert<DATA_TYPE>(pCommand.Parameters[0].Value);
    ....

  • How to pass more than one parameter

    Hello,
    This is my code.
    How to pass more than one parameter:
    SELECT:responsibility_name responsibility_name,
    LPAD(' ', 6*(LEVEL-1))
      || menu_entry.entry_sequence sequence ,
      LPAD(' ', 6*(LEVEL-1))
      || menu.user_menu_name SubMenu_Description ,
      LPAD(' ', 6*(LEVEL-1))
      || func.user_function_name Function_Description ,
      LPAD(' ', 6*(LEVEL-1))
      || menu_entry.prompt prompt
      ,menu.menu_id ,
      func.function_id
      --menu_entry.grant_flag Grant_Flag ,
      --DECODE( menu_entry.sub_menu_id , NULL, 'FUNCTION' , DECODE( menu_entry.function_id , NULL, 'SUBMENU' , 'BOTH') ) Type
    FROM fnd_menu_entries_vl menu_entry ,
      fnd_menus_tl menu ,
      fnd_form_functions_tl func
    WHERE menu_entry.sub_menu_id    = menu.menu_id(+)
    AND menu_entry.function_id      = func.function_id(+)
    AND MENU.LANGUAGE(+) = 'US'
    AND FUNC.LANGUAGE(+) = 'US'
    --AND func.user_function_name LIKE '%Primary Care Providers%'
    AND grant_flag                  = 'Y'
      START WITH menu_entry.menu_id =
      (SELECT menu2.menu_id
      FROM fnd_menus_tl menu2,apps.fnd_responsibility_vl resp
      WHERE menu2.menu_id=resp.menu_id
      and resp.responsibility_name= :responsibility_name
      --and menu2.user_menu_name = ('ATCO HR INQ USER'
      AND LANGUAGE = 'US'
      CONNECT BY MENU_ENTRY.MENU_ID = PRIOR MENU_ENTRY.SUB_MENU_ID
       and menu_entry.function_id not in (select func.function_id
                                       from --fnd_form_functions_vl fnc,
                                       apps.fnd_resp_functions exc,
                                       apps.fnd_responsibility_vl res
                                      where func.function_id = exc.action_id
                                      and res.responsibility_name =:responsibility_name
                                      and res.responsibility_id=exc.responsibility_id)
      and menu_entry.sub_menu_id  not in (select menu.menu_id
                                       from --fnd_menus_vl imn,
                                       apps.fnd_resp_functions exc,
                                       apps.fnd_responsibility_vl res
                                       where menu.menu_id = exc.action_id
                                       and res.responsibility_name =:responsibility_name
                                      and res.responsibility_id=exc.responsibility_id)
    ORDER SIBLINGS BY menu_entry.entry_sequence;
    Thank you for your help
    Shuishenming

    Hi, Ming,
    One way is to put the "parameters" in a table, and join to that table in your query.  If you make it a Global Temporary Table, then multiple sessions can run the query at the same time, and each can be seeing different responsibilities.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.  Since this problem involves parameters, you should give a couple of different sets of parameters, and the results you want from the same sample data for each set.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

Maybe you are looking for

  • How can i remove the gift card credits from my apple account ?

    i´ve already put the credits on my account, but before i try to buy anything apple store keep asking me the awser for the secret questions and i forgot it, so i creat a new account and i want my credits back to use on my new account what should i do

  • Change of file type

    I have a fair amount of picture files either stored as TIFF or JPEG in various subfolders. Since I upgraded to Tiger 10.4.3 (I believe but am not sure, anyway since recently) some of the files appear randomly in Finder as a "Unix executable file". No

  • JAXP vs JAXB

    Hi there, Since there are so many API's to work with XML, and being these Sun specifications, what are the really differences between them? And when should I use one instead of the other. Many Thanks, MeTitus

  • My new hp photosmart printer 7525 will not print to photo paper always prints on regular paper tray

    I have the hp photosmart 7525 wireless printer. When I try to print a picture it doesnt use the photo paper, it keeps using the regular paper.  I have Windows 8.

  • Upgrading OS to use Adobe CS3, but still require access to Classic (OS 9.2)

    I need to upgrade my OS to use Adobe Creative Suite 3 (according to Adobe, requirements for this are OSX10.4.8 to OSX10.5) but also need to maintain access to the Classic environment (OS 9.2), to access legacy documents (in earlier versions of PageMa