grhey

Payroll System

Jul 4th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.50 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3.  
  4.  
  5. public class PayrollSystem {
  6. static ArrayList<String> names = new ArrayList<String> ();
  7. static ArrayList<String> addresses = new ArrayList<String> ();
  8. static ArrayList<Integer> dailyRates = new ArrayList<Integer> ();
  9. static ArrayList<Integer> noOfHoursWorkPerMonth = new ArrayList<Integer> ();
  10. static ArrayList<Integer> noOfHoursAbsent = new ArrayList<Integer> ();
  11. static ArrayList<Integer> totalWorkHours = new ArrayList<Integer> ();
  12. static ArrayList<Double> salesPerMonth = new ArrayList<Double> ();
  13. static ArrayList<String> Commision = new ArrayList<String> ();
  14. static ArrayList<Double> totalDeduction = new ArrayList<Double> ();
  15. static ArrayList<Double> finalSalary = new ArrayList<Double> ();
  16. static ArrayList<Double> baseSalary = new ArrayList<Double> ();
  17. static ArrayList<Double> totalSalary = new ArrayList<Double> ();
  18.  
  19. static Scanner input = new Scanner(System.in);
  20.  
  21. public static void main(String[]args){
  22. int mainMenu= -1;
  23. while (mainMenu != 0) {
  24. menu();
  25. mainMenu = input.nextInt();
  26. input.nextLine();
  27. switch (mainMenu) {
  28. case 0:
  29. exit();
  30. break;
  31. case 1:
  32. add();
  33. break;
  34. case 2:
  35. update();
  36. break;
  37. case 3:
  38. display();
  39.  
  40. break;
  41. case 4:
  42. search();
  43.  
  44. default:
  45. System.out.println("Out of range");
  46. main(args);
  47. break;
  48. }
  49. }
  50.  
  51. }
  52.  
  53. static void menu(){
  54. System.out.println("Payroll System");
  55. System.out.println("[1] Add new account");
  56. System.out.println("[2] Update existing account");
  57. System.out.println("[3] Display all accounts");
  58. System.out.println("[4] Search for account");
  59. System.out.println("[0] Exit");
  60. System.out.print(">>> ");
  61.  
  62. }
  63. static void add(){
  64. String name,address;
  65. int rate;
  66. int DailyRatePerHour;
  67. int NumberOfHoursWorkPerMonth, NumberOfHoursAbsent;
  68. int TotalWorkHours;
  69. double BaseSalary;
  70.  
  71. System.out.println("Add new user!");
  72. System.out.print("Name : ");
  73. name = input.nextLine();
  74. names.add(name);
  75. System.out.print("Address: ");
  76. address = input.nextLine();
  77. addresses.add(address);
  78. System.out.print("Daily Rate: ");
  79. DailyRatePerHour = input.nextInt();
  80. dailyRates.add(DailyRatePerHour);
  81. System.out.println("Enter Number of Work Hours Per Month: ");
  82. NumberOfHoursWorkPerMonth=input.nextInt();
  83. noOfHoursWorkPerMonth.add(NumberOfHoursWorkPerMonth);
  84. System.out.println("Enter Number of Hours Absent:");
  85. NumberOfHoursAbsent=input.nextInt();
  86. noOfHoursAbsent.add(NumberOfHoursAbsent);
  87. TotalWorkHours=NumberOfHoursWorkPerMonth-NumberOfHoursAbsent;
  88. System.out.println("Total Work Hours:"+TotalWorkHours);
  89. totalWorkHours.add(TotalWorkHours);
  90. double sales=0;
  91. System.out.println("Enter Sales Per Month:");
  92. sales=input.nextDouble();
  93.  
  94. if(sales>=10000){
  95. Commision.add("You have 3% Monthly Commision");
  96.  
  97. }else if(sales>=20000){
  98. Commision.add("You have 4% Monthly Commision");
  99.  
  100. }else if(sales>=30000){
  101. Commision.add("You have 5% Monthly Commision");
  102.  
  103. }else if(sales>=40000){
  104. Commision.add("You have 10% Monthly Commision");
  105.  
  106. }if (sales<10000){
  107. Commision.add("You have no Monthly Commision");
  108.  
  109. }
  110. salesPerMonth.add(sales);
  111.  
  112. System.out.println("[1] Married With Children");
  113. System.out.println("[2] Married Without Children");
  114. System.out.println("[3] Single Parent");
  115. System.out.println("[4] Single");
  116. System.out.print(">>> ");
  117. rate = input.nextInt();
  118. BaseSalary=TotalWorkHours*DailyRatePerHour;
  119. baseSalary.add(BaseSalary);
  120. int SSS=550;
  121. int PagIbig=500;
  122. double FinalSalary;
  123. double totalDeductions;
  124.  
  125. if (rate ==1){
  126. double TotalSalary = BaseSalary*.05;
  127. totalSalary.add(TotalSalary);
  128. totalDeductions = SSS+PagIbig;
  129. totalDeduction.add(TotalSalary);
  130. FinalSalary=TotalSalary-totalDeductions;
  131.  
  132. finalSalary.add(FinalSalary);
  133.  
  134. }else if(rate ==2){
  135. double TotalSalary = BaseSalary*0.01;
  136. totalSalary.add(TotalSalary);
  137. totalDeductions = SSS+PagIbig;
  138. totalDeduction.add(TotalSalary);
  139. FinalSalary=TotalSalary-totalDeductions;
  140.  
  141. finalSalary.add(FinalSalary);
  142. }else if(rate ==3){
  143. double TotalSalary = BaseSalary* 0.05;
  144. totalDeductions = SSS+PagIbig;
  145. totalDeduction.add(TotalSalary);
  146. FinalSalary=TotalSalary-totalDeductions;
  147.  
  148. finalSalary.add(FinalSalary);
  149. } if(rate ==4){
  150.  
  151. double TotalSalary = BaseSalary* 0.15;
  152.  
  153. totalDeductions = SSS+PagIbig;
  154. totalDeduction.add(TotalSalary);
  155. FinalSalary= TotalSalary-totalDeductions;
  156.  
  157. finalSalary.add(FinalSalary);
  158. }
  159.  
  160.  
  161. }
  162. static void update(){
  163. String name, newName, newAddress;
  164. System.out.println("Update account!");
  165. System.out.print("Name: ");
  166. name = input.nextLine();
  167. int position = 0;
  168. boolean matched = false;
  169. for (String profile : names) {
  170. if (profile.contains(name)) {
  171. matched = true;
  172. position = names.indexOf(profile);
  173. break;
  174. } else {
  175. matched = false;
  176. }
  177. }
  178. if (matched == true) {
  179. int modify;
  180. System.out.println("[1] Update name");
  181. System.out.println("[2] Update address");
  182. System.out.print(">>> ");
  183. modify = input.nextInt();
  184. input.nextLine();
  185. switch (modify) {
  186. case 1:
  187. System.out.print("New name: ");
  188. newName = input.nextLine();
  189. names.set(position, newName);
  190. break;
  191. case 2:
  192. System.out.print("New address: ");
  193. newAddress = input.nextLine();
  194. addresses.set(position, newAddress);
  195. break;
  196. default:
  197. System.out.println("Unknown command!");
  198. break;
  199. }
  200. } else {
  201. System.out.println(" No data found!!!");
  202. }
  203. }
  204.  
  205. static void display() {
  206.  
  207. System.out.println("All accounts!");
  208.  
  209. for (int i = 0; i < names.size(); i++) {
  210. System.out.println(
  211. "Name: " + names.get(i) +
  212. "\nAddress: " + addresses.get(i) +
  213. "\nDaily Rate: "+ dailyRates.get(i)+
  214. "\nEnter Number of Work Hours Per Month: "+ noOfHoursWorkPerMonth.get(i)+
  215. "\nEnter Number of Hours Absent: "+noOfHoursAbsent.get(i)+
  216. "\nTotal Work hours:"+ totalWorkHours.get(i)+
  217. "\nEnter Sales Per Month: " + salesPerMonth.get(i)+
  218. "\nBase Salary: "+ baseSalary.get(i)+
  219. "\nCommision: "+ Commision.get(i)+
  220. "\nFinal Salary: "+ finalSalary.get(i)+
  221. "\nYour Total Deduction is: " + totalDeduction.get(i)+
  222. "\n"
  223.  
  224. );
  225.  
  226. }
  227.  
  228. }
  229. static void search() {
  230. int position = 0, searchBy;
  231. String name, address;
  232. boolean matched = false;
  233. System.out.println("Search an account!");
  234. System.out.println("[1] By name");
  235. System.out.println("[2] By address");
  236. System.out.print(">>> ");
  237. searchBy = input.nextInt();
  238. input.nextLine();
  239. if (searchBy == 1) {
  240. System.out.print("Name: ");
  241. name = input.nextLine();
  242. for (String profile : names) {
  243. if (profile.contains(name)) {
  244. matched = true;
  245. position = names.indexOf(profile);
  246. break;
  247. } else {
  248. matched = false;
  249. }
  250. }
  251. } else if (searchBy == 2) {
  252. System.out.print("Address: ");
  253. address = input.nextLine();
  254. for (String profile : addresses) {
  255. if (profile.contains(address)) {
  256. matched = true;
  257. position = addresses.indexOf(profile);
  258. break;
  259. } else {
  260. matched = false;
  261. }
  262. }
  263. } else {
  264. System.out.println("Unknown command");
  265. }
  266.  
  267. if (matched == true) {
  268. System.out.println(
  269. "Name: " + names.get(position) +
  270. "\nAddress: " + addresses.get(
  271. position) +"\nDaily Rate: "+ dailyRates.get(position)+
  272. "\nEnter Number of Work Hours Per Month: "+ noOfHoursWorkPerMonth.get(position)+
  273. "\nEnter Number of Hours Absent: "+noOfHoursAbsent.get(position)+
  274. "\nTotal Work hours:"+ totalWorkHours.get(position)+
  275. "\nEnter Sales Per Month: " + salesPerMonth.get(position)+
  276. "\nBase Salary: "+ baseSalary.get(position)+
  277. "\nCommision: "+ Commision.get(position)+
  278. "\nFinal Salary: "+ finalSalary.get(position)+
  279. "\nYour Total Deduction is: " + totalDeduction.get(position)+
  280. "\n" );
  281.  
  282. }
  283. }
  284.  
  285. static int exit(){
  286. return 0;
  287. }
  288. }
  289.  
  290.  
  291.  
  292.  
Advertisement
Add Comment
Please, Sign In to add comment