-
Alarm class
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:
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
Code:
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;
}
}
-
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.
-
Alarm
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.
-
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.
-
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
Code:
public class Alarm
{
private AlarmClock alarmTime;
public Alarm()
{
alarmTime = new AlarmClock();
}
public void setAlarmTime(int hour, int minute)
{
alarmTime.setAlarmTime(hour,minute);
}
}
-
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?
-
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
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();
}
}
Similar Threads
-
By none_none in forum Java
Replies: 17
Last Post: 04-28-2005, 03:00 PM
-
Replies: 5
Last Post: 10-17-2002, 01:58 PM
-
By Shailesh C.Rathod in forum .NET
Replies: 2
Last Post: 03-13-2002, 07:53 PM
-
By Patrick Ireland in forum .NET
Replies: 5
Last Post: 05-10-2001, 06:19 PM
-
Replies: 1
Last Post: 11-09-2000, 05:38 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks