Write a program to add the Student Record in Java



package inheritanceinjava;

import java.util.ArrayList;

import javax.swing.JOptionPane;

public class InheritanceInJava {      

       ArrayList<Student> students = new ArrayList<>();

        while(true){

            int option = mainMenu();

            switch(option)

            {

                case 1:

                    int i = Integer.parseInt(JOptionPane.showInputDialog("Enter the id :"));

                    String n = JOptionPane.showInputDialog("Enter the name : ");

                    

                    float c = Float.parseFloat(JOptionPane.showInputDialog("Enter the cgpa"));

                    int f = Integer.parseInt(JOptionPane.showInputDialog("Enter the fees"));

                    Student s = new Student(c, f, n, i);

                    students.add(s);

                    

                    JOptionPane.showMessageDialog(null, "Student added successfully");

                    break;

                case 2:

                    break;

                case 3:

                    JOptionPane.showMessageDialog(null, "Total students are : "+students.size());

                    break;

                case 4:

                    break;

                case 5:

                    break;

                case 6:               

                    String data = "";

                    for(Student s1:students)

                    {

                        data  = data + s1 + "\n";

                    }

                    

                    JOptionPane.showMessageDialog(null, data);                   

                    break;

                case 7:

                    System.exit(1);

                    break;

                default:

                    JOptionPane.showMessageDialog(null, "Invalid option");

            }

        }

    }

    

    public static int mainMenu()

    {

        String input = JOptionPane.showInputDialog("Press\n1. Add student\n2. Delete Student\n3. Show total Number of students\n4. Search student\n5. Update Student\n6. Show all students\n7. Exit\n");

        return Integer.parseInt(input);

    }

    

}


Comments

Popular posts from this blog