0% found this document useful (0 votes)
22 views9 pages

Ex - 1 Java

The document contains 3 Java classes that model student data and grades. The classes use inheritance and arrays to calculate student attendance, marks in various subjects, averages, and letter grades. Student details like name, city and age are input from the user. Attendance is calculated as a percentage and used to adjust subject marks. Marks in various subjects are stored in an array. The average and letter grade are determined and student data is printed out.

Uploaded by

aravind100305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views9 pages

Ex - 1 Java

The document contains 3 Java classes that model student data and grades. The classes use inheritance and arrays to calculate student attendance, marks in various subjects, averages, and letter grades. Student details like name, city and age are input from the user. Attendance is calculated as a percentage and used to adjust subject marks. Marks in various subjects are stored in an array. The average and letter grade are determined and student data is printed out.

Uploaded by

aravind100305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

CLASS:
import java.lang.*;
import java.util.*;
class Student
{ Scanner sc=new Scanner(System.in);
int age;
String name,city;
String ch;
float av;
Student(String n,String c,int a)
{
this.name=n;
this.city=c;
this.age=a;
attendanceCal();
}
void attendanceCal()
{
float th,ab,pe;
int m;
System.out.print("enter total hours:");
th=sc.nextInt();
System.out.print("enter no of hours absent:");
ab=sc.nextInt();
float pre=th-ab;
pe=((pre/th)*100);
//System.out.println(pe);
if(pe>90)
m=5;
else if(pe>85 && pe<90)
m=4;
else if(pe>80 && pe<85)
m=3;
else if(pe>70 && pe<80)
m=2;
else if(pe>60 && pe<70)
m=1;
else
m=0;

//System.out.print(m);
calculateGrade(m);
}
void calculateGrade(int m)
{ int ma=m;
Scanner sc=new Scanner(System.in);
System.out.print("enter 1st subject mark out of 95:");
int m1=sc.nextInt();
m1=m1+ma;
System.out.print("enter 2nd subject mark out of 95:");
int m2=sc.nextInt();
m2=m2+ma;
System.out.print("enter 3rd subject mark out of 95:");
int m3=sc.nextInt();
m3=m3+ma;
System.out.print("enter 4th subject mark out of 95:");
int m4=sc.nextInt();
m4=m4+ma;
System.out.print("enter 5th subject mark out of 95:");
int m5=sc.nextInt();
m5=m5+ma;

av=(m1+m2+m3+m4+m5)/5;

if(av>90)
ch="O";
else if(av<90 && av>85)
ch="A+";
else if(av<85 && av>80)
ch="A";
else if(av<80 && av>70)
ch="B+";
else if(av>60 && av<70)
ch="B";
else if(av<60 && av>50)
ch="C";
else if(av<50)
ch="F";
//printData();
}
void printData()
{
System.out.println("NAME-"+name+" CITY-"+city+" AGE-"+age+"
AVERAGE MARK-"+av+" GRADE-"+ch);
}
}
class Main
{ static Student [] s=new Student[2];
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
//Student [] s=new Student[2];

for(int i=0;i<2;i++)
{ String n,c;
int a;
//Scanner sc=new Scanner(System.in);
System.out.print("enter age:");
a=sc.nextInt();
System.out.print("enter name:");
n=sc.next();
System.out.print("enter city name:");
c=sc.next();
inputData(a,n,c,i);
if(i==0)
{
System.out.println("ENTER NEXT STUDENT DETAILS:");
}
}
for(int i=0;i<2;i++)
{
s[i].printData();
}
}
static void inputData(int a, String n,String c,int i)
{ //Student [] s=new Student[2];
//String n,c;
//int a,i;
n=n;
a=a;
c=c;
i=i;

s[i]=new Student(n,c,a);

}
}
2. INHERRITANCE:
import java.util.*;
class Student
{
int age;
String name,city;
String ch;
float av;
Student(int a,String n,String c)
{
this.age=a;
this.name=n;
this.city=c;
System.out.println(this.city);
}
void printData(String name,String city,int age,float av,String ch)
{
System.out.println("NAME-"+name+" CITY-"+city+" AGE-"+age+"
AVERAGE MARK-"+av+" GRADE-"+ch);
}
}
class attendanceCal extends Student
{
float th,ab,pe;
int m;

attendanceCal(int a,String n,String c)

{ super(a,n,c);
Scanner sc=new Scanner(System.in);

System.out.print("enter total hours:");


th=sc.nextInt();
System.out.print("enter no of hours absent:");
ab=sc.nextInt();
float pre=th-ab;
pe=((pre/th)*100);
//System.out.println(pe);
if(pe>90)
m=5;
else if(pe>85 && pe<90)
m=4;
else if(pe>80 && pe<85)
m=3;
else if(pe>70 && pe<80)
m=2;
else if(pe>60 && pe<70)
m=1;
else
m=0;
//System.out.println(m);
}

}
class calculateGrade extends attendanceCal

calculateGrade(int a,String n,String c)

{ super(a,n,c);

//int m1,m2,m3,m4,m5;
int ma=m;
Scanner sc=new Scanner(System.in);
System.out.print("enter 1st subject mark out of 95:");
int m1=sc.nextInt();
m1=m1+ma;
System.out.print("enter 2nd subject mark out of 95:");
int m2=sc.nextInt();
m2=m2+ma;
System.out.print("enter 3rd subject mark out of 95:");
int m3=sc.nextInt();
m3=m3+ma;
System.out.print("enter 4th subject mark out of 95:");
int m4=sc.nextInt();
m4=m4+ma;
System.out.print("enter 5th subject mark out of 95:");
int m5=sc.nextInt();
m5=m5+ma;

av=(m1+m2+m3+m4+m5)/5;

if(av>90)
ch="O";
else if(av<90 && av>85)
ch="A+";
else if(av<85 && av>80)
ch="A";
else if(av<80 && av>70)
ch="B+";
else if(av>60 && av<70)
ch="B";
else if(av<60 && av>50)
ch="C";
else if(av<50)
ch="F";

}
}
class Main
{ //Scanner sc=new Scanner(System.in);
public static void main (String[] args)
{ Scanner sc=new Scanner(System.in);
int a;
String n,c,ch;
float av;

System.out.print("1.enter age");
a=sc.nextInt();
System.out.print("1.enter name");
n=sc.next();
System.out.print("1.enter city");
c=sc.next();
Student s1=new calculateGrade(a,n,c);
System.out.print("2.enter age");
a=sc.nextInt();
System.out.print("2.enter name");
n=sc.next();
System.out.print("2.enter city");
c=sc.next();
Student s2=new calculateGrade(a,n,c);

s1.printData(s1.name,s1.city,s1.age,s1.av,s1.ch);
s2.printData(s2.name,s2.city,s2.age,s2.av,s2.ch);
}
}
3. ARRAY:
import java.util.*;
class Student
{
int age;
String name,city;
String ch;
float av;
Student(int a,String n,String c)
{
this.age=a;
this.name=n;
this.city=c;
//System.out.println(this.city);
}
void printData(String name,String city,int age,float av,String ch)
{
System.out.println("NAME-"+name+" CITY-"+city+" AGE-"+age+"
AVERAGE MARK-"+av+" GRADE-"+ch);
}
}
class attendanceCal extends Student
{
float th,ab,pe;
int m;

attendanceCal(int a,String n,String c)

{ super(a,n,c);
Scanner sc=new Scanner(System.in);

System.out.print("enter total hours:");


th=sc.nextInt();
System.out.print("enter no of hours absent:");
ab=sc.nextInt();
float pre=th-ab;
pe=((pre/th)*100);
//System.out.println(pe);
if(pe>90)
m=5;
else if(pe>85 && pe<90)
m=4;
else if(pe>80 && pe<85)
m=3;
else if(pe>70 && pe<80)
m=2;
else if(pe>60 && pe<70)
m=1;
else
m=0;
//System.out.println(m);
}

}
class calculateGrade extends attendanceCal

calculateGrade(int a,String n,String c)

{ super(a,n,c);

//int m1,m2,m3,m4,m5;
int ma=m,z=0;
int p[];
p=new int[5];
Scanner sc=new Scanner(System.in);
System.out.print("enter 5 subject marks out of 95:");
for(int i=0;i<5;i++)
{
p[i]=sc.nextInt();
p[i]+=ma;
z=z+p[i];
}

av=(z)/5;
// System.out.print("sum:"+z);
if(av>90)
ch="O";
else if(av<90 && av>85)
ch="A+";
else if(av<85 && av>80)
ch="A";
else if(av<80 && av>70)
ch="B+";
else if(av>60 && av<70)
ch="B";
else if(av<60 && av>50)
ch="C";
else if(av<50)
ch="F";

}
}
class Main
{ //Scanner sc=new Scanner(System.in);
public static void main (String[] args)

{ calculateGrade [] s=new calculateGrade[3];


Scanner sc=new Scanner(System.in);
int a,i;
String n,c,ch;
float av;

for( i=0;i<3;i++)
{
//Scanner sc=new Scanner(System.in);
System.out.print("enter age:");
a=sc.nextInt();
System.out.print("enter name:");
n=sc.next();
System.out.print("enter city name:");
c=sc.next();
//inputData(a,n,c,i);
s[i]=new calculateGrade(a,n,c);
if(i!=2)
{
System.out.println("ENTER NEXT STUDENT DETAILS:");
}
}
for(i=0;i<3;i++)
{
s[i].printData(s[i].name,s[i].city,s[i].age,s[i].av,s[i].ch);
}
}
}

You might also like