# Hello, I'm a beginner and I really need help for my code..

• August 4th, 2012, 06:58 AM
aimEhjO
Hello, I'm a beginner and I really need help for my code..
here's my code. but I'm having a problem with how to calculate the RATE and the TOTAL HOURS of WORKED.
And there's more, calculate the 24 hours into 12 hours.
The problem is here. :-s

Create a program that will read the employee’s DTR from the textfile named EmployeeDTR.txt. Extract the contents of the textfile and calculate the number of hours work for each employee. Display the employee’s number of hours worked in hours in minutes. Display also the date of the DTR. Use military time format. Disregard the late & early in or out.

Rank Salary Rate/day
1 Php 380.00
2 Php 450.00
3 Php 550.00
To get the Monthly Salary Rate of an employee, multiply the employee’s Salary Rate/day by 26 (number of working days in a month). Use the DecimalFormat class to format employee’s Monthly Salary Rate.

import java.io.*;
import java.util.*;

public class Employee_DTR {
public static void main (String [] args) throws IOException {

System.out.println(" EMPLOYEE's Daily Time Record");
System.out.println("");
String in;
in = textF(line);
System.out.println("");
System.out.println("");

System.out.println(" ********************************");
in = text(line);

System.out.println("");
System.out.println(" ********************************");
in = text(line);

System.out.println("");
System.out.println(" ********************************");
in = text(line);

System.out.println("");
System.out.println(" ********************************");
System.out.println("");
}

public static String textF (String p) {
String in2 = null;
StringTokenizer st = new StringTokenizer (p , "*");
do{
String date = st.nextToken();
System.out.print(" " + date);
}
while (st.hasMoreTokens());
return in2;
}

public static String text (String t) {
String in = null;
StringTokenizer st = new StringTokenizer (t, "*_");

System.out.println("");
String lname = st.nextToken();
System.out.println(" Lastname : " + lname);

while(st.hasMoreTokens()) {
String fname = st.nextToken();
System.out.println(" Firstname : " + fname);

String ID = st.nextToken();
System.out.println(" EmployeeID : " + ID);

String pos = st.nextToken();
System.out.println(" Position : " + pos);

String rank = st.nextToken();
System.out.println(" Rank : " + rank);

System.out.println(" Rate : ");
System.out.println("");

System.out.println(" Morning");

String in_am = st.nextToken();
System.out.println(" IN : " + in_am);

String out_am = st.nextToken();
System.out.println(" OUT : " + out_am);

System.out.println("");
System.out.println(" Afternoon");

String in_pm = st.nextToken();
System.out.println(" IN : " + in_pm);

String out_pm = st.nextToken();
System.out.println(" OUT : " + out_pm);

System.out.println("");
System.out.println(" Total hours worked: ");
}
return in;
}
}

• August 4th, 2012, 07:13 AM
Norm
Re: Hello, I'm a beginner and I really need help for my code..
This is not the right place for questions.
Quote:

The problem is here.
Can you explain what your problems are? You have posted what looks like an assignment but have not asked any questions about the problems you are having.

[code=java]
[/code]
to get highlighting and preserve formatting.
• August 4th, 2012, 07:24 AM
aimEhjO
Re: Hello, I'm a beginner and I really need help for my code..
How to calculate the rate and where should i put it in the code?
should i create another method for the total hours of worked?

here's the output:

EmployeeID : 2006-0031
Lastname : SULLIVAN
Firstname : Jamie
Position : Worker
Rank : 2
Rate : Php 11,700.00

Morning
IN : 08:00
OUT : 12:00
Afternoon
IN : 13:00
OUT : 17:00
Total hours worked: 8 hrs and 0 mins
• August 4th, 2012, 07:28 AM
Norm
Re: Hello, I'm a beginner and I really need help for my code..
Does the assignment give a formula or hints for calculating the rate?

When you get the formula for the calculation, it should go in the code after where all the values needed for the calculation have been read into the program.

What does the input for the program look like?
• August 4th, 2012, 07:35 AM
aimEhjO
Re: Hello, I'm a beginner and I really need help for my code..
only this:

Rank Salary Rate/day
1 ---- Php 380.00
2 ---- Php 450.00
3 ---- Php 550.00
To get the Monthly Salary Rate of an employee, multiply the employee’s Salary Rate/day by 26 (number of working days in a month). Use the DecimalFormat class to format employee’s Monthly Salary Rate.
• August 4th, 2012, 07:41 AM
Norm
Re: Hello, I'm a beginner and I really need help for my code..
Quote:

To get the Monthly Salary Rate of an employee, multiply the employee’s Salary Rate/day by 26 (number of working days in a month).
Can you make a formula from that?

Where do you get the salary rate from? What is in the EmployeeDTR.txt file?
Define what is one each line of the file.
• August 4th, 2012, 07:51 AM
aimEhjO
Re: Hello, I'm a beginner and I really need help for my code..
The salar rate is given from the problem.
and the "EmployeeDTR.txt" is from the another file, it used a notepad. The content of this file is this:

Day:*Monday,*July 4, 2011
Jamie_SULLIVAN*2006-0031*Worker*2*08:00*12:00*13:00*17:00
John_SMITH*2001-0001*Manager*3*07:46*12:00*12:30*17:10
Tim_JONES*2010-0008*Worker*1*08:01*11:55*13:00*16:55

im trying to calculate it like this way:

//the first, second and third are base on the rank
int first = 380 * 26;
int second = 450 * 26;
int third = 550 * 26;

if(rank == 1) {
System.out.println(" Rate : " + first);
}
else if(rank == 2){
System.out.println(" Rate : " + second);
}
else if(rank == 3){
System.out.println(" Rate : " + third);
• August 4th, 2012, 07:53 AM
aimEhjO
Re: Hello, I'm a beginner and I really need help for my code..
but the salary rate is not given at the "EmployeeDTR.txt" so I need to adjust and add the salary rate in the .txt file.
• August 4th, 2012, 08:52 AM
Norm
Re: Hello, I'm a beginner and I really need help for my code..
Can you define what is on each line in the "EmployeeDTR.txt" file?
It looks like the items are separated by "*"s
and that the first item is a name.
What are the rest of the items?

What are you supposed to do with the data that is read in from the file?
• August 4th, 2012, 09:15 AM
aimEhjO
Re: Hello, I'm a beginner and I really need help for my code..
yes. it is separated by * that's why i used StringTokenizer to concat the "*" and call the variable for the output.
anyways, i already got the rate but i got a new problem again.
I used "public static String total (String in_am,out_pm,in_pm,out_pm)" for calculating the hours and minutes.
I converted the String into integer so that I can calculate it.
It said that the "<identifier> expected" . what that supposed to be mean?
• August 4th, 2012, 09:22 AM
Norm
Re: Hello, I'm a beginner and I really need help for my code..
Quote:

It said that the "<identifier> expected
Please post the full text of the error message and the code.