What's new

Java People In School

chaekayeon

Journeyman
Joined
Oct 6, 2021
Posts
16
Reaction
1
Points
25
1637046901595.png

1637046922747.png

1637046951527.png


Meron po bang alam for this problem po?
 

Attachments

Java:
import java.util.*;
class Person {

    private String name;
    private String contactNum;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getContactNum() {
        return contactNum;
    }
    public void setContactNum(String contactNum) {
        this.contactNum = contactNum;
    }
}

class Student extends Person {

    private String program;
    private int yearLevel;

    public void setProgram(String program) {
        this.program = program;
    }
    public void setYearLevel(int yearLevel) {
        this.yearLevel = yearLevel;
    }
    public String getProgram() {
        return program;
    }
    public int getYearLevel() {
        return yearLevel;
    }

    void callStudent(String name, String contactNum, String program, int yearLevel) {
        setName(name);
        setContactNum(contactNum);
        setProgram(program);
        setYearLevel(yearLevel);
        System.out.println("----------------------------");
        System.out.println("Name          : " + getName());
        System.out.println("Contact Number: " + getContactNum());
        System.out.println("Program       : " + getProgram());
        System.out.println("Year Level    : " + getYearLevel());
    }
}

class Faculty extends Employee {

    private boolean status;
    boolean isRegular;
   
    boolean status() {
        if (isRegular == true) {
            return status = true;
        }if (isRegular == false) {
            return status = false;
        }
        return status;
    }

    void CallFaculty(String name, String contactNum, String department, double salary) {

        setName(name);
        setContactNum(contactNum);
        setDepartment(department);
        setSalary(salary);
        System.out.println("----------------------------");
        System.out.println("Name          : " + getName());
        System.out.println("Contact Number: " + getContactNum());
        System.out.println("Departemnt    : " + getDepartment());
        System.out.println("Salary        : " + getSalary());
        if (status() == true) {
            System.out.println("Status        : Regular/Tenured");
        } else if (status() == false) {
            System.out.println("Status        : Not Regular/Tenured");
        }
    }
}
class Employee extends Person {

    Scanner s = new Scanner(System.in);
    private double salary;
    private String department;

    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;
    }

    void callEmployee(String name, String contactNum, String department, double salary) {
        setName(name);
        setContactNum(contactNum);
        setDepartment(department);
        setSalary(salary);
        System.out.println("----------------------------");
        System.out.println("Name          : " + getName());
        System.out.println("Contact Number: " + getContactNum());
        System.out.println("Departemnt    : " + getDepartment());
        System.out.println("Salary        : " + getSalary());
    }
}
public class CollegeList {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        Person p = new Person();
        Student st = new Student();
        Employee emp = new Employee();
        Faculty fac = new Faculty();
        System.out.print("Press E for Employee, F for Faculty, or S for Student: ");
        String user = s.nextLine();

        if (user.equalsIgnoreCase("E")) {
            System.out.println("Type Employee's name, contact number, department and salary."
                    + "\n" + "Press Enter every input");
            emp.callEmployee(s.nextLine(), s.nextLine(), s.nextLine(), s.nextDouble());
        } else if (user.equalsIgnoreCase("S")) {
            System.out.println("Type Student's name, contact number , program and year level."
                    + "\n" + "Press Enter every input");
            st.callStudent(s.nextLine(), s.nextLine(), s.nextLine(), s.nextInt());
        } else if (user.equalsIgnoreCase("F")) {
            String stat;
            System.out.println("Press Y if Regular/Tenured and N if not");
            stat = s.nextLine();
            if (stat.equalsIgnoreCase("Y")) {
                fac.isRegular = true;

            } else if (stat.equalsIgnoreCase("N")) {
                fac.isRegular = false;
            }
            System.out.println("Type Employee's name, contact number, department and salary."
                    + "\n" + "Press Enter every input");
           
            fac.CallFaculty(s.nextLine(), s.nextLine(), s.nextLine(), s.nextDouble());
        }else {
            System.out.println("Invalid Input!");
        }

    }
}

It doesn't worked on me, mali pa rin kasi eh.

1637226730116.png
 

Attachments

suggestion lang, di naman mali pero mas okay kung i override mo ung tostring ng mga classes instead of call<Employee|Faculty> na methods ng class. okay din pa activity ng STI ah, pero mukang di naituro ng maayos ano TS?
 
suggestion lang, di naman mali pero mas okay kung i override mo ung tostring ng mga classes instead of call<Employee|Faculty> na methods ng class. okay din pa activity ng STI ah, pero mukang di naituro ng maayos ano TS?
Mostly lods ganyan din samin pero depende na kasi sa teacher yan. Yung teacher namin dati parang wala lang more on discussion lang siya pero sa coding dun siya GG HAHAHAHA

It doesn't worked on me, mali pa rin kasi eh.

View attachment 1718562

Trial and error lang yan TS. At least may idea ka na pano gawin. Ang gagawin mo na lang ay i-arrange yung code check mo isa isa.
 
Last edited:

Similar threads

Back
Top