473,465 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Hi , can you help me to make a main method (test method ) for this application ?

4 New Member
/**
* Maintain the appointments for one day in a diary.*/



public class Day
{
// The first and final bookable hours in a day.
public static final int START_OF_DAY = 9;
public static final int FINAL_APPOINTMENT_TIME = 17;
// The number of bookable hours in a day.
public static final int MAX_APPOINTMENTS_PER_DAY =
FINAL_APPOINTMENT_TIME -
START_OF_DAY + 1;
// A day number within a particular year. (1-366)
private int dayNumber;
// The current list of appointments for this day.
private Appointment[] appointments;
/**
* Constructor for objects of class Day.
* @param dayNumber The number of this day in the year (1-366).
*/
public Day(int dayNumber)
{
this.dayNumber = dayNumber;
appointments = new Appointment[MAX_APPOINTMENTS_PER_DAY];
}
/**
* Try to find space for an appointment.
* @param appointment The appointment to be accommodated.
* @return The earliest time today that can accommodate
* the appointment. Return -1 if there is
* insufficient space.
*/
public int findSpace(Appointment appointment)
{
int duration = appointment.getDuration();
for(int slot = 0; slot < MAX_APPOINTMENTS_PER_DAY; slot++) {
if(appointments[slot] == null) {
final int time = START_OF_DAY + slot;
// Potential start point.
if(duration == 1) {
// Only a single slot needed.
return time;
}
else {
// How many more slots are needed?
int further_slots_required = duration - 1;
for(int nextSlot = slot + 1;
further_slots_required > 0 &&
appointments[nextSlot] == null;
nextSlot++) {
further_slots_required--;
}
if(further_slots_required == 0) {
// A big enough space has been found.
return time;
}
}
}
}
// Not enough space available.
return -1;
}
/**
* Make an appointment.
* @param time The hour at which the appointment starts.
* @param appointment The appointment to be made.
* @return true if the appointment was successful,
* false otherwise.
*/
public boolean makeAppointment(int time,Appointment appointment)
{
if(time >= START_OF_DAY && time <= FINAL_APPOINTMENT_TIME)
{ int startTime = time-START_OF_DAY;
if(appointments[startTime] == null)
{ int duration = appointment.getDuration();
// Fill in all the slots for the full duration
// of the appointment.
for(int i = 0; i < duration; i++)
{ appointments[startTime + i] = appointment; }
return true;
}
else{
return false;}
}
else{
return false;}
}


/**
* Print a list of the day's appointments on standard output.
*/
public void showAppointments()
{ System.out.println("=== Day " + dayNumber + " ===");
for(int i = 0; i < MAX_APPOINTMENTS_PER_DAY; i++)
{ System.out.print ((START_OF_DAY + i) + ": ");
if(appointments[i] != null)
{ System.out.println(appointments[i].getDescription());}
else {System.out.println();}
}
}


/**
* @return The number of this day within the year (1 - 366).
*/
public int getDayNumber()
{
return dayNumber;
}
}
Jun 10 '10 #1
2 1236
jkmyoung
2,057 Recognized Expert Top Contributor
What do you want the main function to do? Do you have a numbered list of steps that it should take?
Jun 10 '10 #2
ThatThatGuy
449 Recognized Expert Contributor
@electrical
So you got the answer!!
Jun 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bill Davy | last post by:
I am building a C++ program (main.exe) with VC6 which expects to call the Python DLL. When I start it (under the debugger), I get: "This application has failed to start because python24_d.dll was...
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
0
by: Zubair.NET! | last post by:
Hi, I have an ASP.NET application for which I am storing the application name in the database such as <add key="WebsiteRootAddress" value="http://localhost/MyApplicationName" /> and
1
by: Dhruba Bandopadhyay | last post by:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm....
2
by: muzilli | last post by:
Hi, I'm developing an application for Smart Device Application and I'm creating Threads. In determinated time the thread must be stoped. I was searching for the help about the Threads and I...
6
by: trimba | last post by:
Hi guys, Have you created an application that provide Automated test for Access application. What I mean from the Automated test is The Access Form will be open, all text fields will be populated,...
5
by: =?Utf-8?B?U3JpbWFu?= | last post by:
Hi, We are launching .net window from vb6 form. In .net form tabbing(tab out from one control to another control) was not working. for that i have written a code like Sendkeys.send("{TAB}") in the...
0
by: jbvbprgrmr | last post by:
Is it possible to call a .NET shared class method from a VB6 application? I created a small test project consisting of a .NET class library containing the following class: Public Class MyTest...
2
by: Selva123 | last post by:
Hi All, Greetings. I want to test JAVA SWING application with PERL, do we have any module to do so (like win32::GUI for windows)?. or some third party free tools integrated with PERL? I am...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.