Alarm Class

Alarm settings

Page 1 of 1

7 Replies - 16123 Views - Last Post: 06 January 2006 - 04:19 PM Rate Topic: -----

#1 Aristo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 02-December 05

Alarm Class

Posted 02 December 2005 - 12:26 PM

Hello Guys,
I kindly need more direct help please.
This is what I have done so far or (trying to do), .... So basically 2 things (1)That is, an alarm clock that stores the time that the alarm is set to. (2) That time can be changed...
Sincerely appreciate the help.


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



This post has been edited by skyhawk133: 02 December 2005 - 12:37 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Alarm Class

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Alarm Class

Posted 02 December 2005 - 04:07 PM

Well, you've not really provided enough of a template to go on, but I'll hazard a guess that you were going for something like the following:
public class Alarm
{
  private int hour;
  private int minute;
 
  public Alarm()
  {
      hour = 12;
      minute = 30;
   }
     
 
   public void setWakeUpTime(int newhour,int newminute)
  {
      hour = newhour;
      minute = newminute;
   }
       
}



The changeWakeUpTime would work along the same principles...is the changeWakeUpTime method supposed to do something different?
Was This Post Helpful? 0
  • +
  • -

#3 Aristo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 02-December 05

Re: Alarm Class

Posted 03 December 2005 - 11:57 AM

Thanks alot for the help......what I wanted was another alarm class that (1)
Contains a time that the alarm is set to (2) And that time can be changed.....The Alarm class works with 3 other classes, ALARMCLOCK, CLOCKDISPLAY AND NUMBERDISPLAY CLASSES and without changes to the 3 classes write another class called ALARM CLASS.
Appreciate the help.

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

}


public class ClockDisplay
{
    private NumberDisplay hours;
    private NumberDisplay minutes;
    private String displayString;    // simulates the actual display
    
   
    public ClockDisplay()
    {
        hours = new NumberDisplay(24);
        minutes = new NumberDisplay(60);
        updateDisplay();
    }

   
    public ClockDisplay(int hour, int minute)
    {
        hours = new NumberDisplay(24);
        minutes = new NumberDisplay(60);
        setTime(hour, minute);
    }

   
    public void timeTick()
    {
        minutes.increment();
        if(minutes.getValue() == 0) {  // it just rolled over!
            hours.increment();
        }
        updateDisplay();
    }

    /**
     * Set the time of the display to the specified hour and
     * minute.
     */
    public void setTime(int hour, int minute)
    {
        hours.setValue(hour);
        minutes.setValue(minute);
        updateDisplay();
    }

   
    public String getTime()
    {
        return displayString;
    }
    
   
    private void updateDisplay()
    {
        displayString = hours.getDisplayValue() + ":" + 
                        minutes.getDisplayValue();
    }
}






public class NumberDisplay
{
private int limit;
private int value;

/**
* Constructor for objects of class Display
*/
public NumberDisplay(int rollOverLimit)
{
limit = rollOverLimit;
value = 0;
}

/**
* Return the current value.
*/
public int getValue()
{
return value;
}

/**
* Return the display value (that is, the current value as a two-digit
* String. If the value is less than ten, it will be padded with a leading
* zero).
*/
public String getDisplayValue()
{
if(value < 10)
return "0" + value;
else
return "" + value;
}

/**
* Set the value of the display to the new specified value. If the new
* value is less than zero or over the limit, do nothing.
*/
public void setValue(int replacementValue)
{
if((replacementValue >= 0) && (replacementValue < limit))
value = replacementValue;
}

/**
* Increment the display value by one, rolling over to zero if the
* limit is reached.
*/
public void increment()
{
value = (value + 1) % limit;
}
}


[CODE][CODE]
Was This Post Helpful? 0
  • +
  • -

#4 Wizzy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 408
  • Joined: 20-November 05

Re: Alarm Class

Posted 04 December 2005 - 05:36 PM

All you need is a global variable for the alarm for this to do something.

public class clock {
boolean timefixed = false;
if(timefixed) {
System.out.println("Time cannot be altered");
}
}


Was This Post Helpful? 0
  • +
  • -

#5 Aristo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 02-December 05

Re: Alarm Class

Posted 05 December 2005 - 10:02 AM

But what I want or was trying to do is a method to store the time alarm is set to, and another method to change the time ......
Was This Post Helpful? 0
  • +
  • -

#6 M0les  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-January 06

Re: Alarm Class

Posted 02 January 2006 - 10:07 PM

I'm still a bit confused as-to the point of your original pseudocode, but here's some possibilities:
  • both the Alarm object fields and the mthod parameters called "hour" and "minute" are the atomic type "int" and thus do not support method calls themselves. Even so you seemed to be confused as-to how to set the value of an integer.
  • You can access object fields whose names are overridden by method parameters by prefixing with "this." e.g. "this.hour = hour;" assigns the value of the local method parameter "hour" to the object field of the same name.
  • (General obs.) It's usually a good idea to "gate" access to fields through as few methods as possible (hence the change to the constructor below). Although it's not much change in this simple example, it can save hair-pulling with more complex data.
Here's what I think the code should look like if I understand your request correctly:

public class Alarm
{
  private int hour;
  private int minute;
 
  public Alarm()
  {
      setWakeupTime( 12, 30 );
   }
     
 
   public void setWakeUpTime(int hour,int minute)
  {
      this.hour = hour;
      this.minute = minute;
   }
   
   public void changeWakeUpTime(int hour, int minute)
   {
       setWakeUpTime( hour, minute );
   }
}



I'm still confused, however, as to the point of having an alias called "changeWakeupTime" for the method "setWakeupTime" - as far as I can tell from your query, these do the same thing.

M0les.
Was This Post Helpful? 0
  • +
  • -

#7 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Alarm Class

Posted 03 January 2006 - 06:58 AM

You might also think about using a GregorianCalendar to store the date/time.
Was This Post Helpful? 0
  • +
  • -

#8 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 65
  • Joined: 26-December 05

Re: Alarm Class

Posted 06 January 2006 - 04:19 PM

I havnt really gone thru but I think you are missing a class..........The time class, that is the place you need to declare and define methids to manipulate the time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1