Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Payroll{
- static Scanner console = new Scanner(System.in);
- public static void main(String[]args) throws IOException {
- login();
- employee();
- }
- public static void login()throws IOException {
- String IdInput;
- String password;
- int count=0;
- do {
- System.out.print("Username: ");
- IdInput = console.next();
- System.out.print("Password: ");
- password = console.next();
- if(IdInput.equals("rjmj") && password.equals("1234")) {
- System.out.println("Welcome to RJMJ Academy ");
- count = 4;
- Payroll.employee();
- }
- else {
- System.out.print("Incorrect password ");
- }
- count++;
- }while(count<3);
- System.exit(0);
- }
- public static void employee() throws IOException {
- boolean notExists = true;
- while(notExists == true) {
- //objects
- FileInputStream jane = new FileInputStream("empData.txt");
- DataInputStream in = new DataInputStream(jane);
- BufferedReader textReader = new BufferedReader(new InputStreamReader(in));
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String str = "", UserInput = "", tmp = "",welcome="",empName, empId = "";
- String empRank = "",empSg="",empcode="";
- double emprate = 0.0, lateMin, absent;
- int ctr = 0;
- double perDay, day, perHour, dsalary, halfLate, minLate, dayLate;
- double dabsent, dayAbsent, deductAbsent, deductLate, totalDeduction, netSalary, s1, s2, s3;
- String dL, dA, gS;
- System.out.print("Enter Employee Code: ");
- UserInput = br.readLine();
- //loop through the text file
- while( (str = textReader.readLine()) != null ) {
- if(str.equalsIgnoreCase(UserInput)) {
- empcode = UserInput;
- //found the userinput and stores data
- while( (tmp = textReader.readLine()) != null) {
- //reference variable everyline
- switch(ctr) {
- case 0:
- empRank = tmp;
- break;
- case 1:
- empSg = tmp;
- case 2:
- emprate = Double.parseDouble(tmp);
- break;
- }
- ctr++;
- }
- }
- }
- System.out.println();
- System.out.println();
- //check if record exists
- if( !(empcode.equalsIgnoreCase("")) ) {
- System.out.println("***************************Employee Details**************************");
- System.out.println("Employee ID #: " + empcode);
- System.out.println("Employee Rank : " + empRank);
- System.out.println("Employee SG: " +empSg);
- System.out.println("Employee Rate : " + emprate);
- System.out.println();
- System.out.println("********************************************************************");
- //ask the user to input his info
- System.out.print("Enter your name: ");
- empName = br.readLine();
- System.out.print("Enter you Id number: ");
- empId =console.next();
- System.out.print("Enter Date Covered : " );
- String covered = console.next();
- System.out.print("How minutes you're late? ");
- lateMin =console.nextDouble();
- System.out.print("How many days absent? ");
- absent= console.nextDouble();
- perDay=emprate/20;
- day =emprate/2;
- perHour = perDay/8;
- dsalary = perDay*10;
- halfLate= perDay/2;
- minLate= halfLate/15;
- dayLate =dsalary -minLate*lateMin;
- dabsent =perDay*absent;
- dayAbsent=day-dabsent;
- deductAbsent =day-dayAbsent;
- deductLate =day-dayLate;
- totalDeduction =deductLate+deductAbsent;
- netSalary =day- totalDeduction;
- s1=deductLate;
- s2=deductAbsent;
- s3=netSalary;
- dL=Double.toString(s1);
- dA=Double.toString(s2);
- gS=Double.toString(s3);
- //information of the user
- System.out.println();
- System.out.println("****************EMPLOYEE BIMONTH PAYROLL****************************");
- System.out.println();
- System.out.println(" Name : " +empName);
- System.out.println(" Id Number : "+empId);
- System.out.println(" Employee Code: " + empcode);
- System.out.println(" Employee Rank : " + empRank);
- System.out.println(" Employee SG: " +empSg);
- System.out.println(" Employee Rate : " + emprate);
- System.out.println();
- System.out.println(" Date Covered : " + covered);
- System.out.printf(" Deduction Late : Php %-10.2f%n",deductLate);
- System.out.printf(" Deduction Absent : Php %-10.2f%n",deductAbsent);
- System.out.printf(" Net Salary : Php %-10.2f %n", netSalary);
- System.out.println();
- System.out.println("*********************************************************************");
- //outfile of the user
- try {
- FileOutputStream out=new FileOutputStream("output.txt");
- String emp="*********************EMPLOYEE BIMONTH PAYROLL***************************"+welcome+"\r\n";
- String r ="Name : " +empName+"\r\n";
- String q ="Id Number : "+empId+"\r\n";
- String z="Employee Code:" + empcode+"\r\n";
- String y= "Employee Rank :" + empRank+"\r\n";
- String x= "Employee SG:" +empSg+"\r\n";
- String w="Employee Rate :" + emprate+"\r\n";
- String v="Date Covered : " + covered+"\r\n";
- String u="Deduction Late : Php "+s1+"\r\n";
- String t="Deduction Absent : Php "+s2+"\r\n";
- String s="Net Salary : Php "+s3+"\r\n";
- byte a[]=emp.getBytes();
- out.write(a);
- byte i[]=r.getBytes();
- out.write(i);
- byte j[]=q.getBytes();
- out.write(j);
- byte em[]=z.getBytes();
- out.write(em);
- byte b[]=y.getBytes();
- out.write(b);
- byte c[]=x.getBytes();
- out.write(c);
- byte d[]=w.getBytes();
- out.write(d);
- byte f[]=u.getBytes();
- out.write(f);
- byte g[]=t.getBytes();
- out.write(g);
- byte h[]=s.getBytes();
- out.write(h);
- out.flush();
- out.close();
- }
- catch(Exception e) {
- System.out.print(e);
- }
- System.exit(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement