KEMBAR78
Code | PDF | Computer Programming | Software Engineering
0% found this document useful (0 votes)
7 views7 pages

Code

The document defines an abstract class 'Staff' with properties for staff members and an abstract method for calculating salary. It includes two subclasses: 'Bartender', which calculates salary based on shifts worked, and 'Employee', which calculates salary based on a salary factor. Additionally, it presents a 'CoffeeHouseManagement' class for managing staff input, payroll display, and basic operations in a coffee house setting.

Uploaded by

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

Code

The document defines an abstract class 'Staff' with properties for staff members and an abstract method for calculating salary. It includes two subclasses: 'Bartender', which calculates salary based on shifts worked, and 'Employee', which calculates salary based on a salary factor. Additionally, it presents a 'CoffeeHouseManagement' class for managing staff input, payroll display, and basic operations in a coffee house setting.

Uploaded by

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

public abstract class Staff {

private String id;

private String name;

private String phone;

private String address;

// Constructor

public Staff(String id, String name, String phone, String address) {

this.id = id;

this.name = name;

this.phone = phone;

this.address = address;

// Getter và Setter

public String getId() {

return id;

public void setId(String id) {

this.id = id;

public String getName() {

return name;

public void setName(String name) {


this.name = name;

public String getPhone() {

return phone;

public void setPhone(String phone) {

this.phone = phone;

public String getAddress() {

return address;

public void setAddress(String address) {

this.address = address;

// Phương thức trừu tượng

public abstract double getSalary();

@Override

public String toString() {

return "ID: " + id + ", Name: " + name + ", Phone: " + phone + ", Address: " + address;

b)

public class Bartender extends Staff {


private int numOfShifts;

// Constructor

public Bartender(String id, String name, String phone, String address, int numOfShifts) {

super(id, name, phone, address);

this.numOfShifts = numOfShifts;

// Getter và Setter

public int getNumOfShifts() {

return numOfShifts;

public void setNumOfShifts(int numOfShifts) {

this.numOfShifts = numOfShifts;

// Tính lương

@Override

public double getSalary() {

return 450000 * numOfShifts; // Mỗi ca làm được trả 450,000

@Override

public String toString() {

return super.toString() + ", Number of Shifts: " + numOfShifts + ", Salary: " + getSalary();

}
c)

private double salaryFactor;

// Constructor

public Employee(String id, String name, String phone, String address, double
salaryFactor) {

super(id, name, phone, address);

this.salaryFactor = salaryFactor;

// Getter và Setter

public double getSalaryFactor() {

return salaryFactor;

public void setSalaryFactor(double salaryFactor) {

this.salaryFactor = salaryFactor;

// Tính lương

@Override

public double getSalary() {

return 2680000 * salaryFactor; // Lương cơ bản nhân với hệ số lương

@Override

public String toString() {

return super.toString() + ", Salary Factor: " + salaryFactor + ", Salary: " + getSalary();

}
D)

import java.util.ArrayList;

import java.util.Scanner;

public class CoffeeHouseManagement {

private static ArrayList<Staff> staffList = new ArrayList<>();

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

while (true) {

System.out.println("--------- MANAGEMENT ---------");

System.out.println("1. Input Employee / Bartender");

System.out.println("2. Show payroll list");

System.out.println("3. Save data");

System.out.println("4. Load data");

System.out.println("5. Exit");

System.out.print("Choose: ");

int choice = scanner.nextInt();

scanner.nextLine(); // Clear buffer

switch (choice) {

case 1:

inputStaff(scanner);

break;

case 2:

showPayroll();

break;
case 3:

System.out.println("Save data feature not implemented yet.");

break;

case 4:

System.out.println("Load data feature not implemented yet.");

break;

case 5:

System.out.println("Exiting...");

scanner.close();

return;

default:

System.out.println("Invalid choice. Try again.");

private static void inputStaff(Scanner scanner) {

System.out.println("1. Input Employee");

System.out.println("2. Input Bartender");

System.out.print("Choose: ");

int type = scanner.nextInt();

scanner.nextLine(); // Clear buffer

System.out.print("Enter ID: ");

String id = scanner.nextLine();

System.out.print("Enter Name: ");

String name = scanner.nextLine();

System.out.print("Enter Phone: ");

String phone = scanner.nextLine();


System.out.print("Enter Address: ");

String address = scanner.nextLine();

if (type == 1) { // Employee

System.out.print("Enter Salary Factor: ");

double salaryFactor = scanner.nextDouble();

Employee employee = new Employee (id, name, phone, address, salaryFactor);

staffList.add(employee);

} else if (type == 2) { // Bartender

System.out.print("Enter Number of Shifts: ");

int numOfShifts = scanner.nextInt();

Bartender bartender = new Bartender(id, name, phone, address, numOfShifts);

staffList.add(bartender);

} else {

System.out.println("Invalid type.");

private static void showPayroll() {

System.out.println("------- Payroll List -------");

double totalSalary = 0;

for (Staff staff : staffList) {

System.out.println(staff.toString());

totalSalary += staff.getSalary();

System.out.println("Total Salary to Pay: " + totalSalary);

You might also like