Search This Blog

Tuesday 31 August 2021

3. Write a java code to create a class with data members name, category, doj, and fees and static members total_fee, categorywise_no_students, methods to Insert data using parameterized constructor, display student information along with total fees and number of students in each category.

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

class Pro3
    {  
        String name1;
        String cat1;
        String doj1;
        float fees1;
        public static float total_fee=0.0F;
        public static int gm=0,sc=0,st=0,obc=0;
        //creating a parameterized constructor  
        Pro3(String name,String cat, String doj, float fees)
        {  
            name1 = name;
            cat1 = cat;
            doj1 = doj;
            fees1= fees;
        }  
        //method to display the values  
        void display()
        {
            System.out.println("STUDENT INFORMATION");
            System.out.println("NAME: "+name1);
            System.out.println("CATEGORY: "+cat1);
            System.out.println("DOJ: "+doj1);
            System.out.println("FEES: "+fees1);
            total_fee=total_fee+fees1;
            if(cat1.equals("gm") || cat1.equals("GM"))
                gm++;
            if(cat1.equals("sc") || cat1.equals("SC"))
                sc++;
            if(cat1.equals("st") || cat1.equals("ST"))
                st++;
            if(cat1.equals("obc") || cat1.equals("OBC"))
                obc++;
        }  
   
        public static void main(String args[])throws IOException
        {  
            //creating objects and passing values  
            DataInputStream in= new DataInputStream(System.in);
            System.out.println("Enter the name, category, doj and fees of student1");
            Pro3 s1 = new Pro3(in.readLine(),in.readLine(),in.readLine(),Float.parseFloat(in.readLine()));  
            System.out.println("Enter the name, category, doj and fees of student2");
            Pro3 s2 = new Pro3(in.readLine(),in.readLine(),in.readLine(),Float.parseFloat(in.readLine()));
            System.out.println("Enter the name, category, doj and fees of student3");
            Pro3 s3 = new Pro3(in.readLine(),in.readLine(),in.readLine(),Float.parseFloat(in.readLine()));
            //calling method to display the values of object  
            s1.display();  
            s2.display();
            s3.display();
            System.out.println("TotalFees="+total_fee);
            System.out.println("GM Category Students="+gm);
            System.out.println("SC Category Students="+sc);
            System.out.println("ST Category Students="+st);
            System.out.println("OBC Category Students="+obc);
        }  

No comments :

Post a Comment

FREE Hit Counters