1. Write a simple information system that will store and display the complete information of a student, faculty, or employee.
2. Create four no-modifier classes named Person, Student, Faculty, and Employee.
3. Create a public class named CollegeList. This class shall contain the main method.
4. Refer to the UML Class Diagram for the names of the variables and methods. The (-) symbol represents private variables, while (+) represents public method. This should be the sequence of the program upon execution:
a. Prompt the user to select among Employee, Faculty, or Student, by pressing E, F, or S.
b. Ask the user to type the name and contact number.
c. For Employee, ask the user to type the employee's monthly salary and the department where he/she belongs to. Then, display name, contact number, salary, and department.
For Faculty, ask the user to press Y if the faculty member is regular/tenured or N if not. Then, display name, contact number, salary, department, and status.
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
package com.company;
import java.util.*;
class Employee{
String name;
String contact_number;
int salary;
String department;
Employee(String name, String contact_number,int salary, String department)
{
this.name = name;
this.contact_number = contact_number;
this.salary = salary;
this.department = department
}
public void E_display()
{
System.out.println("Name: "+name);
System.out.println("Contact number: "+contact_number);
System.out.println("Salary: "+salary);
System.out.println("Department: "+department);
}
}
class Student{
public static String name;
public static String contact_number;
Student(String name, String contact_number)
{
this.name = name;
this.contact_number = contact_number;
}
public void S_display()
{
System.out.println("Name: "+name);
System.out.println("Contact number: "+contact_number);
}
}
class Faculty{
public static String status;
Faculty(String status)
{
this.status = status;
}
public void F_dispaly()
{
if(status=="Y")
{
System.out.println("faculty member is regular/tenured ");
}
else
{
System.out.println("faculty member is not regular/tenured ");
}
}
}
public class CollegeLis {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("\nE.Employee");
System.out.println("\nS.Student");
System.out.println("\nF.Faculty");
System.out.print("Enter your option: ");
String option = sc.next();
if(option=="E")
{
System.out.println("Enter the name:");
String name = sc.next();
System.out.println("Enter the contact number:");
String contact_number = sc.next();
System.out.println("Enter salary: ");
int salary = sc.nextInt();
System.out.println("Enter the department: ");
String department = sc.next();
Employee my_e = new Employee(name,contact_number,salary,department);
my_e.E_display();
}
else if (option=="S")
{
System.out.println("Enter the name:");
String name = sc.next();
System.out.println("Enter the contact number:");
String contact_number = sc.next();
Student my_s = new Student(name,contact_number);
my_s.S_display();
}
else if(option=="F")
{
System.out.println("Press Y if the faculty member is regular/tenured or N if not");
String status = sc.next();
Faculty my_f = new Faculty(status);
my_f.F_dispaly();
}
}
}
Comments
Leave a comment