Define a class Student with four data members such as name, roll no, sub1, sub2.
- Define appropriate methods to initialize and display the value of data members.
- Also calculate total marks and percentage scored by student.
class Student
{
int roll_no,sub1,sub2,total;
String name;
float per;
Student(int a,String b,int c,int d)
{
roll_no=a;
name=b;
sub1=c;
sub2=d;
}
void cal()
{
total=sub1+sub2;
per=(float)total/200*100;
}
void display()
{
System.out.println("Name of student="+name);
System.out.println("Roll number="+roll_no);
System.out.println("Subject1 marks="+sub1);
System.out.println("Subject2 marks="+sub2);
System.out.println("Total marks="+total);
System.out.println(" Percentage="+per);
}
public static void main(String args[])
{
Student s1=new Student(11,"Swati",68,82);
s1.cal();
s1.display();
}
}
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment