JAVA Program to Display Student Result using Interface

JAVA Program to Display Student Result using Interface:


interface calculateResult
{
 public void calculate_total();
 public void calculate_percentage();
 public void calculate_grade();
}

class student implements calculateResult
{
  int no,m1,m2,m3 ;
  String name;
  int tot;
 float per;
  char  gd ;

  public void get_marks(int mr1,int mr2,int mr3)
  {
    m1=mr1;
    m2=mr2;
    m3=mr3;
  }
  public void calculate_total()
  {
   tot=m1+m2+m3;
   System.out.println("Total:"+tot);
  }
  public void calculate_percentage()
  {
  per=tot/3;
  System.out.println("Percentage:"+per);
  }
  public void calculate_grade()
  {
   if(per>=75)
    gd='A';
   else
   {
       if(per<=75 && per>=50)
        gd='B';
       else
      {
       if(per<=50 && per>=40)
       gd='C';
      }
    }

    System.out.println("Grades:"+gd);
  }

  public static void main(String args[])
  {
  student s=new student();
  s.get_marks(60,80,70);
  s.calculate_total();
  s.calculate_percentage();
  s.calculate_grade();
  }
}

OUTPUT:

Total:210
Percentage:70.0
Grades:B



Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 18 =