*Coded by: Aron Jay Oyong *Email: aron_jay17@live.com *Created on the 4th day of February 2009. ***LICENSE** *This program is licensed under Creative Commons with Attribution-Non Commercial -Share Alike 3.0 Philippines. *see... http://creativecommons.org/licenses/by-nc-sa/3.0/ph/ ... (Common Deed) *see... http://creativecommons.org/licenses/by-nc-sa/3.0/ph/legalcode ... (Legal Code) * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentati on * and/or other materials provided with the program. */ //------------------------------------------------------------// import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import javax.swing.JOptionPane; public class Payroll { public static void main (String[]args) throws IOException{ //input, output and formula for fields are declared here. //?? int tryAgain, //Allows the user to input another accou nt timeIN, //Asks the starting working hour timeOUT, //Asks the end working hour totalTime, //Allows to subtract the timeIN and timeOUT to get the total regular working hours totalHW, //The total of regular working h ours and overtime overTime, //The factorial of payRate and totalHW preOT, //Asks the user for the number o f overtime working hours totalOT, //Multiplies the overTime to pre OT commision, //Asks the user for the commisio n earned payRate=500; //The default hourly payRate double salary, //Multiplies the payRate to the totalTim e preSalary, //Sums the salary and th e commision earned totalSalary; //The sum of preSalary and total OT String name, //Asks the user to input a name accountNum; //Asks the user to input the ID number //start of the loop //?? do { FileWriter fw = new FileWriter("payroll.rtf"); BufferedWriter bw = new BufferedWriter(fw); // Sets up the bufferedwriter stream PrintWriter pw = new PrintWriter(bw); // Sets up the printwriter stream //?? //starting initialization for the JOptionPane accountNum=JOptionPane.showInputDialog("Eployee ID Number: ","ID Number Please"); Object[] possibleValues = { "Mr.", "Ms.", "Mrs." }; Object salutation= JOptionPane.showInputDialog(null, "Choose one", "Prefered Salutation", JOptionPane.QUESTION_MESSAGE, null, possibleValues, possibleValues[0]); //------------------------------------------// name=JOptionPane.showInputDialog("Employee Name: ",""+salutation ); timeIN=Integer.parseInt(JOptionPane.showInputDialog("Time In: ", "Starting Working Hour ")); //? String[] choices1 = { "AM", "PM", ""}; String dayTime1 = (String) JOptionPane.showInputDialog(null, "Ti me In: "+timeIN, "Morning or Afternoon?", JOptionPane.QUESTION_MESSAGE, n ull, choices1, choices1[1]); //? timeOUT=Integer.parseInt(JOptionPane.showInputDialog("Time Out: ","End Working Hour")); String[] choices2 = { "AM", "PM", ""}; String dayTime2 = (String) JOptionPane.showInputDialog(null, "Ti me Out: "+timeOUT, "Morning or Afternoon?", JOptionPane.QUESTION_MESSAGE, n ull, choices2, choices2[1]); //? preOT=Integer.parseInt(JOptionPane.showInputDialog("Over Time: " ,"Number of Hours")); commision=Integer.parseInt(JOptionPane.showInputDialog("Commisio n: ","Commision Earned")); //computation of regular working hours if(timeIN>=timeOUT) //when the input timeIN is great er than or equal to timeOUT the forumala is { totalTime=timeIN-timeOUT; } else //but if timeIN is less than or equal to timeOUT the formula is { totalTime=timeOUT-timeIN; } /*computation of the total salary *-------------WARNING!-------------WARNING!-------------- *do not touch this part or the whole world will fall on you *?? */ salary=payRate*totalTime; //in order: process 1 preSalary=salary+commision; //do not revert or alter any of these formula totalHW=preOT+totalTime; overTime=payRate/totalHW; totalOT=overTime+payRate; totalSalary=preSalary+totalOT; //last: process 6 /*?? *?? *-------------------------------------------------------*/ //input confirmation dialog Object[] options = {"OK"}; JOptionPane.showOptionDialog(null, "ID Number: "+accountNum+"\nN ame: "+name+"\nTime In: "+timeIN+" "+dayTime1 +"\nTime Out: "+timeOUT+" "+dayTime2+"\nOvertime : "+preOT+" Hr."+"\nCommision: "+commision, "You have entered the following", JOptionPane.YES_OPTION, JOptionPane.WARNING_MESS AGE, null, options, options[0]); //total salary earned JOptionPane.showMessageDialog(null, "Salary: " +totalSalary, "Total salary for "+name, JOptionPane.INFORMATIO N_MESSAGE); /*------------------------------------------- *information message*/ JOptionPane.showConfirmDialog(null, "The detailed summary has been written in the pr ogram directory for print output"+ "\nFor further details please see the console wi ndow", "Notice", JOptionPane.CLOSED_OPTION, JOptionPane.INFORMATI ON_MESSAGE); //below is the initialization of the complete output and its det ailed parameters for the console window System.out.println("-------------------------------------------- "); System.out.println(" || PAYROLL SYSTEM || "); System.out.println("-------------------------------------------- "); System.out.println(); System.out.println("Pay Rate: "+payRate+" /Hr."); System.out.println("Over Time Rate: "+totalOT+" /Hr."); System.out.println(); System.out.println("-------------------------------------------- "); System.out.println(); System.out.println("ID Number: "+accountNum); System.out.println("Name: "+name); System.out.println("Starting Working Hour: "+timeIN+" "+dayTime1 ); System.out.println("End Working Hour: "+timeOUT+" "+dayTime2); System.out.println("Over Time Hours: "+preOT+" Hr."); System.out.println("Total Working Hours: "+totalHW+" Hr."); System.out.println("Commision: "+commision); System.out.println("Salary: "+totalSalary); System.out.println(); System.out.println("-------------------------------------------- "); System.out.println(); System.out.print("It took ["); System.out.print(System.currentTimeMillis()); //to display the t otal processing time System.out.println("] milliseconds of computing process to compl ete this data."); System.out.println(); System.out.println(); //?? //-------------------------------------------------------------- ---------// //below is the initialization of the complete output for the Fil eWriter //?? pw.println("--------------------------------------------"); pw.println(" || PAYROLL SLIP || "); pw.println("--------------------------------------------"); pw.println(); pw.println("Pay Rate: "+payRate+" /Hr."); pw.println("Over Time Rate: "+totalOT+" /Hr."); pw.println(); pw.println("--------------------------------------------"); pw.println(); pw.println("ID Number: "+accountNum); pw.println("Name: "+name); pw.println("Starting Working Hour: "+timeIN+" "+dayTime1); pw.println("End Working Hour: "+timeOUT+" "+dayTime2); pw.println("Over Time Hours: "+preOT+" Hr."); pw.println("Total Working Hours: "+totalHW+" Hr."); pw.println("Commision: "+commision); pw.println("Salary: "+totalSalary); pw.println(); pw.println("--------------------------------------------"); pw.println(); pw.println(); //?output tryAgain = JOptionPane.showConfirmDialog(null, "Would you like t o enter another account?"); //allows user to decide to input more information pw.close(); //closes the print function } while(tryAgain == JOptionPane.YES_OPTION); //determines if YES option is chosen to create the loop System.exit(0); //??end. } }