Click to See Complete Forum and Search --> : Alarm class


Aristo
12-03-2005, 01:38 PM
I have a class called AlarmClock class. The specification of my design was to create another class that works with the AlarmClock class called ALARM CLASS that uses methods from AlarmClock class without changing AlarmClock class (that stores the time alarm is set to, and that time can be changed......)
DON'T KNOW ANY MORE REALLY CONFUSED, HAVE TRIED EVERYTHING, really need help here

AlarmClock Class code below
Code:

public class AlarmClock
{
private ClockDisplay clock;
private Alarm alarm;

public AlarmClock()
{
clock = new ClockDisplay();
alarm = new Alarm();
}


public AlarmClock(int hour, int minute)
{
clock = new ClockDisplay(hour,minute);
alarm = new Alarm();
}


public void setAlarm(int hour, int minute)
{
alarm.setWakeUpTime(hour,minute);
}

public String getAlarm()
{
return alarm.getWakeUpTime();
}


public void timeTick()
{
clock.timeTick();
String time = getTime();
boolean wakeUp = alarm.check(time);
if(wakeUp)
{
System.out.println("It is " + time + " - RING RING");
}
else
{
System.out.println("ZZZZZ");
}
}


public void setTime(int hour, int minute)
{
clock.setTime(hour,minute);
}


public String getTime()
{
return clock.getTime();
}

}




What I have done sofar

public class Alarm
{
private int hour;
private int minute;

public Alarm()
{
hour = 12;
minute = 30;
}


public void setWakeUpTime(int hour,int minute)
{
hour.setWakeupTime(hour);
minute.setWakeupTime(minute);
}

public void changeWakeUpTime(int hour, int minute)
{
changeWakeUpTime = setWakeUpTime;
}



}

nspils
12-03-2005, 07:59 PM
To allow an instance of your Alarm class to have access to its very own AlarmClock, you need to have an object of class AlarmClock as a member of your Alarm class. (Your Alarm class "has a" AlarmClock.) Therefore, declare a private member of your class as

private AlarmClock myClock;

and, initialize that instance in your Alarm constructor

public Alarm()
{
myClock = new AlarmClock();
etc.
}

now, you can call upon myClock to execute the PUBLIC methods of the AlarmClock class for your Alarm class. by calling

myClock.setAlarmTime( Time ),

and so on.

Aristo
12-04-2005, 09:46 AM
Thanks for the help... this might seem like a stupid question, I am pretty new to Java, how am I going to set the time? because from your example, you have just one parameter object on the method (Time)......is that not surpose to be 2? that is hours and minutes???
Thanks for your anticipated help.

nspils
12-04-2005, 11:41 AM
I just used Time as a short hand or pseudocode for your class's parameters - rather than reading back to your message to write the code for you. You have the methods, you know the parameters for doing their work. It's up to you to use them.

Aristo
12-04-2005, 12:38 PM
Thanks....but I tried this coding below......but when I try to compile, it gives me an error saying cannot find symbol-method setWakeUpTime(int,int)

CONFUSED :confused:

public class Alarm
{
private AlarmClock alarmTime;


public Alarm()
{
alarmTime = new AlarmClock();
}

public void setAlarmTime(int hour, int minute)
{
alarmTime.setAlarmTime(hour,minute);
}

}

nspils
12-04-2005, 09:58 PM
I am confused about your code, too.

Your "setWakeupTime()" method is in the Alarm class. Take a look at it - you declare setWakeupTime to have two parameters, but then in the body of the method you call itself but this time with only one parameter - and I do not see a signature like that in the code you have provided.

Can you write, in short english phrases, how you expect your AlarmClock and Alarm to work? Where is your method main()? How are you making calls to AlarmClock or Alarm from outside these two classes?

Aristo
12-05-2005, 11:07 AM
OK....basically what I am trying to do is creat another class called Alarm class that works with AlarmClock Class That does two things using methods from AlarmClock Class(1) Contains a time that the alarm is set to (2) That time can be changed., without any changes to the code of the AlarmClock class....

BELOW THE CODE OF THE ALARMCLOCK CLASS

public class AlarmClock
{
private ClockDisplay clock;
private Alarm alarm;

public AlarmClock()
{
clock = new ClockDisplay();
alarm = new Alarm();
}


public AlarmClock(int hour, int minute)
{
clock = new ClockDisplay(hour,minute);
alarm = new Alarm();
}


public void setAlarm(int hour, int minute)
{
alarm.setWakeUpTime(hour,minute);
}

public String getAlarm()
{
return alarm.getWakeUpTime();
}


public void timeTick()
{
clock.timeTick();
String time = getTime();
boolean wakeUp = alarm.check(time);
if(wakeUp)
{
System.out.println("It is " + time + " - RING RING");
}
else
{
System.out.println("ZZZZZ");
}
}


public void setTime(int hour, int minute)
{
clock.setTime(hour,minute);
}


public String getTime()
{
return clock.getTime();
}

}