Answer to Question #263295 in Java | JSP | JSF for joe

Question #263295

Write a menu driven application to maintain the department details of a School

using Java to demonstrate the concept of Inheritance. Your application must contain

the following functionalities along with the use of method overriding, and super

keyword. Consider the example of school of CST having three departments CSE,

AI&SD and CE.

a. For each department maintain the following details.

i. deptName

ii. hodName

iii. noOfFaculty

iv. noOfStudents

v. noOfPrograms

b. Get the department details from user(admin)

c. Display the Department list with all details in a proper and neat format.

d. In the menu give an option to display department wise details.


1
Expert's answer
2021-11-09T17:45:59-0500
import java.util.ArrayList;
import java.util.Scanner;


abstract class Student{
 private String deptName;
 private String hodName;
 private int noOfFaculty;
 private int noOfPrograms;
 private int  noOfStudents;




 public Student() {




 }




 public Student(String deptName, String hodName,int cgpa,
 int noOfPrograms, int  noOfStudents) {
 this.deptName = deptName;
 this.hodName = hodName;
 this.noOfFaculty = noOfFaculty;
 this.noOfPrograms = noOfPrograms;
 this. noOfStudents =  noOfStudents;
 }
 public String toString() {
 return "Name: " + this.deptName + "\n" + "Register number: " + this.hodName + "\n" + "\n" + "\n" + "No of faculty: " + this.noOfFaculty + "\n"
 + "Hostel deptName: " + this.noOfPrograms + "\n" + "Mentor deptName: " + this.deptName + "\n" + "Number of student: "
 + this. noOfStudents + "\n";
 }




 public String getName() {
 return deptName;
 }




 public void setName(String deptName) {
 this.deptName = deptName;
 }




 public String gethodName() {
 return hodName;
 }




 public void sethodName(String hodName) {
 this.hodName = hodName;
 }
 public int getnoOfFaculty() {
 return noOfFaculty;
 }




 public void setnoOfFaculty(int noOfFaculty) {
 this.noOfFaculty = noOfFaculty;
 }


 public String getnoOfPrograms() {
 return noOfPrograms;
 }




 public void setnoOfPrograms(int noOfPrograms) {
 this.noOfPrograms = noOfPrograms;
 }


 public int getNumberArrears() {
 return  noOfStudents;
 }


 public void setNumberArrears(int  noOfStudents) {
 this. noOfStudents =  noOfStudents;
 }
}


class PG extends Student {
 private int level;




 public PG(String deptName, String hodName, String department, int noOfFaculty, int noOfPrograms,
 String mentorName, int  noOfStudents, int level) {
 super(deptName, hodName, noOfFaculty, noOfPrograms, mentorName,  noOfStudents);
 this.level = level;
 }


 public String toString() {
 return super.toString() + "Level: " + this.level + "\n";
 }


 public int getLevel() {
 return level;
 }


 public void setLevel(int level) {
 this.level = level;
 }




}




class CST extends Student {
 private int fees;




 public CST(String deptName, String hodName, String department,, int noOfFaculty, int noOfPrograms,
 int  noOfStudents, int fees) {
 super(deptName, hodName, specialization, noOfFaculty, noOfPrograms,  noOfStudents);
 this.fees = fees;
 }
 public String toString() {
 return super.toString() + "Fees: " + this.fees + "\n";
 }
 public int getFees() {
 return fees;
 }


 public void setFees(int fees) {
 this.fees = fees;
 }
}




public class StudentsApp {




 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 ArrayList<Student> stu = new ArrayList<Student>();
 int ch = -1;
 while (ch != 5) {




 System.out.println("1. Add a new student");
 System.out.println("2. Display all stu");
 System.out.println("3. Display PG stu");
 System.out.println("4. Display CST stu");
 System.out.println("5. Exit");
 System.out.print("Your choice: ");
 ch = input.nextInt();
 switch (ch) {
 case 1: {
 System.out.println("1. Add PG student");
 System.out.println("2. Add CST student");
 System.out.print("Your choice: ");
 int selectedStudent = input.nextInt();
 String hodName = "";
 int noOfFaculty = 0;
 int noOfPrograms = "";
 String mentorName = "";
 int  noOfStudents = 0;
 input.nextLine();
 if (selectedStudent == 1 || selectedStudent == 2) {
 System.out.print("Enter student' deptName: ");
 deptName = input.nextLine();
 System.out.print("Enter student' register number: ");
 hodName = input.nextLine();
 System.out.print("Enter student' noOfFaculty: ");
 noOfFaculty = input.nextInt();
 input.nextLine();
 System.out.print("Enter student' hostel deptName: ");
 noOfPrograms = input.nextLine();
 System.out.print("Enter student' mentor deptName: ");
 mentorName = input.nextLine();
 System.out.print("Enter student' number of arrears: ");
  noOfStudents = input.nextInt();
 }




 if (selectedStudent == 1) {
 System.out.print("Enter student' level: ");
 int level = input.nextInt();
 stu.add(new PG(deptName, hodName, noOfFaculty, noOfPrograms, mentorName,
  noOfStudents, level));




 System.out.println("\nA new student added.\n");
 } else if (selectedStudent == 2) {
 System.out.print("Enter student' fees: ");
 int fees = input.nextInt();
 stu.add(new UG(deptName, hodName, noOfFaculty, noOfPrograms, mentorName,
  noOfStudents, fees));
 System.out.println("\nA new student added.\n");
 } else {
 System.out.println("Invalid choice.");
 }




 }
 break;
 case 2: {
 System.out.println("All stu:");
 for (int i = 0; i < stu.size(); i++) {
 System.out.println(stu.get(i).toString());
 }
 }
 break;
 case 3: {
 System.out.println("All PG stu:");
 for (int i = 0; i < stu.size(); i++) {
 if(stu.get(i) instanceof PG) {
 System.out.println(stu.get(i).toString());
 }
 }
 }
 break;
 case 4: {
 System.out.println("All CST stu:");
 for (int i = 0; i < stu.size(); i++) {
 if(stu.get(i) instanceof CST) {
 System.out.println(stu.get(i).toString());
 }
 }
 }
 break;
 case 5:
 break;
 }
 }
 input.close();
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS