Page 231 - IT-802_class_12
P. 231

In the dialog box, type a name in the Class Name text box. For our program, we type “PercentageCalculator”.
                 When you type the name of the class, the Created File field also changes automatically. Select the <default
                 package> by clicking on drop-down arrow of Package box. Click on Finish button to finish creating the New Java
                 Class File and to return to the IDE.

























             4   Click in the Code Editor Window under the Percentage Calculator. Java tab and type the code as shown below.
                 The comments inserted by NetBeans have been deleted for simplicity.

                 public class percentageCalculator {

                public static void main(String [] args){
                    int total_marks=400;
                    double marks_obtained=364;
                    double percentage;
                    percentage = (marks_obtained/total_marks)*100;

                    System.out.println(“1st Student`s percentage =” +percentage);
                    marks_obtained=214;
                    percentage = (marks_obtained/total_marks)*100;
                    System.out.println(“2nd Student`s percentage =” +percentage);

                }
                 }
             5   Click File → Save (Ctrl+S) to save the file.
             6   Click Run → Run File (Shift + F6) to execute the program. The output of the program appears in the Output window.





















                                                                               Fundamentals of Java Programming  229
   226   227   228   229   230   231   232   233   234   235   236