Objective: Write a program that keeps track of a schedule for a day. Create the
ID: 3764014 • Letter: O
Question
Objective:
Write a program that keeps track of a schedule for a day. Create the following.
Example Dialog:
Welcome to the day planner system
Enter 1 to add an activity
Enter 2 to remove an activity
Enter 9 to quit
1
Enter the activity's name
class
Enter its start hour in military time
13
Enter its end hour in military time
14
class 13 14
Enter 1 to add an activity
Enter 2 to remove an activity
Enter 9 to quit
1
Enter the activity's name
breakfast
Enter its start hour in military time
8
Enter its end hour in military time
9
breakfast 8 9
class 13 14
Enter 1 to add an activity
Enter 2 to remove an activity
Enter 9 to quit
1
Enter the activity's name
lab exam
Enter its start hour in military time
15
Enter its end hour in military time
18
breakfast 8 9
class 13 14
lab exam 15 18
Enter 1 to add an activity
Enter 2 to remove an activity
Enter 9 to quit
1
Enter the activity's name
breakfast part 2
Enter its start hour in military time
8
Enter its end hour in military time
10
The activity to be added conflicts with an existing activity. This activity will not be added.
breakfast 8 9
class 13 14
lab exam 15 18
Enter 1 to add an activity
Enter 2 to remove an activity
Enter 9 to quit
2
Enter the activity's name
breakfast
class 13 14
lab exam 15 18
Enter 1 to add an activity
Enter 2 to remove an activity
Enter 9 to quit
9
class 13 14
lab exam 15 18
Good bye!
Finally:
Upload the .java file to the dropbox
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package schedule;
import java.util.Date;
/**
*
* @author allu
*/
public class Schedule {
int end;
String name;
int start;
public Schedule() {
}
public Schedule( String name, int start,int end) {
this.end = end;
this.name = name;
this.start = start;
}
}
first we write a schedule class in instant variblaes and canstracter
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package schedule;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
/**
*
* @author allu
*/
public class DayPlaner {
public static void main(String []a) throws IOException
{
ArrayList al=new ArrayList();
Scanner in = new Scanner(System.in);
for(int i=0;i<1||i<=al.size();i++)
{
System.out.print("Welcome to the day planner system");
System.out.print(" Enter 1 to add an activity:");
System.out.print(" Enter 2 to remove an activity:");
System.out.print(" Enter 9 to quit: ");
int num = in.nextInt();
String name;
switch (num) {
case 1: System.out.println("Enter the activity's name && time:");
al.add(new Schedule(in.next(),in.nextInt(),in.nextInt()));
Iterator itr=al.iterator();
while(itr.hasNext()){
Schedule ss=(Schedule) itr.next();
System.out.println(" task name:"+ss.name+" start time is:"+ss.start+" end time is"+ss.end);
}
// name = in.next();
break;
case 2: System.out.println("Enter the activity's name:");
Iterator itr2=al.iterator();
while(itr2.hasNext()){
Schedule ss2=(Schedule) itr2.next();
if(ss2.name==in.next()){
al.remove(ss2);
}else{
System.out.println(" task name:"+ss2.name+" start time is:"+ss2.start+" end time is"+ss2.end);
}
}
// name = "February";
break;
default: name = "Invalid number prease";
System.out.println("gud bye:");
break;
}
}
// System.out.println(s.a+num);
// System.out.println(name);
}}
next we set this logic and we get out put as below
output
Welcome to the day planner system
Enter 1 to add an activity:
Enter 2 to remove an activity:
Enter 9 to quit:
1
Enter the activity's name && time:
class
13
14
task name:class
start time is:13
end time is14
Welcome to the day planner system
Enter 1 to add an activity:
Enter 2 to remove an activity:
Enter 9 to quit:
1
Enter the activity's name && time:
breakfast
8
9
task name:class
start time is:13
end time is14
task name:breakfast
start time is:8
end time is9
Welcome to the day planner system
Enter 1 to add an activity:
Enter 2 to remove an activity:
Enter 9 to quit:
2
Enter the activity's name:
breakfast
task name:class
start time is:13
end time is14
Enter 1 to add an activity:
Enter 2 to remove an activity:
Enter 9 to quit:
9
gud bye:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.