Multilevel Inheritance
Excersise: 5
Create a program using Multilevel Inheritance
Program
import java.io.*;
import java.lang.String.*;
class Student
{
protected String name;
int regno,pi,ji,dsi,nmi;
public void getDetails()throws IOException
{
DataInputStream din=new DataInputStream(System.in);
System.out.println("Enter the student name:");
name=din.readLine();
System.out.println("Enter the register no:");
regno=Integer.parseInt(din.readLine());
System.out.println("Enter the PIT internal mark:");
pi=Integer.parseInt(din.readLine());
System.out.println("Enter the java internal mark:");
ji=Integer.parseInt(din.readLine());
System.out.println("Enter the DS internal marks:");
dsi=Integer.parseInt(din.readLine());
System.out.println("Enter the non-major internal mark:");
nmi=Integer.parseInt(din.readLine());
}
}
class Exam extends Student
{
int pe,je,dse,nme;
public void getMark()throws IOException
{
DataInputStream din=new DataInputStream(System.in);
System.out.println("Enter the PIT external mark:");
pe=Integer.parseInt(din.readLine());
System.out.println("Enter the java external marks:");
je=Integer.parseInt(din.readLine());
System.out.println("Enter the Ds external mark:");
dse=Integer.parseInt(din.readLine());
System.out.println("Enter the non-major external mark:");
nme=Integer.parseInt(din.readLine());
}
}
class Result extends Exam
{
String res=new String();
String pr=new String();
String jr=new String();
String dsr=new String();
String nmr=new String();
String cla=new String();
int tot,pt,jt,dst,nmt;
float avg;
public void process()throws IOException
{
int count=0;
pt=pi+pe;
if (pi>=12 && pe>36)
{
pr="pass";
count++;
}
else if(pi<12&&pe>49)
{
pr="pass";
count++;
}
else pr="RA";
jt=ji+je;
if (ji>12 && je>36)
{
jr="pass";
count++;
}
else if (ji<12&&je>49)
{
jr="pass";
count++;
}
else
jr="RA";
dst=dsi+dse;
if (dsi<12&&dse>36)
{
dsr="pass";
count++;
}
else if (dsi<12&&dse>49)
{
dsr="pass";
count++;
}
else
dsr="pass";
nmt=nmi+nme;
if (nmi>12 && nme>36)
{
nmr="pass";
count++;
}
else if(nmi<12&&nme>49)
{
nmr="pass";
count++;
}
else
nmr="RA";
if (count==4)
{
tot=pt+jt+dst+nmt;
res="pass";
avg=tot/4;
if (avg>74)
cla="Distinction";
else if (avg>59)
cla="first";
else
cla="second";
}
else
{
res="pass";
tot=360;
cla="++++++++++++";
}
}
public void display()throws IOException
{
System. out.println("Manonmaniam Sundharnar University");
System.out.println("\tTirunelveli");
System.out.println("T.D.M.N.S.College,T.Kallikulam");
System.out.println("Name:"+name+"\tRegno:"+regno);
System.out.println("________________________");
System.out.println("PIT:"+"\t\t"+pi+"\t"+pe+"\t"+pt+"\t"+pr);
System.out.println("Java:"+"\t\t"+ji+"\t"+je+"\t"+jt+"\t"+jr);
System.out.println("DS:"+"\t\t"+dsi+"\t"+dse+"\t"+dst+"\t" +dsr);
System.out.println("Non:"+"\t\t"+nmi+"\t"+nme+"\t"+nmt+"\t"+nmr);
System.out.println("______________________________________");
System.out.println("RESULT:"+res+"\t"+ "TOTAL:" +tot+"\t"+ " AVERAGE:9"+avg+"\t"+"Class:" +cla);
}
}
class inherit
{
public static void main(String arg[])throws IOException
{
Result r=new Result();
r.getDetails();
r.getMark();
r.process();
r.display();
}
}
Output
Post a Comment
Thanks for your comments. Please be visit and given positive review on our site.