Help in control structure

hey guys nid help on switch structure how can i place mathematical operation/ computation inside a switch without causing any problem...ive seen some switch sample but it only focuses on strings..
...you see my problem is:
Mail order house sells 5 different product..prod1-$2.98, prod2-$4.50, prod3- $9.98, prod4- $4.49 and prod 5- $6.87..Write an application that reads a series of pairs of numbers as follows:
a)Product number
b)Quantity sold for one day
Program should use a switch structure to help determine the retail price for each product.Your program should calculate and display total retail value of all product sold last week. Use a TextField to obtaimn the product number from the user. Use sentinel -controlled loop to determine when the product should stop looping and display final results.
//Fig 4.9: Average.java
//Class average program with sentinel-controlled repetitions
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class AverageMod {
     public static void main( String args[] )
          int quant,
               prodnum,
               gradeCounter,
               gradeValue,
               gtotal,
               total;
          double      
                    average;
          String
                    num1,
                    input;
          total = 0;
          gradeCounter = 0;
          /*input = JOptionPane.showInputDialog( "Enter Grade, -1 to Quit:");
          gradeValue = Integer.parseInt(input);
          num1= JOptionPane.showInputDialog( "Enter Product Number, -1 to Quit");
          prodnum = Integer.parseInt(num1);
          while (prodnum != -1) {
          switch ( prodnum ) {
               case 1:
               //     casetotal = casetotal + 2.98;
                    JOptionPane.showMessageDialog(null, "1 - $2.98");
                    break;
               case 2:
               //     casetotal = casetotal + 4.50;
                    JOptionPane.showMessageDialog(null, "2 - $4.50");
                    break;
               case 3:
                    JOptionPane.showMessageDialog(null, "3 - $9.98");
                    break;
               case 4:
                    JOptionPane.showMessageDialog(null, "4 - $4.49");     
                    break;
               case 5:
                    JOptionPane.showMessageDialog(null, "5 - $6.87");     
                    break;
               default:
                    JOptionPane.showMessageDialog(null, "Invalid value entered" );     
                    break;
               }//end switch
     /*     while (prodnum != -1) {//start while*/
               total = prodnum + total ;
               gradeCounter = gradeCounter + 1;
               num1= JOptionPane.showInputDialog( "Enter Product Number, -1 to Quit");
               prodnum = Integer.parseInt(num1);
               num1= JOptionPane.showInputDialog( "Enter Quantity, -1 to Quit");
               quant = Integer.parseInt(num1);
          } //end while
          DecimalFormat twoDigits = new DecimalFormat( "0.00");
          if ( gradeCounter != 0) {
               average = (double) total/ gradeCounter;
               JOptionPane.showMessageDialog( null, "Class Average is" + twoDigits.format( average ),
               "Class Average",
               JOptionPane.INFORMATION_MESSAGE );
          else
          JOptionPane.showMessageDialog( null,"No Product number entered", "Class Average ", JOptionPane.INFORMATION_MESSAGE );
          System.exit( 0 );
i already created this code but i dont know how to make the computation..thanks GodBless

Can you be more specific about your problem ?
I mean what actually you are trying to do and what all inputs you are
expecting from user ?

Similar Messages

  • === PLease HELP= looping control structure

    Hi,
    I am new to Java and really have difficulities on this ,
    can anyone advice how to do it?????
    Thanks for your time...
    I need to write a small looping program. This program generates a random number between 1-10 (inclusive). Based on the random value generated, the program will loop and display a line of output for each iteration of the loop. Also display the random number.
    Output would be;
    The random number 7
    This is loop 1
    This is loop 2
    This is loop 3
    This is loop 4
    This is loop 5
    This is loop 6
    This is loop 7

    queeny,
    The random number 7Q. So, how do you get a random number?
    A. you google "java random number".
    This is loop 1..7Q. OK. So, how do I loop in java?
    A. you google "java loop"
    Do you see a pattern here... I could replicate the fundamentals of any/every page related to "java whatever" indexed by google, but I'm too fat, too ugly, and far too lazy to attempt it.
    Google is your new best friend... and permit me to suggest that Sun Micro Systems (the originators of the Java language) have the best java tutorials... http://java.sun.com/docs/books/tutorial/ and they're FREE!

  • How can I print source code with connecting lines on control structures?

    Anyone know of any programs that will format source code printouts and print connecting lines from the start to the end of control structures (such as: if--"end if", while-"end while" etc.)?

    Indentations and comments do help read source code. However, when you have a large program with many levels of nesting of control structures the readability of the code (even with indentations) becomes very difficult.

  • Why not a parallel control structure?

    I often come across the need to run several identical and independent operations at the same time. I almost always end up doing them sequentially instead because I can use a for loop for this. It would be a great asset to parallel programming if there was a "for loop" like structure that ran all iterations at the same time (multithreaded, reentrant support, of course). One could then send a command and wait for a response on several instruments at once (in parallel) without having to spend as much time waiting sequentially for each to complete. The input tunnels could be arrays in which the number of elements determined the number of simultaneous panes running each with its own member of the array. The iteration terminal could output
    a sequential number for each logically parallel pane as well. For debug the user could have a way to select which pane to view as all would be running. The output tunnels could also be arrays. Each pane would operate independently from all the others. I think that this is a very useful suggestion and should be incorporated into the product even though it is less intuitive than the other control structures. It provides a capability that currently is hard to attain (though not impossible) but often useful in constructing time efficient hardware control.

    > I have raised this with NI about two years ago
    > thinking that it would not require a huge architectural change but
    > rather a compiler addition only but it has yet to surface in the last
    > three releases.
    Adding a structure like this would be a decent amount of work. It would
    be yet another way of specifying parallel diagrams. I'm not saying that
    LV will never add a structure to make something like this easier, but it
    is more than ajust a compiler tweak. In the meantime, try something
    like the following.
    Place your code to do instrument control in a VI.
    Make the VI reentrant.
    Decide how many parallel tasks you want to carry out. Yes, this is
    static, but there are real limits to how many of these that can be
    carried out anyway.
    So something like two or four is probably a good
    start. Four threads is how many threads LV now spins up for the
    standard execution system by default in LV7 so that seems like a good
    number.
    In your For loop, place N of the reentrant subVIs, index out the
    elements and pass them to the subVI.
    Make sure the subVI tests for a refnum of not a refnum so that you can
    handle indexing past the array.
    This pattern, especially with a diagram comment, should make it pretty
    obvious that you have unrolled the loop and should make it pretty easy
    to change the unrolling number.
    Greg McKaskle

  • SAP TM - Change in Search help in UI structure does not reflect in FPM screen

    Hi Experts,
    We have a FBI view in which we have added a search help to a UOM field by adding the standard search help /SCMTMS/SH_QUANTITY in the UI structure. The standard search help is showing in the UI. Now we want to add a filter in the search help by adding a constant value 'MASS' on the parameter DIMID (dimension) so that only the UOM's for weight are displayed. But this change is not reflecting on the FBI screen. Even if we remove the search help from the structure the change is not reflecting.
    Can you please suggest if there is any way by which the FBI view can be refreshed so that it displays the recent UI search help addition.

    Hi Sayak,
    Except the report above, you can also attach the search help to the UI fields in the view exit class configured in your FBI view dynamically.
    BR, Dawson

  • Change in Search help in UI structure does not reflect in FPM screen

    Hi Experts,
    We have a FBI view in which we have added a search help to a UOM field by adding the standard search help /SCMTMS/SH_QUANTITY in the UI structure. The standard search help is showing in the UI. Now we want to add a filter in the search help by adding a constant value 'MASS' on the parameter DIMID (dimension) so that only the UOM's for weight are displayed. But this change is not reflecting on the FBI screen. Even if we remove the search help from the structure the change is not reflecting.
    Can you please suggest if there is any way by which the FBI view can be refreshed so that it displays the recent UI search help addition.

    Hi Sayak,
    Except the report above, you can also attach the search help to the UI fields in the view exit class configured in your FBI view dynamically.
    BR, Dawson

  • I need help with event structure. I am trying to feed the index of the array, the index can vary from 0 to 7. Based on the logic ouput of a comparison, the index buffer should increment ?

    I need help with event structure.
    I am trying to feed the index of the array, the index number can vary from 0 to 7.
    Based on the logic ouput of a comparison, the index buffer should increment
    or decrement every time the output of comparsion changes(event change). I guess I need to use event structure?
    (My event code doesn't execute when there is an  event at its input /comparator changes its boolean state.
    Anyone coded on similar lines? Any ideas appreciated.
    Thanks in advance!

    You don't need an Event Structure, a simple State Machine would be more appropriate.
    There are many examples of State Machines within this forum.
    RayR

  • I need help with controlling two .swf's from third.

    Hi, thanks for reading!
    I need help with controlling two .swf's from third.
    I have a problem where I need to use a corporate designed
    .swf in a digital signage solution, but have been told by the legal
    department that it can not be modified in any way, I also can't
    have the source file yada yada. I pulled the .swfs from their
    website and I decompiled them to see what I was up against.
    The main swf that I need to control is HCIC.swf and the
    problem is it starts w/ a preloader, which after loading stops on a
    frame that requires user input (button press) on a play button,
    before the movie will proceed and play through.
    What I have done so far is to create a container swf,
    HCIC_container.swf that will act as Target for the HCIC.swf, and
    allow me to send actionscript to the file I'm not allowed to
    modify.
    I managed to get that done with the help of someone on
    another forum. It was my hope that the following script would just
    start HCIC.swf at a frame past the preloader and play button, and
    just play through.
    var container:MovieClip = createEmptyMovieClip("container",
    getNextHighestDepth());
    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(this);
    mcLoader.loadClip("MCIC.swf", container);
    function onLoadInit(mc:MovieClip) {
    mc.gotoAndPlay(14);
    But unfortunately it didn't solve my problem. Because there
    is a media-controller.swf, that is being loaded by HCIC.swf that
    has the controls including the play button to start HCIC.swf.
    Here's a link to a .zip file with all 3 .swf files, and all 3
    .fla files.
    http://www.axiscc.com/temp/HCIC.zip
    What I need to do is automatically start the HCIC.swf file
    bypassing the pre-loader and play button without editing it or the
    media-controller.swf in anyway. So all the scripting needs to be
    done in HCIC_container.swf.
    I know this is confusing, and its difficult to explain, but
    if you look at the files it should make sense.
    ActionScripting is far from my strong point, so I'm
    definitely over my head here.
    Thanks for your help.

    Got my solution on another forum.
    http://www.actionscript.org/forums/showthread.php3?t=146827

  • PLM-CPR Multilevel Controlling (Structure Elemen, Automatic) :: WBS

    We use Multilevel Controlling (Structure Elemen, Automatic) controlling
    method for automatic cProjects project transfer in PS projects. We need
    WBS element key (PRPS-POSID) would be transferted from a cProject
    field with external number (user field or standard field "Number"
    on "General data" tab for cProjects task modifired for external
    maintenence - see message 0000082945 2008). We also would like to
    transfer not all tasks and phases into WBS elemets. We need to transfer
    only some of them.
    Are there any ideas for standart functions modifacation?
    Ñould anyone please name functional modules used in automatic cProjects
    project transfer to PS projects.
    Product versions:
    SAP cProject 4.0 (SP 0011)
    SAP ECC 6.0
    Best regards
    Edited by: Aleksey Teplouhov on Feb 18, 2008 9:11 AM
    Edited by: Aleksey Teplouhov on Feb 18, 2008 9:12 AM

    Hi All,
              Even i need information on this..
    regards,
    rajesh.

  • Getting PL/SQL:ORA-00933 when using CASE logic as a control structure

    Hello Everybody,I have created a PL/SQL block(Control Structure) to calculate bonus of employees based on salary of the employee,but I get errors like ORA-00933 and ORA-06550.Given below is the PL/SQL block which I tried to implement
    SQL> DECLARE
    2
    3 v_EMPNO NUMBER(7,2):= &p_EMPNO;
    4 v_SAL EMP.SAL%TYPE;
    5 v_BONUS NUMBER;
    6
    7 BEGIN
    8 SELECT SAL
    9 FROM EMP
    10 INTO v_SAL
    11 WHERE EMPNO = v_EMPNO;
    12
    13 v_BONUS :=
    14 CASE v_SAL
    15 WHEN v_SAL = 0 THEN 0
    16 WHEN v_SAL < 1500 THEN (0.1*v_SAL)
    17 WHEN v_SAL BETWEEN 1500 AND 3000 THEN (0.15*v_SAL)
    18 WHEN v_SAL > 3000 THEN (0.20*v_SAL)
    19 END;
    20
    21 DBMS_OUTPUT.PUT_LINE(' EMPNO '||v_EMPNO||' SALARY '||v_SAL||' BONUS '||V_BONUS);
    22
    23 END;
    24 /
    Enter value for p_empno: 7100
    old 3: v_EMPNO NUMBER(7,2):= &p_EMPNO;
    new 3: v_EMPNO NUMBER(7,2):= 7100;
    INTO v_SAL
    ERROR at line 10:
    ORA-06550: line 10, column 7:
    PL/SQL: ORA-00933: SQL command not properly ended
    ORA-06550: line 8, column 7:
    PL/SQL: SQL Statement ignored
    Is it that I can not use "CASE" as a control structure in the above block , when I code
    "SELECT SAL
    FROM EMP
    INTO v_SAL
    WHERE EMPNO = v_EMPNO;" to get v_SAL and then use it in CASE exp to calculate a value for v_Bonus.
    Kindly let me know.

    Hi,
    The CASE Expression is also available in PL/SQL.
    Try this code:
    DECLARE
       V_EMPNO   NUMBER (7, 2)  := 7788;
       V_SAL     EMP.SAL%TYPE;
       V_BONUS   NUMBER;
    BEGIN
       SELECT SAL
         INTO V_SAL
         FROM EMP
        WHERE EMPNO = V_EMPNO;
       V_BONUS :=
          CASE
             WHEN V_SAL = 0
                THEN 0
             WHEN V_SAL < 1500
                THEN (0.1 * V_SAL)
             WHEN V_SAL BETWEEN 1500 AND 3000
                THEN (0.15 * V_SAL)
             WHEN V_SAL > 3000
                THEN (0.20 * V_SAL)
          END;
       DBMS_OUTPUT.PUT_LINE (   ' EMPNO '
                             || V_EMPNO
                             || ' SALARY '
                             || V_SAL
                             || ' BONUS '
                             || V_BONUS
    END;As you are Using,Comparison Expression to find a match, Your Searched CASE Expression should be something like this.
    DECLARE
      sal       NUMBER := 2000;
      sal_desc  VARCHAR2(20);
    BEGIN
      sal_desc := CASE
                     WHEN sal < 1000 THEN 'Low'
                     WHEN sal BETWEEN 1000 AND 3000 THEN 'Medium'
                     WHEN sal > 3000 THEN 'High'
                     ELSE 'N/A'
                  END;
      DBMS_OUTPUT.PUT_LINE(sal_desc);
    END;If you are Using CASE as a Value matching then your piece of code should be like this..
    DECLARE
      deptno     NUMBER := 20;
      dept_desc  VARCHAR2(20);
    BEGIN
      dept_desc := CASE deptno
                     WHEN 10 THEN 'Accounting'
                     WHEN 20 THEN 'Research'
                     WHEN 30 THEN 'Sales'
                     WHEN 40 THEN 'Operations'
                     ELSE 'Unknown'
                   END;
      DBMS_OUTPUT.PUT_LINE(dept_desc);
    END;Thanks,
    Shankar

  • Search help at a structure field does not appear

    Hi there,
    i have created a customer own search help and for a first try i have assigned it to a screen field. This worked propperly but i receive values for three fields (document number, company code and fiscal year) from that search help - what has been succesfully testet in SE11 and worked ok.
    To assign all exporting fields to my screen I deleted the search help at the screen field and I created a copy of RF05L structure and assigned my search help to the document number there. My screen fields belong now to a structure and the type of that structure is my version of RF05L, at first with type, later changed to like.
    So my screen field must have the search help from that structure, but it has no search help at all.
    After some trials I deleted my field from the screen and added it again based on my structure and changed the name to my internal structure name for the document field. This was the only trial where the search help appeared afterwards but as I did the same to the two other fields it disappeared again and I could not make it visible until now.
    What shall I do?
    Thank you in advance for any hints.

    Hi Axel,
    When you are adding the screen fields - are you sourcing them from the Program OR Data dictionary.
    You should source it from the Data Dictionary and ensure the screen fields attribute "From Dict." checkbox is marked in the "Dict" tab.
    Hope this helps.
    Regards,
    Aditya

  • User Exit to change idoc control structure

    Hi everybody.
    Does In a inbound idoc process exist any userexit to modify the control structure of the idoc????
    Thanks

    Hi ,
    I dont think you can change the control record of any IDOC .
    If you look at an example Function module MASTERIDOC_CREATE_CREMAS , used to create Vendor IDOCS ,
    the call customer-function has only the idoc data record as tables parameter .

  • Pse give me the document on control structures

    any body have document on control structures pse send me
    (at new,at end,on change of,at start ,at last)

    If it is control break statements.... then here is the types and explanation
    1. AT NEW f.
    2. AT END OF f.
    3. AT FIRST.
    4. AT LAST.
    Effect
    In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT . The sequence of statements which lies between them is then executed if a control break occurs.
    You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.
    The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .
    At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:
    All default key fields (on the right) are filled with "*" after the current control level key.
    All other fields (on the right) are set to their initial values after the current control level key.
    Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).
    At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.
    Notes
    When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.
    If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.
    With LOOP s on extracts, there are also special control break control structures you can use.
    Note
    Runtime errors
    SUM_OVERFLOW : Overflow when calculating totals with SUM .
    Variant 1
    AT NEW f.
    Variant 2
    AT END OF f.
    Effect
    f is a sub-field of an internal table processed with LOOP . The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.
    Example
    DATA: BEGIN OF COMPANIES OCCURS 20,
    NAME(30),
    PRODUCT(20),
    SALES TYPE I,
    END OF COMPANIES.
    LOOP AT COMPANIES.
    AT NEW NAME.
    NEW-PAGE.
    WRITE / COMPANIES-NAME.
    ENDAT.
    WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
    AT END OF NAME.
    SUM.
    WRITE: / COMPANIES-NAME, COMPANIES-SALES.
    ENDAT.
    ENDLOOP.
    The AT statements refer to the field COMPANIES-NAME .
    Notes
    If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name . If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.
    By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.
    A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.
    Note
    Runtime errors
    AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.
    AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.
    ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.
    Variant 3
    AT FIRST.
    Variant 4
    AT LAST.
    Effect
    Executes the appropriate sequence of statements once during the first ( AT FIRST ) or last ( AT LAST ) loop pass.
    Example
    DATA: BEGIN OF COMPANIES OCCURS 20,
    NAME(30),
    PRODUCT(20),
    SALES TYPE I,
    END OF COMPANIES.
    LOOP AT COMPANIES.
    AT FIRST.
    SUM.
    WRITE: 'Sum of all SALES:',
    55 COMPANIES-SALES.
    ENDAT.
    WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
    55 COMPANIES-SALES.
    ENDLOOP.
    ON CHANGE OF f.
    Executes the processing block enclosed by the "ON CHANGE OF f" and "ENDON" statements whenever the contents of the field f change (control break processing).
    Normally, you use the statement to manipulate database fields during GET events or SELECT/ENDSELECT processing.
    ON CHANGE OF is unsuitable for recognizing control levels in loops of this type because it always creates a global auxiliary field which is used to check for changes. This global auxiliary field is only changed in the relevant ON CHANGE OF statement. It is not reset when the processing enters loops or subroutines, so unwanted effects can occur if the loop or subroutine is executed again. Also, since it is set to its initial value when created (like any other field), any ON CHANGE OF processing will be executed after the first test, unless the contents of the field concerned happen to be identical to the initial value.
    DATA T100_WA TYPE T100.
    SELECT * FROM T100
    INTO T100_WA
    WHERE SPRSL = SY-LANGU AND
    MSGNR < '
    ORDER BY PRIMARY KEY.
    ON CHANGE OF T100_WA-ARBGB.
    ULINE.
    WRITE: / '**', T100_WA-ARBGB, '**'.
    ENDON.
    WRITE: / T100_WA-MSGNR, T100_WA-TEXT.
    ENDSELECT.
    Displays all messages with their numbers in the logon language, provided the number is less than '010'.
    Each time the message class changes, it is output.
    AT END OF f.
    f is a sub-field of an internal table or extract dataset (EXTRACT) which is being processed with LOOP, i.e. the variants 1 and 2 only make sense within a LOOP.
    Both "AT NEW f." and "AT END OF f. " introduce processing blocks which are concluded by " ENDAT.".
    These processing blocks are processed whenever the contents of a field f or a sub-field defined before f change as a result of processing with LOOP. "AT NEW f." begins a new group of (table) lines with the same contents as the field f while "AT END OF f." concludes such a group.
    Within the AT ... ENDAT processing of internal tables, all argument fields following f are filled with "*".
    Examples
    1. AT for sub-fields of an internal table
    DATA: BEGIN OF COMPANIES OCCURS 20,
    NAME(30),
    PRODUCT(20),
    SALES TYPE I,
    END OF COMPANIES.
    LOOP AT COMPANIES.
    AT NEW NAME.
    NEW-PAGE.
    WRITE / COMPANIES-NAME.
    ENDAT.
    WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
    AT END OF NAME.
    SUM.
    WRITE: / COMPANIES-NAME, COMPANIES-SALES.
    ENDAT.
    ENDLOOP.
    The AT statements refer to the field COMPANIES-NAME.

  • Please help in Decision Control Structure ..Fix it

    This is using BufferedReader
    import java.io.*;
    public class DCS2{
         public static void main (String [] args)
              throws IOException{
                   BufferedReader myInput = new BufferedReader (new InputStreamReader(System.in));
                   int  al, nmp, brc,ma, ad, ir, code;
                   double i;
                   String name = "" , description = "";
                   System.out.println ("Enter Your Barrower's Name");
                   name = myInput.readLine();
                   System.out.println("Enter Amount Loan");
                   al = Integer.parseInt(myInput.readLine());
                   System.out.println("Enter No. Of Months to Pay");
                   nmp = Integer.parseInt(myInput.readLine());
                   System.out.println("Enter Barrowers Rank code [ 1A - 2B]");
                   code = Integer.parseInt(myInput.readLine());
                   switch (code){
                        case 1:
                             description = "SENIOR";
                   if(al >= 10001){
                        ir = .075;  // this line is the only one in the if
                        i = al*ir*nmp; // this always executes
                        ma = ad/nmp;   // so does this
                   else if ((al < 10000) && (al >= 6001)){ //this is an error
                        ir = .06;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if ((al < 6000) && (al >= 3001)){
                         ir = .045;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   }     else if (al > 3000){
                        ir = .03;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   }else
                             break;
                        case 2:
                             description = "JUNIOR";
                   if(al >= 10001){
                        ir = .085;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if ((al < 10000) && (al >= 6001)){
                        ir = .07;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if ((al < 6000) && (al >= 3001)){
                       ir = .055;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if (al > 3000){
                        ir = .04;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                else
                             break;
                        default:
                             System.out.println("A or B only");
                             break;
                                       System.out.println("Barrower's Name: " + name);
                                       System.out.println("Rank Description : " + description);
                                       System.out.println("Amount Loan: " + al);
                                       System.out.println("Interest: " + i);
                                       System.out.println("Amount Due: " + ad);
                                       System.out.println("Monthly Amortization: " + ma);
    }this using JOptionPane..
    import javax.swing.io.*;
    public class DCS2b{
         public static void main (String [] args){
                   int code, al, nmp, brc;
                   float tf = 0 , ir = 0;
                   String name = "" , description = "";
                   name = JOptionPane.showInputDialog("Enter Your Barrower's Name");
                 al = JOptionPane.showInputDialog("Enter Your Amount Loan");
                   nmp = JOptionPane.showInputDialog("Enter No. Of Months to Pay");
                   code = Integer.parseInt(JOptionPane.showInputDialog("Enter Barrowers Rank code [ A - B]"));
                   switch (code){
                        case A:
                             description = "SENIOR";
                   if(al >= 10001)
                        ir = .075;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   else if ((al < 10000) && (al >= 6001))
                        ir = .06;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   else if ((al < 6000) && (al >= 3001))
                       ir = .045;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   else if (al > 3000)
                        ir = .03;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                  else
                             break;
                        case B:
                             description = "JUNIOR";
                   if(al >= 10001)
                        ir = .085;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   else if ((al < 10000) && (al >= 6001))
                        ir = .07;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   else if ((al < 6000) && (al >= 3001))
                       ir = .055;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   else if (al > 3000)
                        ir = .04;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                  else
                             break;
                        default:
                             System.out.println("A or B only");
                             break;
                                       JOptionPane.showMessageDialog(null, "Hello " + name + "!", "name", "Rank Description : " + description , "description" , "Amount Loan: " + al , "al", "Interest: " + i , "i", "Amount Due: " + ad , "ad", "Amount Due: " + ad , "ad" , "Monthly Amortization: " + ma, "ad",JOptionPane.PLAIN_MESSAGE);
    }In First code. this is error.
    --------------------Configuration: <Default>--------------------
    C:\Users\asus\Documents\Comsys\DCS2.java:21: possible loss of precision
    found   : double
    required: int
                        ir = .075;  // this line is the only one in the if
                                         ^
    C:\Users\asus\Documents\Comsys\DCS2.java:27: possible loss of precision
    found   : double
    required: int
                        ir = .06;
                                         ^
    C:\Users\asus\Documents\Comsys\DCS2.java:31: possible loss of precision
    found   : double
    required: int
                         ir = .045;
                                          ^
    C:\Users\asus\Documents\Comsys\DCS2.java:35: possible loss of precision
    found   : double
    required: int
                        ir = .03;
                                         ^
    C:\Users\asus\Documents\Comsys\DCS2.java:44: possible loss of precision
    found   : double
    required: int
                        ir = .085;
                                         ^
    C:\Users\asus\Documents\Comsys\DCS2.java:48: possible loss of precision
    found   : double
    required: int
                        ir = .07;
                                         ^
    C:\Users\asus\Documents\Comsys\DCS2.java:52: possible loss of precision
    found   : double
    required: int
                       ir = .055;
                                     ^
    C:\Users\asus\Documents\Comsys\DCS2.java:56: possible loss of precision
    found   : double
    required: int
                        ir = .04;
                                         ^
    8 errors
    Process completed.2nd Code ...
    --------------------Configuration: <Default>--------------------
    C:\Users\asus\Documents\Comsys\DCS2b.java:18: 'else' without 'if'
                   else if ((al < 10000) && (al >= 6001))
                            ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:22: 'else' without 'if'
                   else if ((al < 6000) && (al >= 3001))
                            ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:26: 'else' without 'if'
                   else if (al > 3000)
                            ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:30: 'else' without 'if'
                  else
                        ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:38: 'else' without 'if'
                   else if ((al < 10000) && (al >= 6001))
                            ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:42: 'else' without 'if'
                   else if ((al < 6000) && (al >= 3001))
                            ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:46: 'else' without 'if'
                   else if (al > 3000)
                            ^
    C:\Users\asus\Documents\Comsys\DCS2b.java:50: 'else' without 'if'
                  else
                        ^
    8 errors
    Process completed.Edited by: optimumgiant on Aug 17, 2010 7:50 PM

    in BufferReader
    import java.io.*;
    public class DCS2{
         public static void main (String [] args)
              throws IOException{
                   BufferedReader myInput = new BufferedReader (new InputStreamReader(System.in));
                   int  brc,  code;
                   double al, ad, nmp;
                   double ir = 0;
                   double i = al*ir*nmp;
                   double ma = ad/nmp;
                   String name = "" , description = "";
                   System.out.println ("Enter Your Barrower's Name");
                   name = myInput.readLine();
                   System.out.println("Enter Amount Loan");
                   al = Integer.parseInt(myInput.readLine());
                   System.out.println("Enter No. Of Months to Pay");
                   nmp = Integer.parseInt(myInput.readLine());
                   System.out.println("Enter Barrowers Rank code [ 1A - 2B]");
                   code = Integer.parseInt(myInput.readLine());
                   switch (code){
                        case 1:
                             description = "SENIOR";
                   if(al >= 10001){
                        ir = .075;  // this line is the only one in the if
                        i = al*ir*nmp; // this always executes
                        ma = ad/nmp;   // so does this
                   else if ((al < 10000) && (al >= 6001)){ //this is an error
                        ir = .06;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if ((al < 6000) && (al >= 3001)){
                         ir = .045;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   }     else if (al > 3000){
                        ir = .03;
                        i = al*ir*nmp;
                        ma = ad/nmp;
                   }else
                             break;
                        case 2:
                             description = "JUNIOR";
                   if(al >= 10001){
                        ir = .085;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if ((al < 10000) && (al >= 6001)){
                        ir = .07;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if ((al < 6000) && (al >= 3001)){
                       ir = .055;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                   else if (al > 3000){
                        ir = .04;
                        i = al*ir*nmp;
                        ma = ad/nmp;}
                else
                             break;
                        default:
                             System.out.println("A or B only");
                             break;
                                       System.out.println("Barrower's Name: " + name);
                                       System.out.println("Rank Description : " + description);
                                       System.out.println("Amount Loan: " + al);
                                       System.out.println("Interest: " + i);
                                       System.out.println("Amount Due: " + ad);
                                       System.out.println("Monthly Amortization: " + ma);
    }this is problem
    --------------------Configuration: <Default>--------------------
    C:\Users\asus\Documents\Comsys\DCS2.java:9: variable al might not have been initialized
                   double i = al*ir*nmp;
                                       ^
    C:\Users\asus\Documents\Comsys\DCS2.java:9: variable nmp might not have been initialized
                   double i = al*ir*nmp;
                                             ^
    C:\Users\asus\Documents\Comsys\DCS2.java:10: variable ad might not have been initialized
                   double ma = ad/nmp;
                                        ^
    3 errors
    Process completed.Edited by: optimumgiant on Aug 17, 2010 8:22 PM

  • Need help with control system that reduces a flat output signal every time a certain input exceeds given value

    I'm having difficulty setting up a closed loop control system that reduces one of my voltage outputs (connected to a high voltage system) by 30% every time a measured voltage exceeds a certain threshold value.  I'm using a USB 6229 DAQ.  I've been trying to create a waveform that looks like a DC signal, but the only waveforms that I can seem to manipulate while my VI is running are the stock waveform types.  Also, I've tried to use a formula node or conditional structure to update the output value every time the measured voltage exceeds a given value, but everything I do reinitializes the output value every time it runs or won't store the previous signal value.  I'm using LabVIEW 8.6 and don't have the PID or similar express VI's.  I've attached the mess I've got working right now.  Can anyone help?  I'm really stuck!
    Thanks! 
    Attachments:
    HiV step down.vi ‏40 KB
    output control.vi ‏100 KB

    I'm sorry it's such a mess; I'm still pretty new at this.  These are both little driver programs for a larger overall control program. 
    Output control is meant to send a flat signal to the DAQ whose value can be manipulated while the VI is running.  I have the second activated segment merely to check the values being output.  I didn't realize I attached a version with a meaningless control...I had a control where the user would put in the stating voltage (the high voltage source has a 1V-100V setting for external control).  I've attached this slightly different but equally dysfunctional version.  Ideally, I would have liked something like the analog signal generator vi to come with an input wiring for offset on the DC signal.  Most of the code was diabled because it is copied from an example; it is largely rubbish.  I initially used the DAQ Assistant, but when things weren't working out I switched to putting in each step manually to try to troubleshoot.
    As far as HiV step down is concerned, I've tried something different with a nested case structure (if that's the right terminology?), and I've attached that file.  I think this problem has been solved, but you never know!
    Attachments:
    output control slightly different.vi ‏100 KB
    HiV step down w case structures.vi ‏44 KB

Maybe you are looking for