Page 46 - IP
P. 46

Fee for different hobbies are as follows:
                        Hobby             Fee
                        Dancing          1000
                        Drawing          1500
                        Music              2000
                        Singing           2500
                        Help him in writing the code to do the following:

                      i.     As per the hobby chosen in the hobby combo box, fee should be displayed
                             in  the respective text  field  named t1  as  per the criteria  given above after
                             clicking on “Check Fee” button.
                      ii.    If a candidate belongs to “Jr. Category” then a discount of 10% should be
                             given in displayed in the text field.
                      iii.   After clicking on the “Net Fee” button, Net Fee should be calculated and
                             displayed in the respective text field as per the given formula:
                                                   Net Fee = Fee – Discount
                      iv.    Write suitable java code to close the application.
                      v.     Write java statement to add a new hobby “Reading” in the combo box at
                             run time.
                                                                OR
                        Write java statement to make the Net Fee text field named txtNetFee un-editable
                        at run time.

                  Ans:  i. int x=c1.getSelectedIndex();
                           int fee=0;
                           if(x==0)
                           fee=1000;
                          else if(x==1)
                             fee=1500;
                             else if(x==2)
                             fee=2000;
                             else if(x==3)
                             fee=2500;
                             t2.setText(""+fee);

                        (1.5 Mark for correct code)

                         ii.
                         double disc=0;
                         int fee=Integer.parseInt(t2.getText());
                         if(r2.isSelected())
                         disc=fee*10/100;
                         t3.setText(""+disc);

                         (1.5 Mark for correct code)

                         iii.
                         double disc=Double.parseDouble(t3.getText());
                         int fee=Integer.parseInt(t2.getText());
                         double net=fee-disc;
                         t4.setText(""+net);

                         (1 Mark for correct code)



                                                            9
   41   42   43   44   45   46   47   48   49   50   51