Alarm class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Alarm class

  1. #1
    Join Date
    Dec 2005
    Posts
    12

    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;
       }
           
           
         
    }

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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.

  3. #3
    Join Date
    Dec 2005
    Posts
    12

    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.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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.

  5. #5
    Join Date
    Dec 2005
    Posts
    12
    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);
      }
      
    }

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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?

  7. #7
    Join Date
    Dec 2005
    Posts
    12
    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

  1. Help with class/applet
    By none_none in forum Java
    Replies: 17
    Last Post: 04-28-2005, 03:00 PM
  2. Replies: 5
    Last Post: 10-17-2002, 01:58 PM
  3. Assembly class
    By Shailesh C.Rathod in forum .NET
    Replies: 2
    Last Post: 03-13-2002, 07:53 PM
  4. How To Do It - Shared Class Variables Part III
    By Patrick Ireland in forum .NET
    Replies: 5
    Last Post: 05-10-2001, 06:19 PM
  5. Calling base class methods
    By GR in forum Java
    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center