Advertisement
Guest User

Untitled

a guest
May 2nd, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Payroll{
  5. static Scanner console = new Scanner(System.in);
  6. public static void main(String[]args) throws IOException {
  7.  
  8. login();
  9. employee();
  10.  
  11. }
  12. public static void login()throws IOException {
  13. String IdInput;
  14. String password;
  15. int count=0;
  16.  
  17. do {
  18. System.out.print("Username: ");
  19. IdInput = console.next();
  20. System.out.print("Password: ");
  21. password = console.next();
  22.  
  23. if(IdInput.equals("rjmj") && password.equals("1234")) {
  24. System.out.println("Welcome to RJMJ Academy ");
  25. count = 4;
  26. Payroll.employee();
  27.  
  28. }
  29. else {
  30. System.out.print("Incorrect password ");
  31. }
  32. count++;
  33. }while(count<3);
  34. System.exit(0);
  35. }
  36. public static void employee() throws IOException {
  37. boolean notExists = true;
  38.  
  39. while(notExists == true) {
  40. //objects
  41. FileInputStream jane = new FileInputStream("empData.txt");
  42. DataInputStream in = new DataInputStream(jane);
  43. BufferedReader textReader = new BufferedReader(new InputStreamReader(in));
  44. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  45.  
  46. String str = "", UserInput = "", tmp = "",welcome="",empName, empId = "";
  47. String empRank = "",empSg="",empcode="";
  48. double emprate = 0.0, lateMin, absent;
  49. int ctr = 0;
  50. double perDay, day, perHour, dsalary, halfLate, minLate, dayLate;
  51. double dabsent, dayAbsent, deductAbsent, deductLate, totalDeduction, netSalary, s1, s2, s3;
  52. String dL, dA, gS;
  53.  
  54. System.out.print("Enter Employee Code: ");
  55. UserInput = br.readLine();
  56. //loop through the text file
  57. while( (str = textReader.readLine()) != null ) {
  58.  
  59. if(str.equalsIgnoreCase(UserInput)) {
  60. empcode = UserInput;
  61. //found the userinput and stores data
  62. while( (tmp = textReader.readLine()) != null) {
  63. //reference variable everyline
  64. switch(ctr) {
  65. case 0:
  66. empRank = tmp;
  67. break;
  68. case 1:
  69. empSg = tmp;
  70. case 2:
  71. emprate = Double.parseDouble(tmp);
  72. break;
  73. }
  74. ctr++;
  75. }
  76. }
  77. }
  78. System.out.println();
  79. System.out.println();
  80. //check if record exists
  81. if( !(empcode.equalsIgnoreCase("")) ) {
  82.  
  83. System.out.println("***************************Employee Details**************************");
  84. System.out.println("Employee ID #: " + empcode);
  85. System.out.println("Employee Rank : " + empRank);
  86. System.out.println("Employee SG: " +empSg);
  87. System.out.println("Employee Rate : " + emprate);
  88. System.out.println();
  89. System.out.println("********************************************************************");
  90. //ask the user to input his info
  91. System.out.print("Enter your name: ");
  92. empName = br.readLine();
  93. System.out.print("Enter you Id number: ");
  94. empId =console.next();
  95. System.out.print("Enter Date Covered : " );
  96. String covered = console.next();
  97. System.out.print("How minutes you're late? ");
  98. lateMin =console.nextDouble();
  99. System.out.print("How many days absent? ");
  100. absent= console.nextDouble();
  101.  
  102. perDay=emprate/20;
  103. day =emprate/2;
  104. perHour = perDay/8;
  105. dsalary = perDay*10;
  106. halfLate= perDay/2;
  107. minLate= halfLate/15;
  108. dayLate =dsalary -minLate*lateMin;
  109. dabsent =perDay*absent;
  110. dayAbsent=day-dabsent;
  111. deductAbsent =day-dayAbsent;
  112. deductLate =day-dayLate;
  113. totalDeduction =deductLate+deductAbsent;
  114. netSalary =day- totalDeduction;
  115. s1=deductLate;
  116. s2=deductAbsent;
  117. s3=netSalary;
  118. dL=Double.toString(s1);
  119. dA=Double.toString(s2);
  120. gS=Double.toString(s3);
  121. //information of the user
  122. System.out.println();
  123. System.out.println("****************EMPLOYEE BIMONTH PAYROLL****************************");
  124. System.out.println();
  125. System.out.println(" Name : " +empName);
  126. System.out.println(" Id Number : "+empId);
  127. System.out.println(" Employee Code: " + empcode);
  128. System.out.println(" Employee Rank : " + empRank);
  129. System.out.println(" Employee SG: " +empSg);
  130. System.out.println(" Employee Rate : " + emprate);
  131.  
  132. System.out.println();
  133.  
  134. System.out.println(" Date Covered : " + covered);
  135. System.out.printf(" Deduction Late : Php %-10.2f%n",deductLate);
  136. System.out.printf(" Deduction Absent : Php %-10.2f%n",deductAbsent);
  137. System.out.printf(" Net Salary : Php %-10.2f %n", netSalary);
  138. System.out.println();
  139. System.out.println("*********************************************************************");
  140. //outfile of the user
  141. try {
  142. FileOutputStream out=new FileOutputStream("output.txt");
  143. String emp="*********************EMPLOYEE BIMONTH PAYROLL***************************"+welcome+"\r\n";
  144. String r ="Name : " +empName+"\r\n";
  145. String q ="Id Number : "+empId+"\r\n";
  146. String z="Employee Code:" + empcode+"\r\n";
  147. String y= "Employee Rank :" + empRank+"\r\n";
  148. String x= "Employee SG:" +empSg+"\r\n";
  149. String w="Employee Rate :" + emprate+"\r\n";
  150. String v="Date Covered : " + covered+"\r\n";
  151. String u="Deduction Late : Php "+s1+"\r\n";
  152. String t="Deduction Absent : Php "+s2+"\r\n";
  153. String s="Net Salary : Php "+s3+"\r\n";
  154. byte a[]=emp.getBytes();
  155. out.write(a);
  156. byte i[]=r.getBytes();
  157. out.write(i);
  158. byte j[]=q.getBytes();
  159. out.write(j);
  160. byte em[]=z.getBytes();
  161. out.write(em);
  162. byte b[]=y.getBytes();
  163. out.write(b);
  164. byte c[]=x.getBytes();
  165. out.write(c);
  166. byte d[]=w.getBytes();
  167. out.write(d);
  168. byte f[]=u.getBytes();
  169. out.write(f);
  170. byte g[]=t.getBytes();
  171. out.write(g);
  172. byte h[]=s.getBytes();
  173. out.write(h);
  174.  
  175. out.flush();
  176. out.close();
  177. }
  178. catch(Exception e) {
  179. System.out.print(e);
  180.  
  181. }
  182.  
  183. System.exit(0);
  184. }
  185. }
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement