I have the following classes completed and have to create a driver that:
rite a driver program to test your Clock class. The driver program should allow the user to enter both the current time and the alarm time. It should create one or more Clock objects to demonstrate usage of the constructors, and it should print the Clock objects.
to test them and I am stuck. Am I at least on the right page with the driver??
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author tircuit
*/
// The time class stores a time value, in hours and minutes
// Does not have am/pm. Use a 24 hour time system to represent all of the
// hours in a day.
// For more information on 24 hour clocks, see the wikipedia page:
// [url]http://en.wikipedia.org/wiki/24-hour_clock[/url]
public class TimeAT
{
private int hours;
private int minutes;
// Assigns 12pm to the time.
public TimeAT()
{
hours = 12;
minutes = 0;
}
public TimeAT(int h, int m)
{
if(h >= 0 && h <= 24)
hours = h;
else
hours = 12;
if(m >= 0 && m < 60)
minutes = m;
else
minutes = 0;
}
public boolean setHours(int h)
{
if(h >= 0 && h <= 24)
{
hours = h;
return true;
}
return false;
}
public boolean setMinutes(int m)
{
if(m >= 0 && m < 60)
{
minutes = m;
return true;
}
return false;
}
public int getHours()
{
return hours;
}
public int getMinutes()
{
return minutes;
}
public String toString()
{
String str = hours + ":" + minutes ;
if(minutes == 0)
str = str + "0";
return str;
}
}
class Clock
{
private TimeAT currentTime=null;
private TimeAT alarm= null;
public Clock ()
{
currentTime = new TimeAT();
alarm = new TimeAT();
}
public Clock (TimeAT curr, TimeAT al)
{
currentTime = curr;
alarm = al;
}
//setTime and setAlarm method---X
public void set(TimeAT curr, TimeAT al)
{
currentTime = curr;
alarm = al;
}
//getTime---X
public TimeAT getTime()
{
return currentTime;
}
//getAlarm---X
public TimeAT getAlarm()
{
return alarm;
}
//toString---X
public String toString()
{
String str = "Current time: " + currentTime
+ "\nAlarm time: " + alarm;
return str;
}
}
import java.util.Scanner;
public class ClockDemo {
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the current time: ");
int testTime = keyboard.nextInt();
System.out.println("Enter the alarm time: ");
int testAlarm = keyboard.nextInt();
Clock clock1 = new (testTime);
System.out.println(clock1);
Clock clock2 = new Clock(testAlarm);
System.out.println(clock2);
}
}