SchoolFunction.java

 avatar
unknown
java
6 months ago
2.8 kB
1
Indexable
package com.school.SchoolDatabase;

import com.school.Student.Student;
import com.school.ExceptionHandling.WrongDivisionException;

import java.util.List;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.Scanner;

public class SchoolFunction{
	
	private static List<List<TreeMap<Integer,Student>>> listOfDivision;
	
	public SchoolFunction(){
		listOfDivision = new ArrayList<>();
		for(int i = 0 ; i<12 ; ++i) listOfDivision.add(i,new ArrayList<>());	
	}

	public static void addStudent(Scanner sc) throws WrongDivisionException{
		sc.nextLine();
		
		System.out.println("Enter name of student");
		String name = sc.nextLine();
		
		System.out.println("Enter the division he is admitted to");
		int division = sc.nextInt();
		if(division<1 || division>12) throw new WrongDivisionException("Wrong division , please enter correct division");
		
		System.out.println(listOfDivision);
		//listOfDivision.forEach(System.out::println);
		
		System.out.println("Enter the section he is admitted to");
		char section = Character.toUpperCase(sc.next().charAt(0));	
		
		int alphabetValue = section-65;
		for(int i = 0 ; i<=alphabetValue ; ++i){
			if(listOfDivision.get(division).get(i)==null){
					listOfDivision.get(division) = new ArrayList<>();
					listOfDivision.get(division).add(i,new TreeMap<>());
			}
		}

		System.out.println(listOfDivision);

		System.out.println("Enter Student Roll Number");
		int rollNumber = sc.nextInt();
		
		TreeMap<Integer,Student> studentInformation = new TreeMap<>();
		studentInformation.put(rollNumber, new Student(name,division,section));
	}
	public static void showMenu(){
		System.out.println("Welcome Admin, to XYZ School Management System");
		System.out.println("Please enter the choice you want to make");
		System.out.println("1. Add Student to the Database");
		System.out.println("2. Print list of all students");
		System.out.println("3. Print list of student by a standard");
		System.out.println("4. Print list of student by a section");
		System.out.println("5. Find information of a particular student");
	}
	public static void chooseOption(int enterOption , Scanner sc) throws WrongDivisionException{
			switch(enterOption){
				case 1:{
					addStudent(sc);
					break;
				}
				case 2:{
					System.out.println("Coming Soon");
					//printAllStudent();
					break;
				}
				case 3:{
					System.out.println("Coming Soon");
					//printStudentByStandard();
					break;
				}
				case 4:{
					System.out.println("Coming Soon");
					//printStudentBySection();
					break;
				}
				case 5:{
					System.out.println("Coming Soon");
					//findStudent();
					break;
				}
				default:
					break;
			}
	}
}
Editor is loading...
Leave a Comment