Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class PayrollSystem {
- static ArrayList<String> names = new ArrayList<String> ();
- static ArrayList<String> addresses = new ArrayList<String> ();
- static ArrayList<Integer> dailyRates = new ArrayList<Integer> ();
- static ArrayList<Integer> noOfHoursWorkPerMonth = new ArrayList<Integer> ();
- static ArrayList<Integer> noOfHoursAbsent = new ArrayList<Integer> ();
- static ArrayList<Integer> totalWorkHours = new ArrayList<Integer> ();
- static ArrayList<Double> salesPerMonth = new ArrayList<Double> ();
- static ArrayList<String> Commision = new ArrayList<String> ();
- static ArrayList<Double> totalDeduction = new ArrayList<Double> ();
- static ArrayList<Double> finalSalary = new ArrayList<Double> ();
- static ArrayList<Double> baseSalary = new ArrayList<Double> ();
- static ArrayList<Double> totalSalary = new ArrayList<Double> ();
- static Scanner input = new Scanner(System.in);
- public static void main(String[]args){
- int mainMenu= -1;
- while (mainMenu != 0) {
- menu();
- mainMenu = input.nextInt();
- input.nextLine();
- switch (mainMenu) {
- case 0:
- exit();
- break;
- case 1:
- add();
- break;
- case 2:
- update();
- break;
- case 3:
- display();
- break;
- case 4:
- search();
- default:
- System.out.println("Out of range");
- main(args);
- break;
- }
- }
- }
- static void menu(){
- System.out.println("Payroll System");
- System.out.println("[1] Add new account");
- System.out.println("[2] Update existing account");
- System.out.println("[3] Display all accounts");
- System.out.println("[4] Search for account");
- System.out.println("[0] Exit");
- System.out.print(">>> ");
- }
- static void add(){
- String name,address;
- int rate;
- int DailyRatePerHour;
- int NumberOfHoursWorkPerMonth, NumberOfHoursAbsent;
- int TotalWorkHours;
- double BaseSalary;
- System.out.println("Add new user!");
- System.out.print("Name : ");
- name = input.nextLine();
- names.add(name);
- System.out.print("Address: ");
- address = input.nextLine();
- addresses.add(address);
- System.out.print("Daily Rate: ");
- DailyRatePerHour = input.nextInt();
- dailyRates.add(DailyRatePerHour);
- System.out.println("Enter Number of Work Hours Per Month: ");
- NumberOfHoursWorkPerMonth=input.nextInt();
- noOfHoursWorkPerMonth.add(NumberOfHoursWorkPerMonth);
- System.out.println("Enter Number of Hours Absent:");
- NumberOfHoursAbsent=input.nextInt();
- noOfHoursAbsent.add(NumberOfHoursAbsent);
- TotalWorkHours=NumberOfHoursWorkPerMonth-NumberOfHoursAbsent;
- System.out.println("Total Work Hours:"+TotalWorkHours);
- totalWorkHours.add(TotalWorkHours);
- double sales=0;
- System.out.println("Enter Sales Per Month:");
- sales=input.nextDouble();
- if(sales>=10000){
- Commision.add("You have 3% Monthly Commision");
- }else if(sales>=20000){
- Commision.add("You have 4% Monthly Commision");
- }else if(sales>=30000){
- Commision.add("You have 5% Monthly Commision");
- }else if(sales>=40000){
- Commision.add("You have 10% Monthly Commision");
- }if (sales<10000){
- Commision.add("You have no Monthly Commision");
- }
- salesPerMonth.add(sales);
- System.out.println("[1] Married With Children");
- System.out.println("[2] Married Without Children");
- System.out.println("[3] Single Parent");
- System.out.println("[4] Single");
- System.out.print(">>> ");
- rate = input.nextInt();
- BaseSalary=TotalWorkHours*DailyRatePerHour;
- baseSalary.add(BaseSalary);
- int SSS=550;
- int PagIbig=500;
- double FinalSalary;
- double totalDeductions;
- if (rate ==1){
- double TotalSalary = BaseSalary*.05;
- totalSalary.add(TotalSalary);
- totalDeductions = SSS+PagIbig;
- totalDeduction.add(TotalSalary);
- FinalSalary=TotalSalary-totalDeductions;
- finalSalary.add(FinalSalary);
- }else if(rate ==2){
- double TotalSalary = BaseSalary*0.01;
- totalSalary.add(TotalSalary);
- totalDeductions = SSS+PagIbig;
- totalDeduction.add(TotalSalary);
- FinalSalary=TotalSalary-totalDeductions;
- finalSalary.add(FinalSalary);
- }else if(rate ==3){
- double TotalSalary = BaseSalary* 0.05;
- totalDeductions = SSS+PagIbig;
- totalDeduction.add(TotalSalary);
- FinalSalary=TotalSalary-totalDeductions;
- finalSalary.add(FinalSalary);
- } if(rate ==4){
- double TotalSalary = BaseSalary* 0.15;
- totalDeductions = SSS+PagIbig;
- totalDeduction.add(TotalSalary);
- FinalSalary= TotalSalary-totalDeductions;
- finalSalary.add(FinalSalary);
- }
- }
- static void update(){
- String name, newName, newAddress;
- System.out.println("Update account!");
- System.out.print("Name: ");
- name = input.nextLine();
- int position = 0;
- boolean matched = false;
- for (String profile : names) {
- if (profile.contains(name)) {
- matched = true;
- position = names.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- if (matched == true) {
- int modify;
- System.out.println("[1] Update name");
- System.out.println("[2] Update address");
- System.out.print(">>> ");
- modify = input.nextInt();
- input.nextLine();
- switch (modify) {
- case 1:
- System.out.print("New name: ");
- newName = input.nextLine();
- names.set(position, newName);
- break;
- case 2:
- System.out.print("New address: ");
- newAddress = input.nextLine();
- addresses.set(position, newAddress);
- break;
- default:
- System.out.println("Unknown command!");
- break;
- }
- } else {
- System.out.println(" No data found!!!");
- }
- }
- static void display() {
- System.out.println("All accounts!");
- for (int i = 0; i < names.size(); i++) {
- System.out.println(
- "Name: " + names.get(i) +
- "\nAddress: " + addresses.get(i) +
- "\nDaily Rate: "+ dailyRates.get(i)+
- "\nEnter Number of Work Hours Per Month: "+ noOfHoursWorkPerMonth.get(i)+
- "\nEnter Number of Hours Absent: "+noOfHoursAbsent.get(i)+
- "\nTotal Work hours:"+ totalWorkHours.get(i)+
- "\nEnter Sales Per Month: " + salesPerMonth.get(i)+
- "\nBase Salary: "+ baseSalary.get(i)+
- "\nCommision: "+ Commision.get(i)+
- "\nFinal Salary: "+ finalSalary.get(i)+
- "\nYour Total Deduction is: " + totalDeduction.get(i)+
- "\n"
- );
- }
- }
- static void search() {
- int position = 0, searchBy;
- String name, address;
- boolean matched = false;
- System.out.println("Search an account!");
- System.out.println("[1] By name");
- System.out.println("[2] By address");
- System.out.print(">>> ");
- searchBy = input.nextInt();
- input.nextLine();
- if (searchBy == 1) {
- System.out.print("Name: ");
- name = input.nextLine();
- for (String profile : names) {
- if (profile.contains(name)) {
- matched = true;
- position = names.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- } else if (searchBy == 2) {
- System.out.print("Address: ");
- address = input.nextLine();
- for (String profile : addresses) {
- if (profile.contains(address)) {
- matched = true;
- position = addresses.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- } else {
- System.out.println("Unknown command");
- }
- if (matched == true) {
- System.out.println(
- "Name: " + names.get(position) +
- "\nAddress: " + addresses.get(
- position) +"\nDaily Rate: "+ dailyRates.get(position)+
- "\nEnter Number of Work Hours Per Month: "+ noOfHoursWorkPerMonth.get(position)+
- "\nEnter Number of Hours Absent: "+noOfHoursAbsent.get(position)+
- "\nTotal Work hours:"+ totalWorkHours.get(position)+
- "\nEnter Sales Per Month: " + salesPerMonth.get(position)+
- "\nBase Salary: "+ baseSalary.get(position)+
- "\nCommision: "+ Commision.get(position)+
- "\nFinal Salary: "+ finalSalary.get(position)+
- "\nYour Total Deduction is: " + totalDeduction.get(position)+
- "\n" );
- }
- }
- static int exit(){
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment