Java Program to create package SY and TY containing classes SYMarks and TYMarks - IProgramX

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


Post a Comment

4 Comments

  1. Wrong program hai errors aa rahe hai

    ReplyDelete
  2. what are the commands for run this program

    ReplyDelete
  3. Slip10_2: Write a program to create a package name student. Define class StudentInfo
    with method to display information about student such as rollno, class, and percentage.
    Create another class StudentPer with method to find percentage of the student. Accept
    student details like rollno, name, class and marks of 6 subject from user.
    PackageFIle
    package student;
    class StudentInfo
    {
    public int r_no;
    public String name, clas;
    public int a,b,c,d,e,f;
    int sum=0;
    double per;
    public void display()
    {
    System.out.println("Roll_no : "+r_no);
    System.out.println("Name : "+name);
    System.out.println("class :"+clas);
    System.out.println("-----MARKS-------");
    System.out.println("Sub 1 : "+a);
    System.out.println("Sub 2 : "+b);
    System.out.println("Sub 3 : "+c);
    System.out.println("Sub 4 : "+d);
    System.out.println("Sub 5 : "+e);
    System.out.println("Sub 6 : "+f);
    System.out.println("Total : "+sum);
    System.out.println("percentage: "+per);
    System.out.println("------------------");

    }
    }
    public class StudentPer extends StudentInfo {
    public StudentPer(int roll, String nm, String cla,int m1,int m2,int m3,int m4, int
    m5,int m6)
    {
    r_no = roll;
    clas = cla;
    name = nm;
    a = m1;
    b = m2;
    c = m3;
    d = m4;
    e = m5;
    f = m6;
    sum = a+b+c+d+e+f;
    per = sum/6;
    }
    }
    Main File
    import student.StudentPer;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    class StudentMain
    {
    public static void main(String[] args)
    {
    String nm, clas;
    int roll;
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Roll no:= ");
    roll = sc.nextInt();
    System.out.print("Enter Name:= ");
    nm = sc.next();
    System.out.print("Enter class:= ");
    clas= sc.next();
    int m1,m2,m3,m4,m5,m6;
    System.out.print("Enter 6 sub mark:= ");
    m1 = sc.nextInt();
    m2 = sc.nextInt();
    m3 = sc.nextInt();
    m4 = sc.nextInt();
    m5 = sc.nextInt();
    m6 = sc.nextInt();
    StudentPer s = new StudentPer(roll,nm,clas,m1,m2,m3,m4,m5,m6);
    s.display();
    }
    }

    ReplyDelete
  4. Great and I have a tremendous offer: How Often Renovate House house remodeling near me

    ReplyDelete