https://www.Çℎḙḡḡ.com/homework-help...ay-complete-information-student-fac-q60208410
salamat po in advance
Code:
//here we have to use Inheritance to achieve this goal.
//Create all classes in single package and run CollegeList.java
CollegeList.java
import java.util.Scanner;
public class CollegeList {
public static void main(String[] args) {
Person person;
Scanner sc = new Scanner(System.in);
System.out.print("Select Among Employee, Faculty, or Student by pressing E,F,or S: ");
String option = sc.next();
switch (option) {
case "E":
person = new Employee();
System.out.println(person.toString());
break;
case "F":
person = new Faculty();
System.out.println(person.toString());
break;
case "S":
person = new Student();
System.out.println(person.toString());
break;
default:
System.out.println("Invalid choice...");
break;
}
}
}
--------------------------------------------------------------------------------------------------------------------------------------------
Employee.java
import java.util.Scanner;
public class Employee extends Person {
private double salary;
private String department;
public Employee() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Monthly Salary: ");
int salary = sc.nextInt();
sc.nextLine();
System.out.print("Enter Department: ");
String department = sc.next();
setDepartment(department);
setSalary(salary);
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return "Name: " + getName() + "\tContact Number:" + getContactNum() + "\tSalary:" + getSalary() + "\tDepartment:" + getDepartment();
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
Faculty.java
import java.util.Scanner;
public class Faculty extends Employee {
private boolean status;
public Faculty() {
Scanner sc = new Scanner(System.in);
System.out.print("Are you regular? Press Y/N: ");
String yes_no = sc.next();
if (yes_no.equals("Y")) {
status = true;
} else {
status = false;
}
}
public boolean isRegular() {
return status;
}
@Override
public String toString() {
return "Name: " + getName() + "\tContact Number:" + getContactNum() + "\tSalary:" + getSalary() + "\tDepartment:" + getDepartment() + "\tIsRegular:" + isRegular();
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
Student.java
import java.util.Scanner;
public class Student extends Person{
private String program;
private int yearLevel;
public Student()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter Enrolled Program name: ");
String program = sc.next();
sc.nextLine();
System.out.print("Enter Year Level: ");
int year_level = sc.nextInt();
setYearLevel(year_level);
setProgram(program);
}
public String getProgram() {
return program;
}
public void setProgram(String program) {
this.program = program;
}
public int getYearLevel() {
return yearLevel;
}
public void setYearLevel(int yearLevel) {
this.yearLevel = yearLevel;
}
@Override
public String toString() {
return "Name: " + getName() + "\tContact Number:" + getContactNum() + "\tProgram:" + getProgram()+ "\tYear Level:" + getYearLevel();
}
}
Sample run 1 for option E
You do not have permission to view the full content of this post. Log in or register now.
Sample run 1 for option F
You do not have permission to view the full content of this post. Log in or register now.
Sample run 1 for option S
You do not have permission to view the full content of this post. Log in or register now.
