Create a class with following specifications
Class name-Student_grade
Data members-
name[]– array of character
sex[]– array of character
age- int variable
p_marks- int variable
c_marks- int variable
m_marks- int variable
s_marks- int variable
Methods-
void inputdata()- takes name, age, sex, p_marks, m_marks and c_marks
void displaydata()- display name, age, sex, p_marks, m_marks and c_marks
void inputs_marks()- takes the s_marks
void displays_marks()- displays the s_marks
void calculate_grade()- calculates the grade and shows all details
The academic person can access inputdata(),displaydata() and calculate_grade().
The sports person can access calculate_grade(),inputs_marks(),displays_marks().
Source Code:
import java.io.*;
interface academic
{
void inputdata()throws IOException;
void displaydata();
void inputmarks()throws IOException;
void displaymarks();
void calculategrade();
}
interface sports
{
void inputsmarks()throws IOException;
void displaysmarks();
void calculategrade();
}
class student_grade implements academic,sports
{
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
String name,sex;
int age,pmarks,cmarks,mmarks,smarks=0;
public void inputdata()throws IOException
{
System.out.print("\nEnter name of the student:");
name=br1.readLine();
System.out.print("\nEnter sex of the student:");
sex=br1.readLine();
System.out.print("\nEnter age of the student:");
age=Integer.parseInt(br1.readLine());
}
public void inputmarks()throws IOException
{
System.out.print("\nEnter Physics marks of the student:");
pmarks=Integer.parseInt(br1.readLine());
System.out.print("\nEnter Chemistry marks of the student:");
cmarks=Integer.parseInt(br1.readLine());
System.out.print("\nEnter Mathematics marks of the student:");
mmarks=Integer.parseInt(br1.readLine());
}
public void inputsmarks()throws IOException
{
System.out.print("\nEnter Sports marks of the student:");
smarks=Integer.parseInt(br1.readLine());
}
public void displaydata()
{
System.out.print("\nName of the student : "+name);
System.out.print("\nSex of the student : "+sex);
System.out.print("\nAge of the student : "+age);
}
public void displaymarks()
{
System.out.print("\nPhysics marks of the student : "+pmarks);
System.out.print("\nChemistry marks of the student : "+cmarks);
System.out.print("\nMathematics marks of the student : "+mmarks);
}
public void displaysmarks()
{
System.out.print("\nSports marks of the student : "+smarks);
}
public void calculategrade()
{
double gr=(cmarks+pmarks+mmarks+smarks)/4;
if(gr>=100)
System.out.println("\nGrade of the student : A+");
else if(gr>=80 && gr <90)
System.out.println("\nGrade of the student : A");
else if(gr>=70 && gr <80)
System.out.println("\nGrade of the student : B+");
else if(gr>=60 && gr <70)
System.out.println("\nGrade of the student : B");
else if(gr>=50 && gr <60)
System.out.println("\nGrade of the student : c");
else
System.out.println("\nGrade of the student : D");
}
}
************MAIN FUNCTION*************
class main
{
public static void main(String ars[])throws IOException
{
BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
int i=0,j=0,k;
student_grade ob=new student_grade();
sports ob2=ob;
academic ob1=ob;
while(true)
{
System.out.println("\nAre you a Academic person or Sports Person");
System.out.println("\n1. Academic Person 2. Sports Person 3.Exit");
System.out.print("\nEnter your choice:");
int ch=Integer.parseInt(br2.readLine());
if(ch==1)
{
j=1;
k=0;
while(true)
{
System.out.println("\n1. Input data\n2. Input marks\n3. Display data
\n4. Display marks\n5.Calculate grade\n6.Exit from academic person");
System.out.print("\nEnter your choice:");
int ch2=Integer.parseInt(br2.readLine());
switch(ch2)
{
case 1:
ob1.inputdata();
break;
case 2:
ob1.inputmarks();
break;
case 3:
ob1.displaydata();
break;
case 4:
ob1.displaymarks();
break;
case 5:
if(i==0)
System.out.println("\nPlease tell the sports teacher to enter sport marks");
else
ob1.calculategrade();
break;
case 6:
k=1;
break;
default: System.out.println("\nWrong choice");
break;
}
if(k==1)
break;
}
}
else if(ch==2)
{
i=1;
k=0;
while(true)
{
System.out.println("\n1. Input sports marks\n2. Display sports marks
\n3. Calculate grade\n4. Exit from sports person");
System.out.println("\nEnter your choice:");
int ch2=Integer.parseInt(br2.readLine());
switch(ch2)
{
case 1:
ob2.inputsmarks();
break;
case 2:
ob2.displaysmarks();
break;
case 3:
if(j==0)
System.out.println("\nPlease tell the academic person to enter other marks");
else
ob2.calculategrade();
break;
case 4:
k=1;
break;
default: System.out.println("\nWrong choice");
break;
}
if(k==1)
break;
}
}
if(ch==3)
System.exit(0);
}
}
}
OUTPUT:
D:\java>javac assignment10.java
D:\java>java main
Are you a Academic person or Sports Person
1. Academic Person 2. Sports Person 3.Exit
Enter your choice:1
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:1
Enter name of the student:Gautam Pal
Enter sex of the student:Male
Enter age of the student:20
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:2
Enter Physics marks of the student:92
Enter Chemistry marks of the student:77
Enter Mathematics marks of the student:86
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:3
Name of the student : Gautam Pal
Sex of the student : Male
Age of the student : 20
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:4
Physics marks of the student : 92
Chemistry marks of the student : 77
Mathematics marks of the student : 86
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:5
Please tell the sports teacher to enter sport marks
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:6
Are you a Academic person or Sports Person
1. Academic Person 2. Sports Person 3.Exit
Enter your choice:2
1. Input sports marks
2. Display sports marks
3. Calculate grade
4. Exit from sports person
Enter your choice:
1
Enter Sports marks of the student:88
1. Input sports marks
2. Display sports marks
3. Calculate grade
4. Exit from sports person
Enter your choice:
2
Sports marks of the student : 88
1. Input sports marks
2. Display sports marks
3. Calculate grade
4. Exit from sports person
Enter your choice:
4
Are you a Academic person or Sports Person
1. Academic Person 2. Sports Person 3.Exit
Enter your choice:1
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:5
Grade of the student : A
1. Input data
2. Input marks
3. Display data
4. Display marks
5. Calculate grade
6.Exit from academic person
Enter your choice:6
Are you a Academic person or Sports Person
1. Academic Person 2. Sports Person 3.Exit
Enter your choice:3
0 comments