/**
* @(#)registration1.java
*
* registration1 application
*
* @author
* @version 1.00 2012/10/14
*/
import java.util.Scanner;
public class registration1 {
public static final String emp[][] = new String[10][4];
public static boolean setInitialData = false;
public static void main(String[] args) {
startPage();
}
public static void startPage(){
boolean tryAgain = true;
boolean notNull =true;
String employee ="";
data(emp);
do{
Scanner input = new Scanner(System.in);
System.out.println("Registration of Employee");
System.out.println("============================================");
System.out.println("Enter your Choice: ");
System.out.println("============================================");
System.out.println("\t\t[a] Register Employee");
System.out.println("\t\t[b] Time Keeping");
System.out.println(" ");
System.out.print("Choose Letter: ");
String choice1 = input.next();
if(choice1.length() == 1){
char choice2 = choice1.charAt(0);
if (choice2 == 'a' || choice2 == 'A'){
empRegistration();
System.out.println("Registration Success!");
displayEmployees();
}else if(choice2 == 'b' || choice2 == 'B'){
int q =searchEmployee(emp);
double noThw = 0;
double tHW = timekeeper(noThw, q);
double r =getTarOver(tHW);
double s =getOver(tHW);
double x =getGross(tHW,q);
double y =getSSS(x);
double z =getPagibig(x);
double a =getPhilHealth(x);
double b =getTotalTax(x,y,z,a);
double o =getTarOverVal(r,q);
double h =getOverVal(s, q);
generatePayslip(x,y,z,a,b,o,h,q);
}
else{
System.out.println("============================================");
System.out.println("Invalid Letter");
System.out.println("============================================");
}
}else{
System.out.println("Invalid String..!");
}
System.out.println("Do you want to try again12?(Y/N) : ");
String response = input.next();
if(!response.equalsIgnoreCase("Y")){
tryAgain = false;
}
}while(tryAgain);
}
public static void empRegistration(){
int noValue = 0;
String empnum="", empfname="", emplname="",position = "";
if(setInitialData==false){
data(emp);
setInitialData = true;
}
Scanner input = new Scanner(System.in);
boolean repeat=false;
do{
System.out.print("\tEnter Employee number: ");
empnum = input.next();
System.out.println("\n");
if(empnum.length() < 5 || empnum.length() > 5){
System.out.println("============================================");
System.out.println("Employee number should be 5 characters.");
System.out.println("");
System.out.println("============================================");
repeat=true;
}else{
repeat=false;
}
}while(repeat);
System.out.print("Enter Employee's First Name: ");
empfname = input.next();
System.out.print("Enter Employee's Last Name: ");
emplname = input.next();
do{
System.out.print("Enter Position: ");
position = input.next();
System.out.println("\n");
if(!position.equalsIgnoreCase("Regular") && !position.equalsIgnoreCase("Manager") && ! position.equalsIgnoreCase("Supervisor")){
System.out.println("============================================");
System.out.println("");
System.out.println("Employee position should only be Regular,Manager or Supervisor.");
System.out.println("");
System.out.println("============================================");
repeat=true;
}else{
repeat = false;
}
}while(repeat);
boolean eno =toVerify( empnum, position);
boolean efn =toVerifyName(empfname);
boolean eln =toVerifyLname(emplname);
toVerifyFinal(eno,efn,eln);
regisSuccess(empnum, empfname, emplname, position);
}
public static void toVerifyFinal(boolean eno, boolean efn, boolean eln){
int noValue = 0;
boolean respond = true;
stop1:
if(eno == respond || efn == respond || eln == respond){
tryAgainRegister();
break stop1;
}else{
System.out.println("Registration Successful!");
}
}
public static void regisSuccess(String empnum, String empfname, String emplname, String position){
int noValue = 0;
noValue = availableRow(emp);
emp[noValue][0] = empnum;
emp[noValue][1] = empfname;
emp[noValue][2] = emplname;
emp[noValue][3] = position;
}
public static int availableRow(String emp[][]){
int noValue = 0;
stop1:
for( int row=0; row<emp.length; row++ ){
if (emp[row][0].equals("")){
noValue = row;
break stop1;
}
}
return noValue;
}
public static void displayEmployees(){
if(setInitialData==false){
data(emp);
setInitialData = true;
}
for(int i=0;i<emp.length;i++){
System.out.println("");
if(!emp[i][0].equals("")){
System.out.println("EMP NUMBER: "+emp[i][0]);
System.out.println("FIRST NAME: "+emp[i][1]);
System.out.println("LAST NAME: "+emp[i][2]);
System.out.println("POSITION: "+emp[i][3]);
}
}
}
public static boolean toVerify(String empnum, String position){
int noValue=0;
int availRow = 0;
boolean respond = true;
Scanner input =new Scanner(System.in);
availRow = availableRow(emp);
stop1:
for(int i =0;i< emp.length; i++){
if(emp[i][0].equals(empnum) ){
System.out.println("Employee number already registered");
return respond;
}
} respond = false;
return respond;
}
public static boolean toVerifyName(String empfname){
boolean respond = true;
int noValue = 0;
Scanner input= new Scanner(System.in);
for(int i= 0; i< emp.length ; i++){
stop1:
if(emp[i][1].equals(empfname)){
System.out.println("Employee First name already registered");
return respond;
}
}
respond = false;
return respond;
}
public static boolean toVerifyLname( String emplname){
boolean respond = true;
int noValue = 0;
for (int i =0; i<emp.length; i ++){
stop1:
if(emp[i][2].equals(emplname)){
System.out.println("Employee Last name already registered");
return respond;
}
}
respond = false;
return respond;
}
public static void tryAgainRegister(){
boolean respond = true;
Scanner input= new Scanner(System.in);
do{
System.out.println("Do you want to try again213?(Y/N)");
String response = input.next();
if(!response.equalsIgnoreCase("Y")){
respond = false;
}else{
empRegistration();
}
}while(respond);
}
// Methods for Time Keeping.
public static int searchEmployee(String emp[][]){
Scanner input = new Scanner (System.in);
System.out.println("Enter Employee number : ");
String empnum = input.next();
int n = 0;
stop1:
for( int row=0; row<emp.length; row++ ){
if (emp[row][0].equals(empnum)){
n = row;
break stop1;
}
}
return n;
}
public static double getTarOver(double tHW){
double a = 120 - tHW;
double one =1;
double noValue = 0;
if(a>one){
System.out.printf("Time Tardy: %.2f",a);
return a;
}
System.out.println("\nNo Time tardy");
return noValue;
}
public static double getOver(double tHW){
double b =tHW -120;
double noValue = 0;
if(b>1){
System.out.printf("Overtime: %.2f",b);
return b;
}
System.out.println("\nNo Overtime");
return noValue;
}
public static double getTarOverVal(double r,int q){
String e =emp[q][3];
double w = 0;
double noValue = 0;
if(e == "Regular"||e == "regular"){
w =r*70;
System.out.printf("Tardy Equivalent: %.2f\n",w);
}else if(e == "Manager"||e == "manager"){
w =r*90;
System.out.printf("Tardy Equivalent: %.2f\n",w);
}else if(e == "Supervisor"||e == "supervisor"){
w = r *110;
System.out.printf("Tardy Equivalent: %.2f\n",w);
}else{
System.out.printf("No tardy1");
return noValue;
}
return w;
}
public static double getOverVal(double s, int q){
String e =emp[q][3];
double w = 0;
double noValue = 0;
if(e == "Regular"||e == "regular"){
w =s*70;
System.out.printf("Overtime Equivalent: %.2f\n",w);
}else if(e == "Manager"||e == "manager"){
w =s*90;
System.out.printf("Overtime Equivalent: %.2f\n",w);
}else if(e == "Supervisor"||e == "supervisor"){
w = s *110;
System.out.printf("Overtime Equivalent: %.2f\n",w);
}else{
System.out.println("No Overtime :");
return noValue;
}
return w;
}
public static double timekeeper(double tHW, int q){
Scanner input = new Scanner(System.in);
double totalHrs = 0;
System.out.println(emp[q][1]+" " + emp[q][2] +" " +emp[q][3]);
for(int i = 1; i <= 15; i++){
System.out.println("day " + i);
System.out.print("Enter time-in: ");
String strTimeIn = input.next();
String timeInArr[] = strTimeIn.split(":");
Double timeInHr = Double.parseDouble(timeInArr[0]);
Double timeInMin = Double.parseDouble(timeInArr[1]);
double timeIn = timeInHr + (timeInMin/60);
System.out.print("Enter time-out: ");
String strTimeOut = input.next();
String timeOutArr[] = strTimeOut.split(":");
Double timeOutHr = Double.parseDouble(timeOutArr[0]);
Double timeOutMin = Double.parseDouble(timeOutArr[1]);
double timeOut = timeOutHr + (timeOutMin/60);
totalHrs = totalHrs + (timeOut - timeIn);
}
System.out.printf("\nTotal Hours worked: %.2f", totalHrs);
return totalHrs;
}
public static double getGross(double tHW,int q){
double noValue = 0;
double w = 0;
System.out.println("\nPosition: ");
String pos = emp[q][3];
System.out.println(pos);
if(pos == "Regular"||pos == "regular"){
w =tHW*70;
System.out.println("=====================Gross-Pay=====================");
System.out.printf("Total of : %.2f",w );
System.out.println("\n===================================================");
System.out.println("");
}else if(pos == "Manager"||pos == "manager"){
w =tHW*90;
System.out.println("=====================Gross-Pay=====================");
System.out.printf("Total of : %.2f",w);
System.out.println("\n===================================================");
System.out.println("");
}else if(pos == "Supervisor"||pos == "supervisor"){
w = tHW *110;
System.out.println("=====================Gross-Pay=====================");
System.out.printf("Total of : %.2f",w);
System.out.println("\n===================================================");
System.out.println("");
}else{
System.out.println("You entered an invalid letter");
return noValue;
}
return w;
}
public static double getSSS(double x){
double noValue = 0;
double sSS=0;
double grossPayM = x*2;
// Range 1
double p =8250;
double r= 8749.99;
// Range 2
double a =10750;
double b =11249.99;
//Range 3
double c =12750;
double d =13249.99;
//range 4
double e =14750;
if(grossPayM > p && grossPayM <r|| grossPayM == r){
sSS =283.30/2;
System.out.println("=================SSS-Contribution==================");
System.out.printf("Total of : %.2f", sSS);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM>a && grossPayM <b|| grossPayM == d){
sSS = 366.70/2;
System.out.println("=================SSS-Contribution==================");
System.out.printf("Total of : %.2f", sSS);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM>c && grossPayM <d || grossPayM == d){
sSS = 416.70/2;
System.out.println("=================SSS-Contribution==================");
System.out.printf("Total of : %.2f", sSS);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM>e){
sSS= 500/2;
System.out.println("=================SSS-Contribution==================");
System.out.printf("Total of : %.2f", sSS);
System.out.println("\n===================================================");
System.out.println("");
}else{
System.out.println("Invalid Sum" );
return noValue;
}
return sSS;
}
public static double getPagibig(double x){
double grossPayM = x*2;
double noValue = 0;
double q = 0;
double piSemiM = 0;
if(grossPayM < 1499 || grossPayM ==1499) {
q =grossPayM * 0.01;
piSemiM = q/2;
System.out.println("===============Pag-ibig=Contribution===============");
System.out.printf("Total of : %.2f" , piSemiM);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 1500 || grossPayM == 1500){
q =grossPayM *0.02;
piSemiM = q/2;
System.out.println("===============Pag-ibig=Contribution===============");
System.out.printf("Total of : %.2f" , piSemiM);
System.out.println("\n===================================================");
System.out.println("");
}else{
System.out.println("System cannot Calculate");
return noValue;
}
return piSemiM;
}
public static double getPhilHealth(double x){
double grossPayM = x*2;
double noValue = 0;
double philCon = 0;
if(grossPayM > 16000 && grossPayM < 16999.99 || grossPayM==16999.99){
philCon = 200/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 17000 && grossPayM < 17999.99 || grossPayM==17999.99){
philCon = 212/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 18000 && grossPayM < 18999.99 || grossPayM==18999.99){
philCon = 225/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 19000 && grossPayM < 19999.99 || grossPayM==19999.99){
philCon = 237.50/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 20000 && grossPayM < 20999.99 || grossPayM==20999.99){
philCon = 250/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 21000 && grossPayM < 21999.99 || grossPayM==21999.99){
philCon = 262.50/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 22000 && grossPayM < 22999.99 || grossPayM==22999.99){
philCon = 275/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 23000 && grossPayM < 23999.99 || grossPayM==23999.99){
philCon = 287.50/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 24000 && grossPayM < 24999.99 || grossPayM==24999.99){
philCon = 300/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else if(grossPayM > 25000 && grossPayM < 25999.99 || grossPayM==25999.99){
philCon = 312.50/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}
else if(grossPayM > 26000 && grossPayM < 26999.99 || grossPayM==26999.99){
philCon = 325/2;
System.out.println("===============PhilHealth=Contribution=============");
System.out.printf("Total of : %.2f ",philCon);
System.out.println("\n===================================================");
System.out.println("");
}else{
System.out.println("System cannot calculate" );
return noValue;
}
return philCon;
}
public static double getTotalTax(double x, double y, double z, double a){
double noValue = 0;
double taxDeductions = y +z + a;
double taxInc = x - taxDeductions;
double intTax = 0;
double taxExc = 0;
double taxExcF =0;
double totalTax = 0;
double totalDeduct = 0;
if(taxInc > 5833|| taxInc == 5833 && taxInc <10416 || taxInc==10416){
intTax = 937.50;
taxExc = taxInc -5833;
taxExcF = taxExc *0.25;
totalTax = taxExcF + intTax;
totalDeduct = taxDeductions + totalTax;
System.out.println("=========================Total=Tax==========================");
System.out.printf("Initial Tax : %.2f\n ", intTax);
System.out.printf("Tax Excess Value: %.2f\n ", taxExcF);
System.out.printf("Total Tax : %.2f\n" ,totalTax);
System.out.printf("Total Deductions : %.2f\n", totalDeduct);
System.out.println("\n============================================================");
}else if(taxInc > 10417|| taxInc == 10417 && taxInc <20832 || taxInc==20832){
intTax = 2083.33;
taxExc = taxInc -10417;
taxExcF = taxExc *0.30;
totalTax = taxExcF + intTax;
System.out.println("=========================Total=Tax==========================");
System.out.printf("Initial Tax : %.2f\n ", intTax);
System.out.printf("Tax Excess Value: %.2f\n ", taxExcF);
System.out.printf("Total Tax : %.2f\n" ,totalTax);
System.out.printf("Total Deductions : %.2f\n", totalDeduct);
System.out.println("\n============================================================");
}else if(taxInc > 20833|| taxInc == 20833){
intTax = 5208.33;
taxExc = taxInc -20833;
taxExcF = taxExc *0.32;
totalTax = taxExcF + intTax;
System.out.println("=========================Total=Tax==========================");
System.out.printf("Initial Tax : %.2f\n ", intTax);
System.out.printf("Tax Excess Value: %.2f\n ", taxExcF);
System.out.printf("Total Tax : %.2f\n" ,totalTax);
System.out.printf("Total Deductions : %.2f\n", totalDeduct);
System.out.println("\n============================================================");
}else{
System.out.println("System cannot Calculate");
return noValue;
}
return totalTax;
}
public static void generatePayslip(double x, double y,double z,double a, double b,double o,double h, int q){
double totalDeduct =y +z+a+b+o;
double netpay = x-totalDeduct;
double netpay1 = netpay + h;
System.out.println("\n============================================================");
System.out.println(" NetPay");
System.out.println("\n============================================================");
System.out.println(emp[q][1]+" " + emp[q][2] +" " +emp[q][3]);
System.out.printf("GrossPay Semi-Monthly : %.2f\n",x);
System.out.println(" DEDUCTIONS ");
System.out.printf("SSS: %.2f\n",y);
System.out.printf("Pag-ibig : %.2f\n",z);
System.out.printf("PhilHealth : %.2f\n",a);
System.out.printf("Total Tax : %.2f\n",b);
System.out.printf("Tardy: %.2f\n", o);
System.out.printf("Total Deductions: %.2f\n", totalDeduct);
System.out.println(" ADD ");
System.out.printf("OverTime: %.2f\n",h );
System.out.println(" NETPAY ");
System.out.printf("TOTAL NETPAY: %.2f\n",netpay1 );
}
public static void data(String emp[][]){
emp[0][0] = "10000";
emp[0][1] = "John Loudwig";
emp[0][2] = "Alonsagay";
emp[0][3] = "Regular";
emp[1][0] = "10001";
emp[1][1] = "Gienna";
emp[1][2] = "Belonio";
emp[1][3] = "Manager";
emp[2][0] = "10002";
emp[2][1] = "James";
emp[2][2] = "Arcilla";
emp[2][3] = "Supervisor";
emp[3][0] = "10003";
emp[3][1] = "Nina";
emp[3][2] = "Hontucan";
emp[3][3] = "Regular";
emp[4][0] = "";
emp[4][1] = "";
emp[4][2] = "";
emp[4][3] = "";
emp[5][0] = "";
emp[5][1] = "";
emp[5][2] = "";
emp[5][3] = "";
emp[6][0] = "";
emp[6][1] = "";
emp[6][2] = "";
emp[6][3] = "";
emp[7][0] = "";
emp[7][1] = "";
emp[7][2] = "";
emp[7][3] = "";
emp[8][0] = "";
emp[8][1] = "";
emp[8][2] = "";
emp[8][3] = "";
emp[9][0] = "";
emp[9][1] = "";
emp[9][2] = "";
emp[9][3] = "";
}
}