JAVA PACKAGE

AIM:
            To get and display the details of marks and staff using package.
PROCEDURE:
1)Start the program.
2)Create package.
3)Define the details of the classes.
4)Declare the required variables.
5)Define a member function to read the input from the user.
6)Define a member function to display the output.
7)Save the program in their respective directories.
8)Import the package into the main program.
9)Define the main class and create the objects of the classes defined packages.
10)Call the member functions of the classes to get and display the details.
11)Stop the program.









SOURCE CODE:
/*SMS PACKAGE*/
/*PERSONAL CLASS*/
package sms;
import java.io.*;
public class personal
{
            String name,regno,branch,address,gender;
             public void getdata() throws IOException
             {
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("Enter the name:");
                        name=br.readLine();
                        System.out.println("Enter branch:");
                        branch=br.readLine();
                        System.out.println("Enter gender M/F:");
                        gender=br.readLine();
                        System.out.println("Enter the address:");
                        address=br.readLine();
            }
            public void display()throws IOException
            {
                        System.out.println("Name:"+name);
                        System.out.println("Branch:"+branch);
                        System.out.println("Gender:"+gender);
                        System.out.println("Address:"+address);
            }
}

/*MARKS CLAS*/
package sms;
import java.io.*;
public class marks extends personal
{
            int total,m1,m2,m3,m4,m5;
            float avg;
            public void getdata() throws IOException
            {
                        super.getdata();
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("Enter The Mark1:");
                        m1=Integer.parseInt(br.readLine());
                        System.out.println("Enter The Mark2:");
                        m2=Integer.parseInt(br.readLine());
                        System.out.println("Enter The Mark3:");
                        m3=Integer.parseInt(br.readLine());
                        System.out.println("Enter The Mark4:");
                        m4=Integer.parseInt(br.readLine());
                        System.out.println("Enter The Mark5:");
                        m5=Integer.parseInt(br.readLine());
                        total=m1+m2+m3+m4+m5;               
                        avg=(float)total/5;
            }
            public void display()throws IOException
            {
                        System.out.println("\n**********************");
                        System.out.println("     PERSONAL DETAILS   ");
                        System.out.println("**********************");
                        super.display();
                        System.out.println("\n**********************");
                        System.out.println("     ACADEMIC DETAILS   ");
                        System.out.println("**********************");
                        System.out.println("Mark1:"+m1);
                        System.out.println("Mark2:"+m2);
                        System.out.println("Mark3:"+m3);
                        System.out.println("Mark4:"+m4);
                        System.out.println("Mark5:"+m5);                
                        System.out.println("Total:"+total);
                        System.out.println("Average:"+avg);
            }
}

/*STAFF CLASS*/

package sms;
import java.io.*;
public class staff extends personal
{
            String staff_id;
            int bp,pf,lic,da,medical,hra,grosspay,netpay;
            public void getdata()throws IOException
            {
                        super.getdata();
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("Enter the staff id:");
                        staff_id=br.readLine();
                        System.out.println("Enter the basicpay:");
                        bp=Integer.parseInt(br.readLine());
                        System.out.println("Enter the pf:");
                        pf=Integer.parseInt(br.readLine());
                        System.out.println("Enter the medical allowance:");
                        medical=Integer.parseInt(br.readLine());
                        System.out.println("Enter the LIC:");
                        lic=Integer.parseInt(br.readLine());
                        System.out.println("Enter the da:");
                        da=Integer.parseInt(br.readLine());
                        System.out.println("Enter the hra:");
                        hra=Integer.parseInt(br.readLine());
                        grosspay=bp+pf+lic+da+medical+hra;
            }
            public void display()throws IOException
            {
            System.out.println("\n**********************");
            System.out.println("      PERSONAL DETAILS    ");
            System.out.println("**********************");
            super.display();
            System.out.println("\n**********************");
            System.out.println("    STAFF DETAILS     ");
            System.out.println("**********************");
            System.out.println("Staff id:"+staff_id);
            System.out.println("Basic pay:"+bp);
            System.out.println("LIC:"+lic);
            System.out.println("Daily allowance:"+da);
            System.out.println("Medical allowance:"+medical);
            System.out.println("HRA:"+hra);
            System.out.println("Grosspay:"+grosspay);
            System.out.println("Netpay:"+(grosspay-pf-lic-medical));
            }
}

/*MAIN CLASS*/:

import sms.*;
import java.io.*;
class exno4
{
            public static void main(String args[])throws IOException
            {
                        int ch;
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("1.Academic details\n2.Staff details\n");
                        System.out.println("Enter the choice:");
                        ch=Integer.parseInt(br.readLine());
                        switch(ch)
                        {
                         case 1:
                                    marks m=new marks();
                                    m.getdata();
                                    m.display();
                                    break;
                         case 2:
                                    staff s=new staff();
                                    s.getdata();
                                    s.display();
                                    break;
                        default:
                                    System.out.println("Enter correct choice!");
                        }
            }
}











OUTPUT:
1.Acadamic details
2.Staff details

Enter the choice:1
Enter the name:4cNOTES
Enter branch:mca
Enter gender M/F:m
Enter the address:trichy
Enter The Mark1:90
Enter The Mark2:99
Enter The Mark3:98
Enter The Mark4:89
Enter The Mark5:88

**********************
   PERSONAL DETAILS
**********************
Name:4cNOTES
Branch:mca
Gender:m
Address:trichy






**********************
     ACADEMIC DETAILS
**********************
Mark1:90
Mark2:99
Mark3:98
Mark4:89
Mark5:88
Total:464
Average:92.8


Enter the choice:2
Enter the name: nandhakumar
Enter branch: mca
Enter gender M/F: m
Enter the address: trichy
Enter the staff id: s101
Enter the basicpay: 30000
Enter the pf: 2000
Enter the medical allowance: 1000
Enter the LIC: 3000
Enter the da: 400
Enter the hra: 4000



**********************
      PERSONAL DETAILS
**********************
Name:nandhakumar
Branch:mca
Gender:m
Address:trichy

**********************
    STAFF DETAILS
**********************
Staff id:s101
Basic pay:30000
LIC:3000
Daily allowance:400
Medical allowance:1000
HRA:4000
Grosspay:40400
Netpay:34400

0 comments: