Page 12 - KMK PREPSPM2 1819 ANSWER
P. 12

SULIT     No. Matrik…………………………………….… No. Kad Pengenalan…………………………..  SC015



                                                                                                 [1 mark]
                                          b*b – Math.sqrt(4*a*c);

                                            
                                     c.  7
                                            
                                                                                                 [1 mark]
                                          7*x/y;

                              (iii)   Complete the Java program for the problem statement below.

                                     “Calculate and display the bonus earned by an insurance agent which
                                     is always 10% of his total sales. Given that his basic salary is rm400,
                                     calculate the net salary for an insurance agent.”
                                                                                                [3 marks]
                                      import java.util.Scanner;
                                      class NetSalary{
                                         public static void main(String[] ar){
                                            Scanner sc=new Scanner(System.in);
                                            double totalSale, netSalary;

                                            totalSale=sc.nextDouble();
                                            netSalary = 400 + (0.1*totalSale);
                                            System.out.println(netSalary);
                                         }
                                      }

                       (c)    Control structures can be divided into three (3) types; sequence, selection, and
                              repetition.
                               (i)   Find the output of the following Java program given a set of data as
                                     below.

                                       import java.util.Scanner;
                                       class Triangle{
                                          public static void main(String[] ar){
                                             Scanner sc=new Scanner(System.in);
                                             double base, height, area;

                                             for(int i=0;i<2;i++){
                                                base=sc.nextDouble();
                                                height=sc.nextDouble();
                                                area=0.5*base*height;
                                                System.out.println(“\t\tArea=”+area);
                                             }
                                          }
                                      }

                                                          base                 height
                                                            3                    4
                                                            6                    8




                                                           12                                SULIT
   7   8   9   10   11   12   13   14   15   16