kiad_198's Profile
Reputation: 3
Apprentice
- Group:
- Active Members
- Active Posts:
- 107 (0.07 per day)
- Joined:
- 19-November 08
- Profile Views:
- 4,740
- Last Active:
Dec 08 2012 01:05 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Latest Visitors
-
modi123_1 
30 Sep 2012 - 09:36 -
n00l3 
04 Sep 2011 - 19:57 -
deVirus 
30 Dec 2010 - 19:36 -
macosxnerd101 
28 Dec 2010 - 13:50 -
Salem_c 
25 Aug 2010 - 10:50
Posts I've Made
-
In Topic: How to select data in a row of text file?
Posted 5 Aug 2012
Thank you for the reply guys,
Above all thanks God Its working now...
- kiad - -
In Topic: How to select data in a row of text file?
Posted 5 Aug 2012
hehehe... Yes, but I'm no good to String.split at this moment.
Here's another version of the code, the same aim:
import java.text.DateFormat; import java.text.DecimalFormat; import java.io.*; import java.util.*; public class sample{ public static void main(String args[]) { String Filename = "EmployeeDTR.txt"; try { FileReader fr = new FileReader(Filename); BufferedReader br = new BufferedReader(fr); String list = br.readLine(); System.out.println("\n\t\t\tEmployer's Daily Time Record \n"); date(list); while(list !=null) { list = br.readLine(); EmployeeProfile(list); } fr.close(); } catch(IOException e) { System.out.println("Problem Reading File: " + Filename); } } //---------------------get the date--------------------------------- public static void date(String list) { StringTokenizer st = new StringTokenizer(list,""); while(st.hasMoreTokens()) { final String[] in = {"\t\t\t " + st.nextToken()+ " \n" }; for ( final String s : in ) { System.out.println( s.replaceAll ( "\\*(\\B)/>","$1 " ) ); } System.out.println("-----------------------------------------------------------------------------\n\n"); } } // -----------------get the employee profile------------------------- public static void EmployeeProfile(String list) { String EmployeeID,FirstName,LastName,position,rank,Am_In, Am_Out,Pm_In,Pm_Out,ranks ; double rank1 = 26 * 380.00; double rank2 = 26 * 450.00; double rank3 = 26 * 550.00; double tsalary=0.0; StringTokenizer st = new StringTokenizer(list,"*_"); FirstName = st.nextToken(); LastName = st.nextToken(); EmployeeID = st.nextToken(); position = st.nextToken(); rank = st.nextToken(); Am_In = st.nextToken(); //08:00 Am_Out = st.nextToken();//12:00 Pm_In = st.nextToken(); Pm_Out = st.nextToken(); System.out.println("\n\tEmployee ID: " + EmployeeID); System.out.println("\tLast Name : " + LastName); System.out.println("\tFirst Name : " + FirstName); System.out.println("\tPosition : " + position); System.out.println("\tRank : " + rank); if( rank == "1"){ tsalary = rank1; }else if (rank == "2"){ tsalary = rank2; }else if (rank == "3"){ tsalary = rank3; } System.out.println("\tRate : " + tsalary); System.out.println("\n\tMorning"); System.out.println("\t IN : " + Am_In); System.out.println("\t OUT : " + Am_Out); System.out.println("\n\tAfternoon"); System.out.println("\t IN : " + Pm_In); System.out.println("\t OUT : " + Pm_Out); int TotalHours=0; int TotalMinutes=0; System.out.println("\n\t Total hours worked: " + TotalHours + " hrs and " + TotalMinutes + " mins \n"); System.out.println("-----------------------------------------------------------------------------"); } }
Ouput :


This kinda bit working. In the next phase of this, I've using IF Statement to identify the ranking of each employee then display their corresponding salary calculation. You could see in this code.
Quote
if( rank == "1"){
tsalary = rank1;
}else if (rank == "2"){
tsalary = rank2;
}else if (rank == "3"){
tsalary = rank3;
}
It seems that nothing happen in tsalary. As you can see in the output the rate of employee is 0.00. I think the initial got display not the IF Statement. I also plan to use IF Statement in calculating the time in Hours and Minutes.
1. How can I make the IF Statement working?
2. Any insight of time calculation in this program?
3. In the output, their is an error displaying the last statement. How can I fix it?
Question 1 & 2 are urgent. 3 is optional.
Please share your ideas.
Very much appreciated all the reply.
Thanks...
- kiad - -
In Topic: How to select data in a row of text file?
Posted 5 Aug 2012
-
In Topic: How to select data in a row of text file?
Posted 5 Aug 2012
smohd, on 05 August 2012 - 02:34 AM, said:You need to know in what index you are in for you here. So you have to append the text by yourself. That means, if I used split I will use retured array and say:
"Employee ID: " + arr[2]....
and so. Which means you have to know which token has been returned now by either having an index and an if condition or like
hehehe, I'm not good array.
StringTokenizer st = new StringTokenizer(contents.toString(),"*_"); while (st.hasMoreTokens()) { System.out.println(st.nextToken() + ""); } System.out.println("\n--------");
Where can put an array on this code? or do you have a link so I can learn?
In your splitting code, how did you do that?
Thank you sir smohd... -
In Topic: How to select data in a row of text file?
Posted 5 Aug 2012
smohd, on 05 August 2012 - 01:31 AM, said:After reading each line, you have to use split to divide your line into different segments. So there according to your file, you will have to split using "*" because is the differentiating data.
Then you can use the returned array to display the output which you need.
Look on how to use split here and here
Yes, I Split it this way:
StringTokenizer st = new StringTokenizer(contents.toString(),"*_"); while (st.hasMoreTokens()) { System.out.println(st.nextToken() + ""); } System.out.println("\n--------");
The output looks like this:
Quote
Day:
Monday,
July 4, 2011
Jamie
SULLIVAN
2006-0031
Worker
2
...
But How can I assign like the output in the top post?
Is their a way I can set a variable in each column?
I think looping is good in it but I'm no good.
Very much appreciated!
Thanks
- kiad -
My Information
- Member Title:
- D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
kiad_198 hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
kiad_198 has no profile comments yet. Why not say hello?