Q. Write a Java program to create a Package “SY” which has a class SYMarks (members – ComputerTotal, MathsTotal, and ElectronicsTotal). Create another package TY which has a class TYMarks (members – Theory, Practicals). Create n objects of Student class (having rollNumber, name, SYMarks and TYMarks).  Add the marks of SY and TY computer subjects and calculate the Grade (‘A’ for >= 70, ‘B’ for >= 60 ‘C’ for >= 50 , Pass Class for > =40 else ‘FAIL’) and display the result of the student in proper format. 



NOTE: THIS QUESTION HAS THREE PROGRAMS THAT ARE TO BE WRITTEN AND COMPILED DIFFERENTLY.

Program 1:

package Assignment2.SY;

import java.io.BufferedReader;
import java.io.*;

public class SYClass {
public int ct,mt,et;
public void get() throws IOException{
System.out.println("Enter marks of students for computer, maths and electronics subject out of 200 ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
ct=Integer.parseInt(br.readLine());
mt=Integer.parseInt(br.readLine());
et=Integer.parseInt(br.readLine());
}


}

Program 2:



package Assignment2.TY;

import java.io.*;
public class TYClass {
public int tm,pm;
public void get() throws IOException{
System.out.println("Enter the marks of the theory out of 400 and practicals out of 200: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
tm=Integer.parseInt(br.readLine());
pm=Integer.parseInt(br.readLine());
}

}

Program 3:

package Assignment2;
import Assignment2.SY.*;
import Assignment2.TY.*;
import java.io.*;
class StudentInfo{
int rollno;
String name,grade;
public float gt,tyt,syt;
public float per;
public void get() throws IOException{
System.out.println("Enter roll number and name of the student: ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
rollno=Integer.parseInt(br.readLine());
name=br.readLine();
}
}
public class StudentMarks {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of students:");
int n=Integer.parseInt(br.readLine());
SYClass sy[]=new SYClass[n];
TYClass ty[]=new TYClass[n];
StudentInfo si[]=new StudentInfo[n];
for(int i=0;i<n;i++)
{
si[i]=new StudentInfo();
sy[i]=new SYClass();
ty[i]=new TYClass();
si[i].get();
sy[i].get();
ty[i].get();
si[i].syt=sy[i].ct+sy[i].et+sy[i].mt;
si[i].tyt=ty[i].pm+ty[i].tm;
si[i].gt=si[i].syt+si[i].tyt;
si[i].per=(si[i].gt/1200)*100;
if(si[i].per>=70) si[i].grade="A";
else if(si[i].per>=60) si[i].grade="B";
else if(si[i].per>=50) si[i].grade="C";
else if(si[i].per>=40) si[i].grade="Pass";
else si[i].grade="Fail";
}
System.out.println("Roll No\tName\tSyTotal\tTyTotal\tGrandTotal\tPercentage\tGrade");
for(int i=0;i<n;i++)
{
System.out.println(si[i].rollno+"\t"+si[i].name+"\t"+si[i].syt+"\t"+si[i].tyt+"\t"+si[i].gt+"\t\t"+si[i].per+"\t\t"+si[i].grade);
}
}

}


Output:

Enter the number of students:
3
Enter roll number and name of the student:
2
amit
Enter marks of students for computer, maths and electronics subject out of 200
168
178
156
Enter the marks of the theory out of 400 and practicals out of 200:
389
178
Enter roll number and name of the student:
3
ramesh
Enter marks of students for computer, maths and electronics subject out of 200
159
146
187
Enter the marks of the theory out of 400 and practicals out of 200:
364
144
Enter roll number and name of the student:
4
suresh
Enter marks of students for computer, maths and electronics subject out of 200
126
80
154
Enter the marks of the theory out of 400 and practicals out of 200:
205
100
Roll No Name SyTotal TyTotal GrandTotal Percentage Grade
2       amit         502.0 567.0 1069.0 89.08333 A
3         ramesh 492.0 508.0 1000.0 83.33333 A
4         suresh 360.0 305.0 665.0 55.416668 C