proud and happy … that i’ve made it correctly
Sample Tester or the main Program
**********************************************************
//Jaquelyn M. Lagbas
//December 5, 2006
//Time and Again
import java.io.*;
import java.util.*;
public class DSAlgo05 extends myTime
{
public static void main (String[] args) throws IOException
{
System.out.println("===Case #1===");
myTime t1=new myTime();
t1.setTime(14,58,03);
t1. print();
System.out.println();
t1.advance();
t1.print();
System.out.println();
t1.advance(3,5,2);
t1.print();
System.out.println();
System.out.println("===Case #2===");
myTime t2=new myTime();
t2.setTime(7,75,98);
t2.print();
System.out.println();
t2.advance();
t2.print();
System.out.println();
t2.advance(3,5,2);
t2.print();
System.out.println();
}
}
***********************************************
this is it!!!
time Class
**************************************
import java.io.*;
import java.util.*;
public class myTime
{
private int hour;
private int minute;
private int second;
private int other;
public myTime()
{
hour = 0;
minute = 0;
second = 0;
other=0;
}
public myTime(int a, int b, int c)
{
setTime(a, b, c);
}
public void setTime(int a, int b, int c)
{
hour = a;
minute = b;
second = c;
}
////////////////reset//////////////////
public void reset(int a, int b, int c)
{
hour = a;
minute = b;
second = c;
}
public void reset(int a, int b)
{
hour = a;
minute = b;
}
public void reset(int a)
{
hour = a;
}
public void reset()
{
hour = 0;
minute = 0;
second = 0;
}
////////////////////////////////////////
//////////////////////GET///////////////////////
public int gethour()
{ return hour; }
public int getminute()
{ return minute; }
public int getsecond()
{ return second;}
/////////////////////////////////
/////////////advance//////////////////
public void advance(int a, int b, int c)
{
hour=hour+a;
minute=minute+b;
second=second+c;
normalize();
}
public void advance()
{
hour=hour+0;
minute=minute+0;
second=second+1;
normalize();
}
public void advance(int a, int b)
{
hour=hour+a;
minute=minute+b;
normalize();
}
public void advance(int a)
{
hour=hour+a;
normalize();
}
/////////////////////////////////////////////////
/////////////////nortmalize/////////////////
public void normalize()
{
while(second>60){second=second%60; minute++; }
while(minute>60){minute=minute%60; hour++; }
while(hour>12){hour=hour-12; }
}
public void print()
{
normalize();
System.out.print (hour + ":" + minute + ":" + second);
}
}
This code will let the user advance , reset and normlize the time(12hours)…







