0% found this document useful (0 votes)
4 views

SchoolManagement. Java

Uploaded by

Siddhi Landage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

SchoolManagement. Java

Uploaded by

Siddhi Landage
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

ArrayList;
import java.util.Scanner;

// Class for Student


class Student {
String name;
int id;

Student(String name, int id) {


this.name = name;
this.id = id;
}

void displayStudent() {
System.out.println("Student ID: " + id + ", Name: " + name);
}
}

// Class for Teacher


class Teacher {
String name;
int id;

Teacher(String name, int id) {


this.name = name;
this.id = id;
}

void displayTeacher() {
System.out.println("Teacher ID: " + id + ", Name: " + name);
}
}

// Main Class
public class SchoolManagement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Student> students = new ArrayList<>();
ArrayList<Teacher> teachers = new ArrayList<>();

while (true) {
System.out.println("\nSchool Management System");
System.out.println("1. Add Student");
System.out.println("2. Add Teacher");
System.out.println("3. View Students");
System.out.println("4. View Teachers");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter Student ID: ");
int studentId = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Student Name: ");
String studentName = scanner.nextLine();
students.add(new Student(studentName, studentId));
System.out.println("Student added successfully!");
break;

case 2:
System.out.print("Enter Teacher ID: ");
int teacherId = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Teacher Name: ");
String teacherName = scanner.nextLine();
teachers.add(new Teacher(teacherName, teacherId));
System.out.println("Teacher added successfully!");
break;

case 3:
System.out.println("\nList of Students:");
for (Student student : students) {
student.displayStudent();
}
break;

case 4:
System.out.println("\nList of Teachers:");
for (Teacher teacher : teachers) {
teacher.displayTeacher();
}
break;

case 5:
System.out.println("Exiting...");
scanner.close();
return;

default:
System.out.println("Invalid choice! Please try again.");
}
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy