Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

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

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    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 {
    BufferedReader br = new BufferedReader (new FileReader ("emp_DTR.txt"));

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

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

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

    System.out.println("");
    System.out.println(" ********************************");
    line = br.readLine();
    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;
    }
    }

    Please help me


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hello, I'm a beginner and I really need help for my code..

    This is not the right place for questions.
    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.

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hello, I'm a beginner and I really need help for my code..

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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);

  8. #8
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hello, I'm a beginner and I really need help for my code..

    It said that the "<identifier> expected
    Please post the full text of the error message and the code.
    Wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Beginner - Where to put code to connect to database
    By newbiee in forum JDBC & Databases
    Replies: 1
    Last Post: May 17th, 2012, 05:40 AM
  2. Beginner having some trouble with two parts in my code
    By csprung in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2012, 04:23 AM
  3. Need Help with code ...beginner
    By Envious1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 19th, 2012, 08:52 AM
  4. (beginner) if else code.
    By dumb1101 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 16th, 2012, 02:47 AM
  5. Beginner - Help with my code.
    By eddross in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 12th, 2010, 09:30 AM