//Represents time in hours and minutes using 
//the customary conventions

public class Time
{
	
	private int hours; //hours in conventional time
	
	private int minutes;	//minutes in conventional time	
	
	private boolean afternoon;	//true if afternoon time, false if morning time

	//Constructs a cutomary time (12 hours, am or pm)
	//from a military time ##:##
	public Time(String militaryTime)
	{
		
		
	public void setHours(int hours)
	{
		//Check to make sure something was entered
		if (militaryTime == null)
		{
			System.out.print(
				"You must enter a valid miliary time." );
		}
		//Check to make sure there are 5  characters
		else if (!(militaryTime == 5))
		{
			System.out.print(militaryTime + 
				" is not a valid miliary time." );
		}
		else
		{
	}		
			//Check to make sure the colon is in 
			//the correct spot
			if (!(militaryTime == colon)) 
			{
				System.out.print(militaryTime + 
					" is not a valid miliary time." );
			}
			//Check to make sure all other characters are digits
			else if (!(militaryTime == digit))	{
				System.out.println(militaryTime + 
					" is not a valid miliary time." );
			}
			else if (!(militaryTime == 23))			{
				System.out.print(militaryTime + 
					" is not a valid miliary time." );
			}
			else if (!(militaryTime == 59))
			{
				System.out.print(militaryTime + 
					" is not a valid miliary time." );
			}
			else if (!(militaryTime == 12))
			{
				System.out.println(militaryTime + 
					" is not a valid miliary time." );
			}
			else
			{
				//SEPARATE THE STRING INTO THE HOURS 
				//AND THE MINUTES, CONVERTING THEM TO 
				//INTEGERS AND STORING INTO THE 
				//INSTANCE VARIABLES				
				
				public void setAfternoon(boolean afternoon) 
	
				{
				//validate hours and minutes are valid values
				if(hours > 23)
				{
					System.out.print(militaryTime + 
						" is not a valid miliary time." );
				}
				else if(minutes > 59)
				{
					System.out.print(militaryTime + 
						" is not a valid miliary time." );
				}
				//convert military time to conventional time
				//for afternoon times
				else if (hours > 12)
				{
					hours = hours - 12;
					afternoon = true;
					System.out.print(this.toString());					
				}
				//account for midnight
				else if (hours == 0 && minutes == 0)
				{
					hours = 12;
					System.out.print(this.toString());
				}
				//morning times don't need converting
				else
				{
					System.out.print(this.toString());
				}
			}
		}
	}	
}

	
	
	public int getHours() 
	{
		return hours;
	}	
	public int getMinutes() 
	{
		return minutes;	
	}	
	public boolean getAfternoon() 	
	{
		return afternoon;	
	}
	
	
	public String toString()
	{
		String am_pm;
		String zero = "";
		if (afternoon)
			am_pm = "PM";
		else
			am_pm = "AM";
		if (minutes < 10)
			zero = "0";
		
		return hours + ":" + zero + minutes + " " + am_pm;
	}
}