author (ANUPAMA KRISHNAN)
This java program using: Constructor, call by reference
This program take subject marks and name of 2 students and print their Subject wise average,student marks average.
Code:
Comment below for your query and feedback... :)
This java program using: Constructor, call by reference
This program take subject marks and name of 2 students and print their Subject wise average,student marks average.
Code:
/*This java program using: Constructor, call by reference
This program take subject marks and name of 2 students and print their Subject wise average,student marks average.*/
This program take subject marks and name of 2 students and print their Subject wise average,student marks average.*/
public class Student
{
public String name ;
public int age , maths , science , eng ;
public Student( String name1, int age1, int maths1, int science1 , int eng1 )
{
name= name1 ;
age = age1 ;
maths = maths1 ;
science = science1 ;
eng = eng1 ;
}
public static void main()
{
Student stu1 = new Student( "Rani Thomas" , 13 , 70 , 75 , 60 );//calling constructor
Student stu2 = new Student( "Rhea Anthony" , 14 , 65 , 77 , 66 );
display( stu1 , stu2 ); // call by reference
subAvgMks( stu1 , stu2 );
stuAvgMks( stu1 , stu2 );
}
public static void subAvgMks( Student s1 , Student s2 ) // method to calculate avrege marks of each subject
{
double mathsAvg = ( s1.maths + s2.maths ) / 2 ;
System.out.println(" The average marks in maths are : " + mathsAvg ) ;
double scienceAvg = ( s1.science + s2.science ) / 2 ;
System.out.println(" The average marks in science are : " + scienceAvg ) ;
double engAvg = ( s1.eng + s2.eng ) / 2 ;
System.out.println(" The average marks in english are : " + engAvg ) ;
}
public static void stuAvgMks( Student st1 , Student st2 )// method to calculate avrege marks of each students
{
double avgs1 = ( st1.maths + st1.science + st1.eng ) / 3 ;
System.out.println(" The average marks gained by " + st1.name + " is " + avgs1 ) ;
double avgs2 = ( st2.maths + st2.science + st2.eng ) / 3 ;
System.out.println(" The average marks gained by " + st2.name + " is " + avgs2) ;
}
public static void display( Student astu , Student bstu )// methods to display all results
{
System.out.println(" STUDENT 1 : " ) ;
System.out.println(" NAME : "+astu.name);
System.out.println(" AGE : "+astu.age);
System.out.println(" MATHS : "+astu.maths);
System.out.println(" SCIENCE : "+astu.science);
System.out.println(" ENGLISH : "+astu.eng);
System.out.println(" STUDENT 2 : ");
System.out.println(" NAME : "+bstu.name);
System.out.println(" AGE : "+bstu.age);
System.out.println(" MATHS : "+bstu.maths);
System.out.println(" SCIENCE : "+bstu.science);
System.out.println(" ENGLISH : "+bstu.eng);
}
}
Comment below for your query and feedback... :)
anyone one knows how to find the average of two numbers, if you know please do help i'd be grateful
ReplyDelete