Computer Science, asked by BarbieDGirl, 8 months ago

Given a time in numbers we can convert it into words. For example 5:00 five o'clock 5:10 ten minutes past five 5:15 quarter past five 5:30 half past five 5:40 twenty minutes to six 5 : 45 quarter to six 5:47 thirteen minutes to six. WAP which first input two integers, the first between 1 and 12 (both inclusive) and second between 0 and 59 (both inclusive) and then prints out the time they represents, in words. Your program should follow the format of the examples above. SAMPLE DATA INPUT: TIME: 3,0 OUTPUT 3:00 three o'clock INPUT: TIME: 7,29 OUTPUT 7:29 Twenty nine minutes past seven. INPUT: TIME: 6,34 OUTPUT 6:34 twenty six minutes to seven INPUT: TIME: 12,1 OUTPUT 12:01 one minutes past twelve INPUT: TIME: 12, 45s OUTPUT 12:45 quarter to one INPUT: TIME: 10 , 59 OUTPUT 10:59 one minute to eleven INPUT: TIME: 14,60 OUTPUT: incorrect input. Test your program for the data values ​​given in the examples above and some random data.
PLEASE SOLVE THE ENTIRE PROGRAM ILL MARK YOU AS BRAINLIST!!​

Answers

Answered by ap5495988
0

Answer:

this question is very hard

i am trying solving please mark m brainliest pls

Answered by srishtigoyal1910
0

Explanation:

import java.util.*;

class Time

{

void main()

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter number of hours:");

int h=sc.nextInt();

System.out.print("Enter number of minutes:");

int m=sc.nextInt();

int b[]={1,2,3,4,5,6,7,8,9,10,11,12};

String a[]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","One"};

String s="";

if(m>=0 && m<=59 && h>=0 && h<=12)

{

if((m>=1 && m<=14)||(m>=16 && m<=29))

{

switch(m)

{

case 1:s="One minutes past ";

break;

case 2:s="Two minutes past ";

break;

case 3:s="Three minutes past ";

break;

case 4:s="Four minutes past ";

break;

case 5:s="Five minute past ";

break;

case 6:s="Six minute past ";

break;

case 7:s="Seven minute past ";

break;

case 8:s="Eight minute past ";

break;

case 9:s="Nine minute past ";

break;

case 10:s="Ten minute past ";

break;

case 11:s="Eleven minutes past ";

break;

case 12:s="Twelve minutes past ";

break;

case 13:s="Thirteen minutes past ";

break;

case 14:s="Fourteen minutes past ";

break;

case 16:s="Sixteen minutes past ";

break;

case 17:s="Seventeen minutes past ";

break;

case 18:s="Eighteen minutes past ";

break;

case 19:s="Nineteen minutes past ";

break;

case 20:s="Twenty minutes past ";

break;

case 21:s="Twenty one minutes past ";

break;

case 22:s="Twenty two minutes past ";

break;

case 23:s="Twenty three minutes past ";

break;

case 24:s="Twenty four minutes past ";

break;

case 25:s="Twenty five minute past ";

break;

case 26:s="Twenty six minute past ";

break;

case 27:s="Twenty seven minute past ";

break;

case 28:s="Twenty eight minute past ";

break;

case 29:s="Twenty nine minute past ";

break;

default:break;

}

for(int i=0;i<11;i++)

{

char ch=a[i+1].charAt(0);

ch=Character.toLowerCase(ch);

if(h==b[i+1])

System.out.println(h+":"+m+" "+s+ch+a[i+1].substring(1));

}

}

else if(m==15)

{

for(int i=0;i<11;i++)

{

if(h==b[i+1])

System.out.println(h+":"+m+" fivteen minutes past "+a[i+1]);

}

}

else if(m==45)

{

for(int i=0;i<11;i++)

{

if(h==b[i+1])

System.out.println(h+":"+m+" quarter to "+a[i+2]);

}

}

else if((m>=31 && m<=44)||(m>=46 && m<=59))

{

switch(m)

{

case 31:s="Twenty nine minutes to ";

break;

case 32:s="Twenty eight minutes to ";

break;

case 33:s="Twenty seven minutes to ";

break;

case 34:s="Twenty six minutes to ";

break;

case 35:s="Twenty five minute to ";

break;

case 36:s="Twenty four minutes to ";

break;

case 37:s="Twenty three minutes to ";

break;

case 38:s="Twenty two minutes to ";

break;

case 39:s="Twenty one minutes to ";

break;

case 40:s="Twenty minutes to ";

break;

case 41:s="Nineteen minutes to ";

break;

case 42:s="Eigthteen minutes to ";

break;

case 43:s="Seventeen minutes to ";

break;

case 44:s="Sixteen minutes to ";

break;

case 46:s="Fourteen minutes to ";

break;

case 47:s="Thirteen minutes to ";

break;

case 48:s="Twelve minutes to ";

break;

case 49:s="Eleven minutes to ";

break;

case 50:s="Ten minutes to ";

break;

case 51:s="Nine minutes to ";

break;

case 52:s="Eigth minutes to ";

break;

case 53:s="Seven minutes to ";

break;

case 54:s="Six minutes to ";

break;

case 55:s="Five minutes to ";

break;

case 56:s="Four minutes to ";

break;

case 57:s="Three minutes to ";

break;

case 58:s="Two minutes to ";

break;

case 59:s="One minute to ";

break;

default:break;

}

int k=0;

for(int i=0;i<11;i++)

{

k=i+1;

char ch=a[k+1].charAt(0);

ch=Character.toLowerCase(ch);

if(h==b[i+1])

System.out.println(h+":"+m+" "+s+ch+a[k+1].substring(1));

}

}

else if(m==30)

{

for(int i=0;i<11;i++)

{

if(h==b[i+1])

System.out.println(h+":"+m+" Half past"+a[i+1]);

}

}

}

else

System.out.println("Invalid Time");

}

}

Similar questions