Hello everyone,
I am pretty new to java and i have an assignment that to write the code for clock in and clock out for employee .Down here is my code, and now i am stuck with the while loop to print out the name, like if Bob work on Monday with several work session, it should display with the name Bob and Monday and the total hours on that day. Please help me.

import java.util.Scanner;
public class TimeClock
{
    public static void main(String [] args) {
       System.out.println("Employee Work Report :");
       System.out.println("Person "+ "    "  + "Day "+ "    "  + "Hours "+ "    "  +" WeekRegular "+ "    " +  "WeekOVT" );

          String name;
          String day;
          String timein;
          String timeout;
          // read in by Scanner
          Scanner input = new Scanner(System.in);
          name = input.next();
          day = input.next();
          timein = input.next();
          timeout = input.next();
          while(!input.equals("END")){


          String currentName = name;
          if (currentName.equals(name)){
          System.out.println(currentName);  

          }
           else 

              currentName = name;


          }

}

    public static int hour(String x)
    {
        int y = x.indexOf(":");
        String hour = x.substring(0,y);
        int hour1= Integer.valueOf(hour);
        return hour1;

    }

    public static int minute(String x)
    {
        int y = x.indexOf(":");
        String minute = x.substring(y+1,y+3);
        int minute1 = Integer.valueOf(minute);
        return minute1;

    }

    public static float thediff(int hour, int minute, int hour1, int minute1)
    {
        float diff = hour1 - hour;
        float theminute = minute1 - minute;
        float theminute1 = theminute / 60;
        if(theminute1 < 0){
            theminute1= (-1)*theminute1; 
        }
        return (diff + theminute1);

    }
}

well, I'm not sure what it is you are having trouble with, can you be a bit more specific?

anyway, look at the next two lines: can you see where you're going wrong there?

String currentName = name;
          if (currentName.equals(name)){

I am trying to get the name and the day, like
Bob Monday 10:30 12:30
Bob Monday 13:00 1:30
I try to get the name Bob the day is only Monday work 3:30 and something like that, i am stuck on that . For the code above , I tried to get the name which i read in and made it equal with the the current so i can compare it .

well, ok, but since you overwrite the name always ... you should re-think the logic of your code.
also: do you see the (quite obvious) flaw in your logic which I tried to point out?

This article has been dead for over six months. Start a new discussion instead.