Assigning strings a value?

I had another problem with nested if structure, i have tried ever way i could think of possibly to assign the value to a string. hard to explain, example below
//classCode is input from user
// classYear is the current year in highschool, i keep on getting errors no matter which way i assign the string!
i'm trying to figure out how to do this correctly
If(ClassCode = ("FR") // i know it's not correct, but i have no idea classyear= "Freshman"; // what is? same for this assignmeny!
If(grdP = 100)
grade = "A"; // results in a error, i'm real confused

Try using a switch statement to solve your problem. It'll be cleaner code and easier to read and understand.
//declare a variable
int usrInput;
if( ( usrInput >= 10 ) || ( usrInput <= 1 2) )
switch(classYear)
case 10:
classyear = "Freshman";
case 11:
classyear = "Sofmore"; etc.
Not sure if this will help but here's a project that I worked on for a class and it was assigning a string value to a variable. I used a switch statement (do you know what those are?) to determine which value was selected.
I know this is a bit long but I think it's easy enough to understand. You will have to determine what value you want to put in your if statement. Switch does not use Strings so you'll have to use an integer to determine what is selected.
import java.text.NumberFormat;                              // Java core packages
import java.util.Locale;
import javax.swing.JOptionPane;                              // Java extension packages
public class A4_512                                             // begin class definition
                                                                 // main method begins execution
                                                                 // of Java application
     public static void main( String args[] )
          int     counter,                                        // counter variable
               itmSold,                                        // holds usrInput for product sold as int data type
               qtySold = 0;                                   // holds usrInput for quantity sold as int data type
     double     itmValue = 0.00,                              // value of item sold
               totSales = 0.00;                              // total value of items sold
     String     usrInputItm = "",                              // holds usrInput for product sold as int String type
               usrInputQty = "",                              // holds usrInput for product sold as int String type
               currDay = "",                                   // String value for current day
               results = "";                                   // holds output results
                                                                 // Begin counter controlled loop
          for( counter = 0; counter <= 6; counter++ )
               switch ( counter )                              // Begin switch statement to determine day of the week
                    case 0:
                         currDay = "Sunday";
                         break;
                    case 1:
                         currDay = "Monday";
                         break;
                    case 2:
                         currDay = "Tuesday";
                         break;
                    case 3:
                         currDay = "Wednesday";
                         break;
                    case 4:
                         currDay = "Thursday";
                         break;
                    case 5:
                         currDay = "Friday";
                         break;
                    case 6:
                         currDay = "Saturday";
                         break;
                                                                 // prompt for input and read
                                                                 // product number then convert
                                                                 // data type to integer data type
               usrInputItm = JOptionPane.showInputDialog(
                    "Please enter a product number purchased on " + currDay + "\n\n Enter 0 to enter data for next day." );
               itmSold = Integer.parseInt( usrInputItm );
               while( itmSold != 0 )                         // Begin sentinel control while loop
                                                                 // if statement to determine correct product number entered
                    if( ( itmSold > 5 ) || ( itmSold < 0 ) )
                                                                 // display error message
                         JOptionPane.showMessageDialog ( null, "You must enter product number from 1 through 5.\nPlease try again.",
                              "Wrong Product Number Error", JOptionPane.ERROR_MESSAGE );
                                                                 // prompt for input and read
                                                                 // product number then convert
                                                                 // data type to integer data type
                         usrInputItm = JOptionPane.showInputDialog(
                              "Please enter a product number purchased on " + currDay + "\n\n Enter 0 to enter data for next day." );
                         itmSold = Integer.parseInt( usrInputItm );
                    else
                         switch ( itmSold )               // begin switch statement to determine value of itmSold
                              case 1:
                                   itmValue = 2.98;
                                   break;
                              case 2:
                                   itmValue = 4.50;
                                   break;
                              case 3:
                                   itmValue = 9.98;
                                   break;
                              case 4:
                                   itmValue = 4.49;
                                   break;
                              case 5:
                                   itmValue = 6.87;
                                   break;
                         }                                        // end switch statement
                                                                 // prompt for input and read
                                                                 // quantity sold then convert
                                                                 // data type to integer data type
                         usrInputQty = JOptionPane.showInputDialog(
                              "Please enter quantity sold on " + currDay );
                         qtySold = Integer.parseInt( usrInputQty );
                         totSales += itmValue * qtySold;
                                                                 // prompt for input and read
                                                                 // product number then convert
                                                                 // data type to integer data type
                         usrInputItm = JOptionPane.showInputDialog(
                              "Please enter a product number purchased on " + currDay + "\n\n Enter 0 to enter data for next day." );
                         itmSold = Integer.parseInt( usrInputItm );
                    }                                             // end if statement to determine correct product number entered
               }                                                  // end while statement
          }                                                       // end for loop
                                                                 // set currency format for output
          NumberFormat moneyFormat =
               NumberFormat.getCurrencyInstance( Locale.US );
                                                                 // add total to results
          results = "Total Sales for the week: " + moneyFormat.format( totSales );
                                                                 // show output
          JOptionPane.showMessageDialog ( null, results,
               "Results", JOptionPane.PLAIN_MESSAGE );
          System.exit( 0 );                                   // terminate application
     }                                                            // end main method
}          // end class definition

