Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you please do it as a Java (.java) Create a program that generates a simple

ID: 3848663 • Letter: C

Question

Can you please do it as a Java (.java)

Create a program that generates a simple day schedule with 3 activities, based upon the following inputs:

1-Activity Name (Keep it to a short word if you are using tabs, or in the length range using a .format() or .printf() statement)

2-Activity Starting Hour (in military time, which is a 24 hr clock, acceptable numbers 1-24 – do data validation)

3-Activity Ending Hour (in military time also) – perform a validity check to be sure that this number is greater than or equal to Starting Hour

4-Hints:

.Activities do not have to be entered in chronological order, but there should be no overlapping. Start/End numbers are inclusive.

.Utilize a nested loop, the outer loop goes from 1..24 for the hour of day.

.For each iteration of the outer loop, have an inner for() loop that goes from col=1 to col=3

.Use a switch statement to test for the case of 1, 2, and 3 to represent each of 3 cols/activities. Then, under the case, use an if statement to test if the hour falls between the start/end time for this activity. Then perform the output of the activity into the appropriate column (tabs work here, or you can use the .printf() or .format() method, which is preferred. If using tabs, you can tab out when processing activity 1 - two tabs, activity 2 - three tabs, and activity 3 - four tabs, for example.

.Perform data validation to prevent bad input.

.This program requires at least 3 variables for each of the 3 activities you are logging, and 2 loop counter variables.

.Arrays are not necessary, but if you want to use them you may.

Sample Output:

Enter activity 1 name: Eat

Enter activity 1 starting hour: 12

Enter activity 1 ending hour: 14

Enter activity 2 name: Sleep

Enter activity 2 starting hour: 1

Enter activity 2 ending hour: 9

Enter activity 3 name: School

Enter activity 3 starting hour: 16

Enter activity 3 ending hour: 22

My Schedule

Hour     Act1      Act2      Act3

1                      Sleep

2                      Sleep

3                      Sleep

4                      Sleep

5                      Sleep

6                      Sleep

7                      Sleep

8                      Sleep

9                      Sleep

10

11

12         Eat

13         Eat

14         Eat

15

16                                 School

17                                 School

18                                 School

19                                 School

20                                 School

21                                 School

22                                 School

23

24

Explanation / Answer

import java.util.Scanner;
class acti
{
public static void main(String args[])
{
String act1,act2,act3; //variable delaration
act1="";
act2="";
act3="";
int k=1;
int st1,st2,st3,en1,en2,en3,i;
int hr[]=new int[24];
String a1[]=new String[24];
String a2[]=new String[24];
String a3[]=new String[24];
for(i=0;i<24;i++)
{
hr[i]=k;
a1[i]="";
a2[i]="";
a3[i]="";
k=k+1;
}
Scanner sc=new Scanner(System.in); //taking user input
System.out.println("Enter activity 1 name:");
act1=sc.next();
do
{
System.out.println("Enter activity 1 starting hour:");
st1=sc.nextInt();
System.out.println("Enter activity 1 ending hour:");
en1=sc.nextInt();
}while(st1>=24 || en1>=24 || en1<st1);
System.out.println("Enter activity 2 name:");
act2=sc.next();
do
{
System.out.println("Enter activity 2 starting hour:");
st2=sc.nextInt();
System.out.println("Enter activity 2 ending hour:");
en2=sc.nextInt();
}while(st2>=24 || en2>=24 || en2<st2);
System.out.println("Enter activity 3 name:");
act3=sc.next();
do
{
System.out.println("Enter activity 3 starting hour:");
st3=sc.nextInt();
System.out.println("Enter activity 3 ending hour:");
en3=sc.nextInt();
}while(st3>=24 || en3>=24 || en3<st3);
for(i=st1;i<=en1;i++) //putting the value in the array
{
a1[i-1]=act1;
}
for(i=st2;i<=en2;i++)
{
a2[i-1]=act2;
}
for(i=st3;i<=en3;i++)
{
a3[i-1]=act3;
}
System.out.println("My schedule"); //displaying n format
System.out.println("Hour"+" "+"Act1"+" "+"Act2"+" "+"Act3");
for(i=0;i<24;i++)
{
System.out.println(hr[i]+" "+a1[i]+" "+a2[i]+" "+a3[i]);
}
  
}
}