Search This Blog

Sunday 11 May 2014

Java program to display student result using class Person and class Student.

import java.lang.*;
import java.io.*;
import java.util.*;

class Person
{
    String pname,dob,city;
    int phno;
    void read()
    {
        try
        {
            DataInputStream in=new DataInputStream(System.in);
            System.out.println("Enter the name:");
            pname=in.readLine();
            System.out.println("Enter DOB:");
            dob=in.readLine();
            System.out.println("Enter city:");
            city=in.readLine();
            System.out.println("Enter phone no:");
            phno=Integer.parseInt(in.readLine());
        }//try block close.
        catch (Exception e)
        {
        }
   
    }//read() close.
}//Person class close.

class Student extends Person
{
    int m1,m2,m3,m4,m5,total;
    String regno,course,sem,grade;
    double per;
    void get()
    {
        read();
        try
        {
            DataInputStream in1=new DataInputStream(System.in);
            System.out.println("Enter regno:");
            regno=in1.readLine();
            System.out.println("Enter the course:");
            course=in1.readLine();
            System.out.println("Enter the semester:");
            sem=in1.readLine();
            System.out.println("Enter marks < 100 for 5 subjects");
            System.out.println("K/H/U/S:");
            m1=Integer.parseInt(in1.readLine());
            System.out.println("English:");
            m2=Integer.parseInt(in1.readLine());
            System.out.println("Java Programming:");
            m3=Integer.parseInt(in1.readLine());
            System.out.println("Operations Research:");
            m4=Integer.parseInt(in1.readLine());
            System.out.println("Computer Graphics:");
            m5=Integer.parseInt(in1.readLine());
           
        }//try block close
        catch (Exception e)
        {
        }
        calc();
    }//get() close.
    void calc()
    {
        total=m1+m2+m3+m4+m5;
        per = total / 5;
   
        if(m1<40 || m2<40 || m3<40 || m4<40 || m5<40)
            grade= "FAIL";
        else
        {
                if(per >=70)
                    grade = "DISTINCTION";
                else if(per >= 60 && per < 70)
                    grade = "FIRST CLASS";
                else if(per >= 50 && per < 60)
                    grade = "SECOND CLASS";
                else if(per >= 40 && per < 50)
                    grade = "PASS";
           
        }
    }//calc() close.

    void put()
    {
        System.out.println("\n\n");
        System.out.println("                         Kuvempu University                ");
        System.out.println("                             MARKS SHEET                  \n");
        System.out.println("Name of the Student : "+pname+"                  Register Number : "+regno);
        System.out.println("Course              : "+course+"                       Semester     : "+sem);
        System.out.println("---------------------------------------------------------------------------");
        System.out.println("  SUBJECTS            MAX.MARKS     MIN.MARKS      MARKS OBTAINED    ");
        System.out.println("---------------------------------------------------------------------------");
        System.out.println(" 1.K/H/U/S              100           40              "+m1);
        System.out.println(" 2.ENGLISH              100           40              "+m2);
        System.out.println(" 3.JAVA PROGRAMMING     100           40              "+m3);
        System.out.println(" 4.OPERATIONS RESEARCH  100           40              "+m4);                                                                 
        System.out.println(" 5.COMPUTER GRAPHICS    100           40              "+m5);
        System.out.println("---------------------------------------------------------------------------");
        System.out.println(" TOTAL MARKS      :     500           200            "+total);
        System.out.println(" PERCENTAGE MARKS :     "+per);
        System.out.println(" GRADE            :     "+grade);
        System.out.println("---------------------------------------------------------------------------");
    }//put() close.
}// Student class close.

class Result
{
    public static void main(String args[])
    {
        Student s = new Student();
        s.get();
        s.put();
    }
}

No comments :

Post a Comment

FREE Hit Counters