1 Attachment(s)
Computing Timein and Timeout To get Total hours
import java.io.*;
import java.text.*;
import java.util.StringTokenizer;
public class Payroll
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String empCode;
System.out.print("Enter Employee Code: "); //Get employee Code
empCode = br.readLine();
displayInformation(empCode); //Call the methode display Information
setLogged(empCode);
}
public static void displayInformation(String ecode)throws IOException
{
DecimalFormat df=new DecimalFormat("0.00");
FileInputStream fs = new FileInputStream("employee.txt");
BufferedInputStream bf = new BufferedInputStream(fs);
DataInputStream dis = new DataInputStream(bf);
String line; //Get the data per line
String tempEmployee="";
int noofrecords=5;
String[] code = new String[noofrecords]; //Array of records
String[] employee = new String[noofrecords];
String[] level = new String[noofrecords];
int x=0,find=0;
double salary;
StringTokenizer st1; //Get the data in the text file
while(x<noofrecords)
{
line = dis.readLine();
st1 = new StringTokenizer(line,","); //set comma as delimeter in the string
tempEmployee = st1.nextToken();
employee[x] = "";
for(int i=0;i<tempEmployee.length();i++)
{
if(tempEmployee.charAt(i)=='_') // if character is underscore change it into space
employee[x] = employee[x] + " "; // <----------- Space
else
employee[x] = employee[x] + tempEmployee.charAt(i);
}
code[x] = st1.nextToken();
level[x] = st1.nextToken();
x++;
}
for(int z=0;z<noofrecords;z++) //This will check if the code is equal to the value inputted
{
if(code[z].equals(ecode))
{
System.out.println("Employee Name: " + employee[z]);
System.out.println("Employee Name: " + code[z]);
System.out.println("Salary Level: Level " + level[z]);
if(level[z].equals("1")) //Check the level of the salary of the employee
salary=380;
else if(level[z].equals("2"))
salary=450;
else
salary=550;
System.out.println("Salary Rate: Php " + df.format(salary) + "/day");
find=1; //If find variable is equal to 1 then
//the statement inside the if statement below will not be executed;
}
}
if(find!=1)
System.out.println("Can't Find the Employee Number");
System.exit(0);
}
public static void setLogged(String empNo)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String week[]={"Monday","Tuesday","Wednesday","Thursday","Frida y"};
String data = "",timein,timeout,otin,otout,res;
FileOutputStream fo = new FileOutputStream("test.txt"); // This will write the data in the text file
for(int x=0;x<week.length;x++)
{
System.out.println("Enter the time-in for " + week[x] + ": ");
timein = br.readLine();
System.out.println("Enter the time-out for " + week[x] + ": ");
timeout = br.readLine();
System.out.println("Is " + week[x] + " a Holiday? ");
res = br.readLine();
System.out.println("Enter the overtime-in for " + week[x] + ": ");
otin = br.readLine();
System.out.println("Enter the overtime-out for " + week[x] + ": ");
otout = br.readLine();
data = data+ "," + timein + "," + timeout + "," +otin + "," + otout; //Collect the data from the user of the program
}
data = empNo + data;
for(int x=0;x<data.length();x++)
{
fo.write(data.charAt(x)); //Write the line of data inside the text file
}
}
}
Hello Experts,,
Please help to my program,, this program will input Timein, Timeout,Otin,Otout, and holiday,, in 5 Days(from Monday - Friday),,
my problem is i dont know how to compute the Timein and Timeout(ex. Monday timein: 8:30 and Monday Timeout: 17:30) i need the result of total hours is 9,, hope u can help me,,
Sorry for my bad english!!,, tnx in advance,,