Test program not giving expected result


 
Thread Tools Search this Thread
Top Forums Programming Test program not giving expected result
# 1  
Old 01-18-2011
Test program not giving expected result

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
# 2  
Old 01-18-2011
Post your code. I have no idea why it's not working, I can't see it from here.
# 3  
Old 01-18-2011
Need details

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.
# 4  
Old 01-18-2011
Code:
[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

Last edited by Scott; 01-18-2011 at 12:48 PM.. Reason: Code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

awk not giving the output expected

Hello, I am practising awk and decided to compare two columns and print the result of the comparison as third column i/p data c1,c2,c3 1,a,b 1,b,b i am trying to compare the last two columns and if they match I am trying to print match else mismatch(Ideally i want that as a last column... (5 Replies)
Discussion started by: mkathi
5 Replies

3. Shell Programming and Scripting

Not getting expected result

Hi Experts, I have written the below script but its not working as per expectation. My requirement is if this condition ] is satisfied then only check for this condition ] if this also satisfied check for the condition ]. vi p_values.ksh path="/db/ora/files" mode=1 b_days=10... (5 Replies)
Discussion started by: nalu
5 Replies

4. Shell Programming and Scripting

For loop not giving expected output

#cat /tmp/input old_array old_dev new_dev new_array 0577 008AB 01744 0125 0577 008AC 01745 0125 0577 008AD 005C8 0125 0577 008AE 005C9 0125 0577 008AF 005CA 0125 0577 008B0 005CB 0125 0577 008B1 005CC 0125 cat test.sh #!/bin/ksh... (4 Replies)
Discussion started by: mbak
4 Replies

5. UNIX for Dummies Questions & Answers

Grep not giving expected results

Version: RHEL 5.8 I am doing a grep of the piped output from ps command as shown below. I am grepping for the pattern ora_dbw* . But, in the result set I am seeing strings with ora_dbr* as well like ora_dbrm_SDLM1DAS3 as shown below. Any idea why is this happening ? $ ps -ef | grep... (6 Replies)
Discussion started by: John K
6 Replies

6. Shell Programming and Scripting

AWK Looping. How can I get expected result?

Can Anyone help with looping... awk 'FNR==1{i++} {for(k=1; k<=NF; k++) A=$k} # 3 Dimension Array END{ for(i=1;i<=217;i++) # For loop 2nd File 1st and 2nd column x=0;y=0 ... (18 Replies)
Discussion started by: Akshay Hegde
18 Replies

7. Shell Programming and Scripting

Monitoring Sript giving random end result

Hi Guys, I am developing a script to monitor GUI based FileNet Component "Component Manager" which logs it's running status in a log file. Log file is a huge file so in script I put last 300 lines of log file in seperate file and run script every 5 minutes. I am searching the string... (2 Replies)
Discussion started by: dhirajdsharma
2 Replies

8. AIX

errpt not giving a result

my system get rebooted by its self after its came up i try to check the error log P690/>errpt | more Cannot open error message catalog /usr/lib/nls/msg/en_US/codepoint.cat. The error report will still run, but it will not have explanatory messages P690/>ls -lrt... (1 Reply)
Discussion started by: thecobra151
1 Replies

9. Shell Programming and Scripting

My script is not giving result for 2 or more arguments

Hi, I am new to shell scripting and my below script is not giving result for 2 or more arguments. Can anyone help pls. #!/bin/sh sname=$(basename $(readlink -nf $0)) echo "This is $sname, running at $(date)" echo "It is running on $(hostname)" echo "Script being run by" echo " User... (3 Replies)
Discussion started by: baigmd
3 Replies

10. UNIX for Dummies Questions & Answers

Script giving different result on Linux compared to Unix

Hi I have a script executing fine in Unix but in linux I am getting different result. I have three files under /local/home/temp/Gen test.sh list.txt shst.txt Contents of test.sh -------------------------- #!/bin/ksh K=0; SCRIPT_DIR=/local/home/temp/Gen cat... (2 Replies)
Discussion started by: malavm
2 Replies
Login or Register to Ask a Question