Java Program code for implementing array of objects

import java.util.*;
class Sports
{
int cr;
boolean ingame,outgame;
Sports(boolean ig,boolean og)
{
cr=0;
ingame=ig;
outgame=og;
}
void cre()
{
if(ingame==true)
cr+=5;
if(outgame==true)
cr+=10;
}
}
class Marksheet extends Sports
{
int m1,m2,m3,tot,avg;
char grade;

Marksheet(int a,int b,int c,boolean ig,boolean og)
{
super(ig,og);
m1=a;
m2=b;
m3=c;
}

void calculate()
{
cre();
tot=m1+m2+m3;
avg=tot/3;
if(avg>=90)
{
grade='O';
cr+=15;
}
else if(avg>=80)
{
grade='E';
cr+=10;
}
else if(avg>=70)
{
grade='A';
cr+=5;
}
else if(avg>=60)
grade='B';
else if(avg>=50)
grade='C';
else if(avg>=40)
grade='D';
else
grade='F';
}
}
class Student extends Marksheet
{
int roll;
String name;
String addr;
String phno;
Student(int r,String nm,String adr,String phn,int a,int b,int c,boolean ig,boolean og)
{
super(a,b,c,ig,og);
roll=r;
name=nm;
addr=adr;
phno=phn;
}

void dispRec()
{
calculate();
System.out.println("Record is : ");
System.out.println(roll + " " + name + " " + addr + " " + phno + " " + cr);
}
}

class StudentRecord
{
public static void main(String []ar)
{
Scanner inp=new Scanner(System.in);
int rl;
String nm,adr,phn;
boolean p,q;

int g,i,a,b,c;
System.out.println("Enter the number of students : ");
g=inp.nextInt();
Student ob[]=new Student[g];
for(i=0;i<g;i++)
{
System.out.print("Enter the roll  number : ");
rl=inp.nextInt();
//inp.nextLine();
System.out.print("Enter the Name : ");
nm=inp.nextLine();
inp.nextLine();
System.out.print("Enter the Address : ");
adr=inp.nextLine();

System.out.print("Enter the Phone Number : ");
phn=inp.nextLine();

System.out.print("Enter First Marks : ");
a=inp.nextInt();

System.out.print("Enter Second Marks : ");
b=inp.nextInt();

System.out.print("Enter Third Marks  : ");
c=inp.nextInt();
System.out.print("Play Indoor Game (true/false)  : ");
p=inp.nextBoolean();
System.out.print("Play Outdoor Game (true/false)  : ");
q=inp.nextBoolean();


ob[i]=new Student(rl,nm,adr,phn,a,b,c,p,q);

}
for(i=0;i<g;i++)
ob[i].dispRec();

}
}

Comments

Popular posts from this blog

Pascal Triangle using 2D array

JAVA program to add two distance