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 5 of 5

Thread: Im a java beginner and I need help :|

  1. #1
    Junior Member javaDO's Avatar
    Join Date
    Jul 2012
    Location
    Philippines
    Posts
    1
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Im a java beginner and I need help :|

    Guyss can u help to my program??
    this is the instructions:

    DTR or Daily Time Record is a form which details each employee's total hours of work daily at the time of arrival and departure from office in the morning and in the afternoon.Employees must report on duty at exactly 08:00 AM in the morning until 12:00 NN. And in the afternoon, they must time-in at exactly 13:00 (1:00PM) until 17:00 (5:00PM).

    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.

    Create the following methods that will help you solve the tasks:
    1. A method to calculate the number of hours worked from time in until time out in hours and minutes.
    2. A method to display your output

    You can also create additional methods such as:
    1. Methods used to read the contents of the text file

    Here is the text from notepad:


    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


    Here is a sample output:

    ----------------------------------------------------------------
    EMPLOYEE’s Daily Time Record
    Day: Monday, July 4, 2011
    -----------------------------------------------------------------
    EmployeeID : 2006-0031
    Lastname : SULLIVAN
    Firstname : Jamie
    Position : Worker
    Rank : 2

    Morning
    IN : 08:00
    OUT : 12:00
    Afternoon
    IN : 13:00
    OUT : 17:00
    Total hours worked: 8 hrs and 0 mins
    -----------------------------------------------------------------


    This is my work guys.. plss hel mee



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

    public class EmployeeDTR{
    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("Employer's Daily Time Record");
    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())

    {
    System.out.println(st.nextToken() + " ");
    }

    System.out.println("\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;
    StringTokenizer st = new StringTokenizer(list,"*_");

    EmployeeID = st.nextToken();
    FirstName = st.nextToken();
    LastName = 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("Employee ID: " + EmployeeID);
    System.out.println("Last Name : " + lastName);
    System.out.println("First Name : " + FirstName);
    System.out.println("Position : " + position);
    System.out.println("Rank : " + rank);
    System.out.println("\nMorning");
    System.out.println("\t IN: " + AM_In);
    System.out.println("\tOUT: " + AM_Out);
    System.out.println("\nAfternoon");
    System.out.println("\t IN: " + PM_In);
    System.out.println("\tOUT: " + PM_Out);



    daily_hours_work( AM_In,AM_Out,PM_In,PM_Out);
    System.out.println("-----------------------------------------------------------------------------");
    }

    //-------------------------------total hours worked---------------------------
    public static void daily_hours_work(String AM_In,AM_Out,PM_In,PM_Out)
    {

    StringTokenizer HoursIn_amToken = new StringTokenizer(AM_In,":");
    int Hours_AM_In = Integer.parseInt(HoursIn_amToken.nextToken());
    int Minutes_AM_In = Integer.parseInt(HoursIn_amToken.nextToken());

    StringTokenizer MinutesOut_amToken = new StringTokenizer(AM_Out,":");
    int Hours_AM_Out = Integer.parseInt(MinutesOut_amToken.nextToken());
    int Minutes_AM_Out = Integer.parseInt(MinutesOut_amToken.nextToken());

    StringTokenizer HoursIn_pmToken = new StringTokenizer(PM_In,":");
    int Hours_PM_in = Integer.parseInt(HoursIn_pmToken.nextToken());
    int Minutes_PM_in = Integer.parseInt(HoursIn_pmToken.nextToken());

    StringTokenizer MinutesIn_pmToken = new StringTokenizer(PM_Out,":");
    int Hours_PM_out = Integer.parseInt(HoursIn_pmToken.nextToken());
    int Minutes_PM_out = Integer.parseInt(HoursIn_pmToken.nextToken());

    int Total_AM_Hours = Hours_AM_Out - Hours_AM_In; //calculate the subtotal morning hrs
    int total_AM_Minutes = Minutes_AM_Out + Minutes_AM_In; //calculate the subtotal morning mins

    int Total_PM_Hours = Hours_PM_out - Hours_PM_in; //calculate the subtotal afternoon hrs
    int Total_PM_Minutes = Minutes_PM_out + Minutes_PM_in; //calculate the subtotal afternoon mins

    int TotalHours = Total_AM_Hours + Total_PM_Hours; //calculate the total
    int TotalMinutes = total_AM_Minutes + Total_PM_Minutes;


    System.out.println("nTotal hours worked:" + TotalHours + " hrs and " + TotalMinutes + " mins");
    System.out.println("-----------------------------------------------------------------------------");
    }
    }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Im a java beginner and I need help :|

    This is my work guys.. plss hel mee
    Getting help is best done when you ask a question, or state exactly what the problem is. Does it compile? Are there exceptions? Does it misbehave (if so, what do you expect and what do you get)? And please read the forum guidelines, which explain how to wrap your code in the code tags to preserve formatting

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Im a java beginner and I need help :|

    Read the forum rules. Posting duplicate posts is not allowed, and neither is posting photos that can be considered profane - this is a technical forum, treat it that way. Your other post has been deleted. Take this as a first warning, and there won't be a second one.

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Im a java beginner and I need help :|

    Quote Originally Posted by copeg View Post
    Does it compile? Are there exceptions? Does it misbehave (if so, what do you expect and what do you get)?
    I second copeg's questions. We really need a *description* of the problem to be able to help.

    And the place for a description (and the help it might result in) is here in the forum, rather than PMing individuals. I don't say this to be heavy handed about "rules", but just because I think the public forums are the most effective way of getting help.

    I look forward to seeing your answer's to copeg's questions!

  5. #5
    Junior Member ShadeDarkan's Avatar
    Join Date
    Jul 2012
    Location
    Houston, TX
    Posts
    13
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default Re: Im a java beginner and I need help :|

    Other than having to fix your Am and Pm variables in the EmployeeProfile function, the problem seems to all be in the daily_hours_work function. That's where my IDE kept pointing to for noSuchElement exceptions in the StringTokenizer.
    If I comment out the call to daily_hours_work the program runs as expected, minus the total hours and minutes worked for the day.

Similar Threads

  1. Beginner in java, looking for all the help I can get
    By Travis.Nichols777 in forum Member Introductions
    Replies: 2
    Last Post: February 26th, 2012, 06:31 AM
  2. Java Beginner
    By kney in forum Java Theory & Questions
    Replies: 10
    Last Post: October 18th, 2011, 06:38 AM
  3. Another beginner to Java!
    By jwise95 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 21st, 2011, 04:27 PM
  4. Java Beginner Here!
    By j3nn42o in forum The Cafe
    Replies: 10
    Last Post: January 10th, 2011, 03:57 AM
  5. Java Beginner
    By rannoune in forum Java Theory & Questions
    Replies: 3
    Last Post: December 25th, 2009, 02:30 AM

Tags for this Thread