Make your own free website on Tripod.com

class fullTimeEmployee

{

private String firstName;

private String lastName;

private String empId;

private double payRate;

private double hoursWorked;

public fullTimeEmployee(String fn,String ln, String id, double rate, double hrs)

{

firstName=fn;

lastName=ln;

empId=id;

payRate=rate;

hoursWorked=hrs;

}


public String getFirstName()

{

return firstName;

}


public String getLastName()

{

return lastName;

}


public String getId()

{

return empId;

}


public double getPayrate()

{

return payRate;

}


public double getHrsWork()

{

return hoursWorked;

}

public double calculatePay()

{

return(payRate*hoursWorked);

}

}



public class casualEmployee extends fullTimeEmployee

{

private String type;


public casualEmployee(String firstName,String lastName,String emptId, double payRate, double hoursWorked,String t)

{

super (firstName,lastName, emptId, payRate, hoursWorked);

type=t;

}


public String getEmpType()

{return "Employment type:\t"+type;}

}



//Name: Chumnap Thach

//Function: Calculate payroll

//Date: 25, may, 2005


import java.io.*;

class test

{

static BufferedReader kb=new BufferedReader(new InputStreamReader(System.in));


//==================Main method==========================

public static void main(String [] args) throws IOException

{

int num=0; char cont;

do{

do

{

menu();

num = Integer.parseInt(kb.readLine());

switch(num)

{

case 1:

enterDetail();

break;


case 2:

readList();

break;


case 3:

break;

default: System.out.print("out of range..");

}//end switch

}while(num !=3);//end do

System.out.print("Are you sure you want to exit? (y/n): ");

String s=kb.readLine();

cont=s.charAt(0);

}while(cont !='y');

}//end main




//===========MENU========

public static void menu()

{

System.out.println("\n\t\t---------------------------------");

System.out.println("\t\t\tEMPLOYEE PAY SYSTEM..");

System.out.println("\t\t---------------------------------");

System.out.println();

System.out.println("\t\t1.\tCalculate employee pay");

System.out.println("\t\t2.\tPrint employee list");

System.out.println("\t\t3.\tExit");

}


//=======================================================

public static void enterDetail() throws IOException

{

int fullTimeNo=2;

int casualNo=2;

int noOfEmployee=fullTimeNo+casualNo;

//public double hoursWorked=0;

String []fname= new String[noOfEmployee];

String []lname= new String[noOfEmployee];

String []id=new String[noOfEmployee];

String []type= new String[noOfEmployee];

double []rate =new double[noOfEmployee];

double []hrs=new double[noOfEmployee];

double []pay=new double[noOfEmployee];



fullTimeEmployee []fm= new fullTimeEmployee[noOfEmployee];


//---------ENTER FULL TIME EMPLOYEE DETAIL---------------------


System.out.print("Please enter employment type: ");

System.out.print("'F' for \"full time\", 'C' for \"Casual\"");

char empType = kb.readLine().charAt(0);

switch(empType)

{

case 'f':

case 'F':


System.out.print("Please enter full time pay rate:\t");

double payRate=Double.parseDouble(kb.readLine());


for(int i=0;i<fullTimeNo;i++)

{

System.out.print(i+". First name:\t");

String firstName=kb.readLine();


System.out.print(i+". Last name:\t");

String lastName=kb.readLine();


System.out.print(i+". Id number :\t");

String empId=kb.readLine();

System.out.println();


System.out.println("\n\t\tPlease enter hours worked");


System.out.print("\t\tMonday:\t\t");

double Monday=Double.parseDouble(kb.readLine());


System.out.print("\t\tTuesday:\t");

double Tuesday=Double.parseDouble(kb.readLine());


System.out.print("\t\tWednesday:\t");

double Wednesday=Double.parseDouble(kb.readLine());


System.out.print("\t\tThursdy:\t");

double Thursday=Double.parseDouble(kb.readLine());


System.out.print("\t\tFriday:\t\t");

double Friday=Double.parseDouble(kb.readLine());


double hoursWorked=Monday+Tuesday+Wednesday+Thursday+Friday;

System.out.println("\t\tHours worked:\t"+hoursWorked);


//Constructor

fm[i]=new fullTimeEmployee(firstName, lastName, empId, payRate, hoursWorked);


System.out.println("You was enter detail as below:");

fullTimeEmployee f=fm[i];

System.out.println(i+". First name:\t"+f.getFirstName());

System.out.println(i+". Last name:\t"+f.getLastName());

System.out.println(i+". Gross pay:\t"+f.calculatePay());


fname[i]=firstName;

lname[i]=lastName;

id[i]=empId;

type[i]= "Full time";

rate[i]=payRate;

hrs[i]=hoursWorked;

pay[i]=payRate*hoursWorked;

}//end for


//==============

try{

PrintWriter pw=new PrintWriter(new FileWriter("payslip.txt"));

for(int i=0;i<fullTimeNo;i++)

{

pw.print("First name:\t");

pw.println(fname[i]);

pw.print("Last name:\t");

pw.println(lname[i]);

pw.print("Id number:\t");

pw.println(id[i]);

pw.println("Employment type:\t"+type[i]);

pw.println("Pay rate\t"+rate[i]);

pw.println("Hours Worked\t"+hrs[i]);

pw.println("Gross pay:\t"+pay[i]);

pw.println(); //seperate each employee

// System.out.print(lname[i]);

}

pw.close();

System.out.println("Payslip has been write to payslip.txt");

}

catch(IOException e)

{

System.out.print("File writing errors");

}

//==================

PrintWriter pw2=new PrintWriter(new FileWriter("list.txt"));

for(int i=0;i<fullTimeNo;i++)

{

pw2.print(fname[i]);

pw2.print("\t");

pw2.println(lname[i]);

}

pw2.close();



break;


case 'c':

case 'C':

//-------Enter casual employee details-------------------

System.out.println("\n\tPLEASE ENTER CASUAL EMPLOYEE DETAIL");

System.out.print("Please enter Casual pay rate:\t");

payRate=Double.parseDouble(kb.readLine());



for(int i=fullTimeNo;i<fm.length;i++)

{

System.out.print(i+". First name:\t");

String firstName=kb.readLine();


System.out.print(i+". Last name:\t");

String lastName=kb.readLine();


System.out.print(i+". Id number:\t");

String empId=kb.readLine();



double hoursWorked;

System.out.println("\n\t\tPlease enter hours worked");

System.out.print("\t\tMonday:\t\t");

double Monday=Double.parseDouble(kb.readLine());

//hoursWorked=Monday;


System.out.print("\t\tTuesday:\t");

double Tuesday=Double.parseDouble(kb.readLine());


System.out.print("\t\tWednesday:\t");

double Wednesday=Double.parseDouble(kb.readLine());


System.out.print("\t\tThursdy:\t");

double Thursday=Double.parseDouble(kb.readLine());


System.out.print("\t\tFriday:\t\t");

double Friday=Double.parseDouble(kb.readLine());


hoursWorked=Monday+Tuesday+Wednesday+Thursday+Friday;

System.out.println("Hours work\t"+hoursWorked);



casualEmployee cs=new casualEmployee(firstName, lastName,empId, payRate,hoursWorked,"Casual");

fm[i]=cs;

casualEmployee c=cs;

System.out.println(c.getEmpType());

System.out.println();

fname[i]=firstName;

lname[i]=lastName;

id[i]=empId;

type[i]="Casual";

rate[i]=payRate;

hrs[i]=hoursWorked;

pay[i]=payRate*hoursWorked;

}


//======================

PrintWriter p=new PrintWriter(new FileWriter("payslip.txt"));

for(int i=fullTimeNo;i<fm.length;i++)

{

p.print("First name:\t");

p.println(fname[i]);

p.print("Last name:\t");

p.println(lname[i]);

p.print("Id number:\t");

p.println(id[i]);

p.println("Employment type:\t"+type[i]);

p.println("Pay rate\t"+rate[i]);

p.println("Hours Worked\t"+hrs[i]);

p.println("Gross pay:\t"+pay[i]);

p.println(); //seperate each employee

// System.out.print(lname[i]);

}

p.close();

System.out.println("Payslip has been write to payslip.txt");


PrintWriter p2=new PrintWriter(new FileWriter("list.txt"));

for(int i=fullTimeNo;i<fm.length;i++)

{

p2.print(fname[i]);

p2.print("\t");

p2.println(lname[i]);

}

p2.close();


break;

default: System.out.print("Please enter C or F");


}


}//enterDetail?



//=================Read payslip==================

public static void readList()throws IOException

{

FileReader fr=new FileReader("list.txt");

BufferedReader rf=new BufferedReader(fr);

boolean eof=false;

while(!eof)

{

String line=rf.readLine();

if(line==null)

eof=true;

else

System.out.println(line);

}rf.close();

}


}//end class