Page 275 - ComputerScience_Class_11
P. 275

6          double avg_marks;
                   7          void accept()

                   8          {
                   9              Scanner sc=new Scanner(System.in);

                  10              System.out.println("Enter your name:");
                  11              name=sc.nextLine();

                  12              System.out.println("Enter marks in 2 subjects:");
                  13              marks1=sc.nextInt();

                  14              marks2=sc.nextInt();

                  15              System.out.println("Enter your age:");
                  16              age=sc.nextInt();

                  17          }
                  18          void compute()

                  19          {
                  20              max_marks=(marks1>marks2)?marks1:marks2;

                  21              avg_marks=(marks1+marks2)/2.0;

                  22          }
                  23          void display()

                  24          {
                  25              System.out.println("Name of the student : "+name + " Age : "+age);

                  26              System.out.println("Marks:"+marks1+","+marks2);
                  27              System.out.println("Maximum Marks:"+max_marks);

                  28              System.out.println("Average:"+ avg_marks);

                  29          }
                  30          public static void main(String args[])

                  31          {
                  32              student_marks ob=new student_marks();

                  33              ob.accept();
                  34              ob.compute();

                  35              ob.display();

                  36          }
                  37      }








                                                                                           Methods and Constructors  273
   270   271   272   273   274   275   276   277   278   279   280