I have five classes. 2 composition classes,1 aggregation class and 1 dependency class.I have coded all the classes but one of my test program is not giving me the expected result.I have the following classes:
TimeStamp
Interval (composition of 2 TimeStamps)
TimeSheet ( aggregation of many Interval)
Employee (composition of many TimeSheet)
FlexiEmployee (dependecy on Employee)
I have coded all the classes but when I run my test program for the Employee it does not give the details of the TimeSheet class.
Please give an insight of what I should do.
Thanks
Post your code. I have no idea why it's not working, I can't see it from here.
joeyg
January 18, 2011, 10:04am
3
Does this work for any employees?
Hard to provide programming guidance when you only speak in generalities. Please show some example data and your programming.
[public class TimeStamp
{
private int day;
private int minutes;
public TimeStamp()
{
day = 0;
minutes = 0;
}
public TimeStamp(int day,int minutes)
{
this.day = day;
this.minutes = minutes;
}
public void setDay(int day)
{
this.day = day;
}
public void setMinutes(int minutes)
{
this.minutes = minutes;
}
public int getDay()
{
return day;
}
public int getMinute()
{
return minutes;
}
public String toString()
{
return ":- " + "Day: " + day + " Minutes: " + minutes;
}]
[public class Interval
{
private TimeStamp clockIn;
private TimeStamp clockOut;
private int daysWorked;
public Interval()
{
clockIn = new TimeStamp();
clockOut = new TimeStamp();
daysWorked = 0;
}
public Interval(TimeStamp clockIn,TimeStamp clockOut,int daysWorked)
{
this.clockIn = clockIn;
this.clockOut = clockOut;
this.daysWorked = daysWorked;
}
public void setClockIn(TimeStamp clockIn)
{
this.clockIn = clockIn;
}
public void setClockOut(TimeStamp clockOut)
{
this.clockOut = clockOut;
}
public void setDaysWorked(int daysWorked)
{
this.daysWorked = daysWorked;
}
public TimeStamp getClockIn()
{
return clockIn;
}public TimeStamp getClockOut()
{
return clockOut;
}
/** Returns the number of days worked */
public int getDaysWorked()
{
return daysWorked;
}
public int getDuration()
{
return clockOut.getMinute() - clockIn.getMinute();
}
public String toString()
{
return "Interval: " + " ClockIn " + clockIn +","+ " ClockOut " + clockOut + " Duration: " + getDuration()
+ " DaysWorked " + daysWorked;
}
}]
[public class IntervalTest
{
public static void main(String[] args)
{
Interval I = new Interval();
I.setTimeStampIn(new TimeStamp(10,100));
I.setTimeStampOut(new TimeStamp(10,250));
System.out.println(I.toString());
System.out.println("ClockInTime is " + I.getclockIn().getminute() + "mins");
System.out.println("ClockOutTime is " + I.getclockOut().getminute() + "mins");
System.out.println("Duration is " + I.getDuration() + "mins");
System.out.println();
}
}]
[public class TimeSheet implements Iterable<Interval>
{
private ArrayList<Interval>intervalList;
private String name;
public TimeSheet()
{
intervalList = new ArrayList<Interval>();
name = "-";
}
public TimeSheet(String name)
{
intervalList = new ArrayList<Interval>();
this.name = name;
}
public void ClearInterval()
{
intervalList.clear();
}public void addInterval(Interval L)
{
intervalList.add(L);
}
public void setName(String name)
{
this.name = name;
}
@Override
public Iterator<Interval> iterator()
{
return intervalList.iterator();
}
public int getNumberOfInterval()
{
return intervalList.size();
}
public String getName()
{
return name;
}
public int getNumberOfDays()
{
int numberOfDays = 0;
for (Interval L : intervalList)
{
numberOfDays = numberOfDays + L.getDaysWorked();
}
return numberOfDays;
}
public String toString()
{
String L = "TimeSheet:"+ this.name +"\n";
for (int i = 0; i < intervalList.size(); i++)
{
L = L + i + "\t" + intervalList.get(i).toString() + "\n";
}
return L;
}
}]
[import java.util.ArrayList;
public class TimeSheetTest
{
public static void main(String[] args)
{
TimeSheet timesheet = new TimeSheet();
ArrayList<Interval> L = new ArrayList<Interval>();
timesheet.addInterval( new Interval(new TimeStamp(10,210),new TimeStamp(10,360), 12));
timesheet.addInterval( new Interval(new TimeStamp(30,150),new TimeStamp(30,960), 20));
System.out.println();
System.out.println(timesheet.toString());
}
}]
[public class Employee
{
private String ID;
private int payPerHour;
private int minutesWorked;
private TimeSheet timeSheet;
public Employee()
{
ID = "-";
payPerHour = 0;
minutesWorked = 0;
timeSheet = new TimeSheet();
}
public Employee(String ID,int payPerHour,int minutesWorked,TimeSheet timeSheet)
{
this.ID = ID;
this.payPerHour = payPerHour;
this.minutesWorked = minutesWorked;
this.timeSheet = timeSheet;
}
public void setId(String ID)
{
this.ID = ID;
}
public void setPayperHour(int payPerHour)
{
this.payPerHour = payPerHour;
}
public void setMinutesworked(int minutesWorked)
{
this.minutesWorked = minutesWorked;
}
public void setTimesheet(TimeSheet timeSheet)
{
this.timeSheet = timeSheet;
}
public void resetMinutesWorked(int minutesWorked)
{
this.resetMinutesWorked(0);
}
public void processtimeSheet()
{
this.processtimeSheet();
}
public int getpay()
{
return payPerHour * minutesWorked;
}
public String getid()
{
return ID;
}
public int getMinutesworked()
{
return minutesWorked;
}
public int getPayperhour()
{
return payPerHour;
}
public TimeSheet getTimesheet()
{
return timeSheet;
}
public String toString()
{
return "Employee: " + ID + " PayPerHour: " + payPerHour + " MinutesWorked: " + minutesWorked +
" TimeSheet: " + timeSheet + " DailyPay: " + getpay();
}
}]
[public class EmployeeTest
{
public static void main(String[] args)
{
Employee E = new Employee();
System.out.println(E.toString());
}
}]
those are the codes I've written so far