Similar Messages

  • Assigning strings a value?(revised)

    I had another problem with nested if structure, i have tried ever way i could think of possibly to assign the value to a string. hard to explain, example below
    //classCode is input from user
    // classYear is the current year in highschool, i keep on getting errors no matter which way i assign the string!
    i'm trying to figure out how to do this correctly
    If(ClassCode = ("FR")
    classyear= "Freshman";
    // i know it's not correct, but i have no idea
    // what is? same for this assignment!
    If(grdP = 100)
    grade = "A"; // results in a error, i'm real confused

    if(classCode.equals("FR"))
    classyear= "Freshman"; For objects use .equals, for primitives use "==".
    If(grdP = 100)
    grade = "A"; // results in a error, i'm real confused At a guess grade is a char,
    grade = 'A';

  • Assigning a node value from an XML variable to a String type  in Weblogic Process Integrator

    Hi,
    Is there any way to assign a node value from an XML variable to a String variable
    in Weblogic Process Integrator...
    Thanx.
    Narendra.

    Nerendra
    Are you talking about using Xpath on the XML document and assigning to a
    variable, it is unclear what you are asking
    Tony
    "Narendra" <[email protected]> wrote in message
    news:3bba1215$[email protected]..
    >
    Hi,
    Is there any way to assign a node value from an XML variable to a Stringvariable
    in Weblogic Process Integrator...
    Thanx.
    Narendra.

  • Assigning a javascript value to a JSP variable

    How do i assign a javascript value to a JSP variable?
    eg
    <%
    String JSPvar;
    %>
    <script language="JavaScript1.2">
    <!--
    var javascriptVar="hey"
    -->
    </script>
    <%
    JSPvar = javascriptVar ???
    %>

    You do know that the JSP runs on the server and generates HTML, including Javascript, that is executed on the client, don't you?

  • Assigning a number value to a line from file without array

    How do you assign a number value to a line from a file? I want to use the assigned number so that the i can use random number to randomly select a line
    Example. i have the lines A,B,C,D,E
    A
    B
    C
    D
    E
    i know that a is line 1 b is line 2 so on so on
    (1) A
    (2)B
    (3)C
    (4)D
    (5)E
    so from here i would use the random number generator so that i could randomly select one of these. I already know how to code for the number generator but how would i make it so that i can access each individual line as a number?

    ya that's what im using but reguarding the code i dont think it does what im looking for. yes it does provide a random line but wen i run it multiple times it gives me the same line repeatedly. also i need to be able to refer to that line in the future so in the code the String line gets replaced each time
    BufferedReader bF = new BufferedReader(new FileReader("someFilePath"));
              String line;
              int someRandomNumber = 9;
              int counter = 0;
              while ((line = bF.readLine()) != null){
                   if (counter == someRandomNumber){
                        break;
                   counter++;          
              System.out.println(line); //line at #someRandomNumber in the file

  • Assigning a binary value to an integer

    Hi, I am trying to assign a binary value in my program to an integer. In some assembly languages you would do the following:
    mov a, 00010101b
    for binary and for hex:
    mov a, 0E2h
    In java, you can assign a hex value with:
    int a=0x3F;
    What should I do to assign a binary value? Is it possible?
    Regards... Martin Schmiedel

    The static method parseInt in the java.lang.Integer class can be used to convert a String representing a binary number into its decimal integer value. In addition to the string representing the number, you also pass in an integer representing the radix, which for binary would be 2, hex would be 16, etc. So for example:
    int x = Integer.parseInt("00010110", 2);
    Is that what you're trying to do? Cheers,
    Chris

  • Assignment % String sx = % search goes wrong

    Hello,
    I have the following JavaScript function in my JSP:
    On Button click
    ( <INPUT type="button" name="Search" value="Search for Service" onclick="searchService(document.myform.Keyword.value);"></TD> )
    the function searchService is called:
    <SCRIPT language="JavaScript">
    function searchService(s) {
         var search = s;
         <% String sx = %> search;
         var output = "<%= agent.searchForService(sx).elementAt(0)%>";
    </SCRIPT>
    How can I assign <% String sx = %> search; ?
    The error message I get is: incompatible type for declaration. Can't convert void to java.lang.String.
    String sx = ^ 1 error
    Can anybody help me out please?
    Thanks
    Simone

    Think of the transaction of processing a JSP page as server-side, client-side and a long pipe in between (the http connection).
    First the server-side stuff is executed on the server, then the result is sent down the pipe and then the client-side stuff is executed on the client.
    If you want client-side stuff to change the server-side execution, you will need to do a round trip back to the server - i.e. post the data to another (or the same) JSP in order to continue processing.
    Sometimes it helps to think of this process as above in order to clarify the timing of when things happen.
    Hope that helped.

  • Assigning a default value to a field

    Hello Everyone,
           Could you please tell me how to assign a default value to a field in a transparent table, so that while creating an entry even if we don't enter the value, a default value will be assigned.
    Thanks,
    Anbu.

    Like this
    DATA: BEGIN OF itab OCCURS 0,
            field1 TYPE c VALUE 'X'
            field2 TYPE c,
          END OF itab.
    append itab.
    append itab.
    You will have by default X set in both rows for field1.
    Regards
    Marcin
    PS: Ooops I just noticed you meant transparent table but I wrote about internal one. As long as you maintain that table using maintenance view you can use event 05 - When Creating a New Entry and set fixed value for a field there. So whenever you create new entry it will receive that value.
    Edited by: Marcin Pciak on Jun 23, 2010 8:57 AM

  • How to send timer job email to "assigned to" feild value in a task list?

    Hi All,
    How to send timer job email  to "assigned to" field value in a task list if due date is after two days from now?

    Create a SharePoint Designer Workflow and use "pause until date" option when an new item is created/update.
    Using Server Object model, I believe you can create the timer job from item event receiver.
    --Cheers

  • How to Assign a Constant Value to a Dim. Member when pulling Master Data?

    BPC Gurus:
    I am trying load Vendor and Customer Master data into BPC dimension.  My Dimesnion has memebrs: ID, EVDESCRIPTION, PARENTH1, TYPE.  I have successfully pulled the ID and the description from 0CUSTOMER and 0VENDOR.  However, I
    need to have a ttext value for 'PARENTH1' and 'TYPE'.  For Customers, I want to add a FIXED value "'CUSTOMER' for every
    Customer ID pulled in and also for "TYPE", I want a value of "CUSTOMER".  When I maintainthe Dimension, I want to see
    th followingvalues:
    ID                          EVDESCRIPTION                                   PARENTH1                         TYPE
    0000000001         WALMART                                            CUSTOMER                        CUSTOMER
    0000000002          TARGET                                               CUSTOMER                        CUSTOMER
    and so ON
    Since we have Vendor Numbers in the same Diemsnion, when I pull Vendors, I need to have similar values as:
    ID                          EVDESCRIPTION                                   PARENTH1                         TYPE
    0000005050         ABC Supply Inc.                                   VENDOR                            VENDOR
    0000005051         BASF                                                    VENDOR                            VEDOR
    and so ON
    How can assign a Fixed value to the member Propert?  Can I achieve it in Conversion file....? 
    ( My atempts failed...).
    Any suggestion recommendation would be gretaly appreciated.
    Munna.

    Hi,
    For adding fixed values to the properties, you can use the transformation file. In the mapping section, you can specify a constant value. This value will be written to properties of all the members while importing master data. However, for parenth, its a bit different. First thing is that, you need to have a member called CUSTOMER, then only you can have CUSTOMER in the parenth column. Even if you add it and use the mapping section for this purpose, then it will write CUSTOMER to parenth for all the members (even to CUSTOMER member). And this will be wrong. So, you will need to write it manually.
    Hope you got the idea.

  • How to assign a default value to a column ?

    Hi
    In the Object browser is it possible to modifiy a column in order to assign a defalut value to the column ?
    I have a table FICHE in which I want to assign a default value 0 to a column which type is NUMBER.
    Thank you for your kind answers.
    Christian.

    Hi Christian
    For one reason or the other you can't do that using 'Create Column' or 'Modify Column'. You can only do that by issuing a SQL command : alter table fiche modify column( <column name> default 0)
    HTH
    Roel

  • How to assign a default value when there is no prompted value

    Dear all,
    I create a filter and it's value is relate to a prompt.If the prompt is not fill I found that all record is selected.
    How did I assign a default value so that when I didn't fill some value in to the prompt and still can get the result by
    the default value I set?
    Thanks a lot!

    Are you using dates for between or some character column?
    Post your example.
    Instead of between use to is equal prompts, so u will have then 2 fields one for date from a nd one for date to. Everything is the same as I wrote just repeat steps...
    You must put 2 separate fields if you are using date between and you want to have default variable for both.
    Column formula for the first calendar date prompt:
    case when 1=2 then TIMES.TIME_ID else cast ('1.1.1900' as date) end
    and for the second:
    case when 1=2 then TIMES.TIME_ID else cast ('1.1.2900' as date) end
    Now you set up default repository variable for both prompts.
    Presentation variable you put in the set presentation variable on each prompt:
    p_date_from
    p_date_to
    And in Answers filter will be like this:
    *TIMES.TIME_ID between @{p_date_from}{VALUEOF("rv_test_date_to_char")} and @{p_date_to}{VALUEOF("rv_test_date_to_char")}*
    or you can put a different default variables
    *TIMES.TIME_ID between @{p_date_from}{VALUEOF("rv_test_date_to_char_from")} and @{p_date_to}{VALUEOF("rv_test_date_to_char_to")}*
    I posted similar in my blog:
    Date between in filter and title when using presentation variable from calendar dashboard prompt or drop-down list in OBIEE
    http://108obiee.blogspot.com/2009/03/date-between-in-filter-and-title-when.html
    Regards,
    Goran O
    http://108obiee.blogspot.com
    Edited by: Goran O on 2009.04.23 03:37

  • How to assign the default value to search parameter

    Hi Experts,
    I am using search view , In this I have 5 parameter lets say Transaction Type, Partner No. etc... Now I want to assign a default value to transaction type ( lets say TA) . User should be able to see this default value in the transaction type field before pressing search button.
    How can I do it?
    My second problem is: I have configured this search view using configuration tool but I want to assign only one value to transaction type (i.e. user should not be able to add new row in the search criteria for the transaction type by using + sign)  but in rest 4 fields he can add new row and search based on that.
    Note: I am using only "Is" criteria .
    Any pointer will be helpful for me
    Thanks and regards,
    Sandeep

    Hi Sandeep,
    For the default search values, here is a solution. You have to redefine the method GET_VALUE1 of the context node
    For example if it is the BP search (component BP_HEAD_SEARCH) context node is your enhanced class: ZL_BP_HEAD__MAINSEARCH_CN00
    METHOD get_value1.
      CALL METHOD super->get_value1
        EXPORTING
          attribute_path = attribute_path
          iterator       = iterator
        RECEIVING
          value          = value.
      TRY.
    *     Delegate operation to selection parameter
          DATA: current TYPE REF TO if_bol_bo_property_access.
          IF iterator IS BOUND.
            current = iterator->get_current( ).
          ELSE.
            current = me->parameter_collection->get_current( ).
          ENDIF.
          IF current->get_property_as_string( iv_attr_name = 'ATTR_NAME' ) EQ 'XXX'.
            IF value IS INITIAL.
              value = 'Your default value'.
            ENDIF.
          ENDIF.
        CATCH cx_root.
      ENDTRY.
    ENDMETHOD.
    where XXX is the name of the field.
    Default value will then appear in your search field, but you are still able to modify it if you want...
    Regards,
    Fabian

  • Assigning LOV return Value to multiple text items

    Hi all
    I have a custom form on which i have 10 text items
    text item 1,text item 2 ....text item10
    I have a table xx_querywith fields
    text_item,query
    i have inserted into the xx_query table
    insert into xx_query(text_item,query)
    values(text_item1,'select sysdate from dual');
    insert into xx_query(text_item,query)
    values(text_item2,'select sysdate-1 from dual');
    I have created a record group dynamically and i am getting the query from the query column of the xx_query table into the record group(say test_rg)
    I have created a LOV test_lov and thr set_lov_property i have populated the test_rg query into the test_LOV
    is it possible for me to set the return item of the LOV dynamically so that i can get the LOV on the item which i want to ?
    thanks
    _

    Hi All
    thanks for your responses
    I have Created a control item and assigned the return value of the LOV to the control item
    and i have assigned the LOV to the text item that i want
    Currently when i navigate to the text item the LOV is visible
    but when i select a value from the LOV the value is not getting populated into the text item
    I have assigned the value of the control item to the text item
    but i am not sure in which trigger to write the code so as when i select the value from the LOV the value should be shown on the form populating in the text item
    Thanks

  • A question about assigning a default value

    Hi guys, I have a question about assigning a default value to a Numeric Decision CO. This Co needs 2 parameters to compare with each other. I wanna assign para1 during runtime and para2 during design time, but I have no idea how to assign a default value to para2 during design time. Can anyone help me solve this question? Thx a lot.
    BTW I`m searching an article about Time-off example`s "details". I have read several articles about time-off example, but those are not detailed enough. I wanna know about all details of COs. Can anyone forward such article to me, plz.  Thx again.^^

    Hi,
    You can assign a default value to the parameter of a callable object.
    First attach your CO to an Action.At the action level you can assign default values to the CO Parameters.
    Select the action in the design time.
    Select the parameters tab for that action.
    Select the required paramter. At the top, you can find Default value tab, with that you can assign default value.
    I think you can achieve your requirements with Business logic CO better.
    [Business Logic CO|http://help.sap.com/saphelp_nwce10/helpdata/en/44/3d3936c5c14a8fe10000000a1553f6/content.htm]
    Thanks

Maybe you are looking for

  • How can I transfer a CC Indesign license to another user?

    I am the IT manager so I purchased two licenses at two different times. They are all associated with my online ID. When I try to use the new license I am told that my ID is aleady in use on two computers - my desktop and laptop which I am legally all

  • IMac G5 Freezes

    About three weeks ago, our iMac G5 froze. Then it froze more or less every day. Then it went a week or so without freezing, then started again last week. We had an expansion memory module 512M installed, so I pulled it. Computer seemed ok for the res

  • Problem in sending mail to external id from customer exit

    Hello All, I have a problem that I am sending mail to supervisor. I have written code and it is working correctly in se38 program. This code If I keep in an exit and run tcode then it is not working and it is giving message no mail sent. Why is this

  • Installing SMC 3.5.1a on Solaris 10

    After "successfully" installing SMC via es-guiinst the process fails when attempting to use es-setup/es-guisetup. I get a message saying setup unsuccessful and pointing to a log (/var/opt/SUNWsymon/install/gui_setup_spinel.x) containg the following i

  • EPS files in ID contact sheets

    Bridge CS2 on Mac OS 10.3.9 I am trying to produce ID contact sheets generated from Bridge's Tools menu of the images on a number of CDs of product photos, but have run into a snag. I am having a recurrence of a problem once solved some time ago in t