In this assignment, we will develop a tool that we can use to keep track of acti
ID: 3568415 • Letter: I
Question
In this assignment, we will develop a tool that we can use to keep track of activities (events) a basic electronic planner of sorts. In order to bound the scope of the assignment, you are required to build a system that: will be able to add events, delete events and view events either for a specific date or for seven days starting at a specific date. events will be stored in an array (set maximum size for now to be 1000). there can only be one event for a given date and time sorting, deleting and retrieving events efficiently in an array will be a major topic in your third semester Data Structures course; for now, events will be stored in an array and do not need to be sorted. This means we will just search sequentially through the array. You must write a class called Event which will handle the date/time/actions for a single Event. All events will contain a date (day, month, year), time (hour, minute), and activity description (String). All input entered from the keyboard must be fully edited for valid data You must use the two classes that we have developed previously in this course- the OurDate and a Time class from Unit 3 examples (call it now OurTime). (This is meant to help bound the scope of the assignment so that the amount of work is limited). You must write a class called Planner which will handle an array of Events. There will be one method for each of the menu selections in this class You must write a class called Assign4 which contains method main for this assignment which contains the menu for the program. Enhancements (bonus) Clearly, there are many possible enhancements to this program. Enhancements will earn bonus marks if all requirements for the assignment are met! Maximum 3 marks bonus.
Sample Output (blue is user input)
Enter 1 to add an activity to planner; 2 to display activities for a day; 3 to display activites for a week; 4 to delete an activity; 0 to quit: 1
Enter month: 11
Enter day: 5
Enter year: 2014
Enter hour (0-23): 10
Enter minute: 0
Enter event description: Coordinator meeting
Code I have so far------
OurTime
public class OurTime {
private int hours;
private int minutes;
private int seconds;
public OurTime() {
hours = 0;
minutes = 0;
seconds = 0;
}
public OurTime (int h, int m, int s) {
hours = h;
minutes = m;
seconds = s;
}
public void setHoursFromUser( ) {
Scanner input = new Scanner (System.in);
System.out.println("Enter the hours(0-23): ");
hours = input.nextInt();
while (hours < 0 || hours > 23) {
System.out.println("Error...invalid hours....Enter the hours(0-23): ");
hours = input.nextInt();
}
}// end setHours
public void setMinutesFromUser( ) {
Scanner input = new Scanner (System.in);
System.out.println("Enter the minutes (0-59): ");
minutes = input.nextInt();
while (minutes < 0 || minutes > 59) {
System.out.println("Error...invalid minutes....Enter the minutes(0-59): ");
minutes = input.nextInt();
}
}// end setMinutes
public void setSecondsFromUser( ) {
Scanner input = new Scanner (System.in);
System.out.println("Enter the seconds (0-59): ");
seconds = input.nextInt();
while (seconds < 0 || seconds > 59) {
System.out.println("Error...invalid seconds....Enter the seconds(0-59): ");
seconds = input.nextInt();
}
}// end setSeconds
public void display() {
System.out.println (hours + ":" + minutes + ":" + seconds);
}// end of display
public int calcTotalSeconds() {
return ((hours*60+minutes)*60+seconds);
}// end calcTotalSeconds
}// end of class Time
OurDate
public class OurDate {
private int month;
private int day;
private int year;
public OurDate() {
month = 01;
day = 01;
year = 1901;
}
public OurDate (int mm, int dd, int yyyy) {
month = mm;
day = dd;
year = yyyy;
}
public void inputMonth() {
Scanner input = new Scanner (System.in);
System.out.println("Enter the month(0-12): ");
month = input.nextInt();
}
public void inputDay() {
Scanner input = new Scanner (System.in);
System.out.println("Enter the day (0-31): ");
day = input.nextInt();
}
public void inputYear() {
Scanner input = new Scanner (System.in);
System.out.println("Enter the year (0-2500): ");
year = input.nextInt();
}
public void displayDate() {
System.out.println ("Inital Date is "+ month + "/" + day + "/" + year);
}
public void display() {
System.out.println ("The Date is "+ month + "/" + day + "/" + year);
}
public static void main (String [] args) {
OurDate Date1 = new OurDate();
Date1.displayDate();
Date1.inputMonth();
Date1.inputDay();
Date1.inputYear();
Date1.display();
}
}// end of class OurDate
Explanation / Answer
Event planner java programs
//OurDate.java
import java.util.Scanner;
public class OurDate
{
private int month;
private int day;
private int year;
public OurDate()
{
month = 01;
day = 01;
year = 1901;
}
public OurDate (int mm, int dd, int yyyy)
{
month = mm;
day = dd;
year = yyyy;
}
public void inputMonth() {
Scanner input = new Scanner (System.in);
System.out.println("Enter the month(0-12): ");
month = input.nextInt();
}
public void inputDay() {
Scanner input = new Scanner (System.in);
System.out.println("Enter the day (0-31): ");
day = input.nextInt();
}
public void inputYear() {
Scanner input = new Scanner (System.in);
System.out.println("Enter the year (0-2500): ");
year = input.nextInt();
}
//Add accessor methods to get day,month and year of date.
public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
public void displayDate() {
System.out.println ("Inital Date is "+ month + "/" + day + "/" + year);
}
public void display() {
System.out.println ("The Date is "+ month + "/" + day + "/" + year);
}
}// end of class OurDate
-------------------------------------------------------------------
import java.util.Scanner;
public class OurTime
{
private int hours;
private int minutes;
private int seconds;
public OurTime()
{
hours = 0;
minutes = 0;
seconds = 0;
}
public OurTime (int h, int m, int s)
{
hours = h;
minutes = m;
seconds = s;
}
public void setHoursFromUser( )
{
Scanner input = new Scanner (System.in);
System.out.println("Enter the hours(0-23): ");
hours = input.nextInt();
while (hours < 0 || hours > 23) {
System.out.println("Error...invalid hours....Enter the hours(0-23): ");
hours = input.nextInt();
}
}// end setHours
public void setMinutesFromUser( )
{
Scanner input = new Scanner (System.in);
System.out.println("Enter the minutes (0-59): ");
minutes = input.nextInt();
while (minutes < 0 || minutes > 59)
{
System.out.println("Error...invalid minutes....Enter the minutes(0-59): ");
minutes = input.nextInt();
}
}// end setMinutes
public void setSecondsFromUser( )
{
Scanner input = new Scanner (System.in);
System.out.println("Enter the seconds (0-59): ");
seconds = input.nextInt();
while (seconds < 0 || seconds > 59) {
System.out.println("Error...invalid seconds....Enter the seconds(0-59): ");
seconds = input.nextInt();
}
}// end setSeconds
public void display()
{
System.out.println (hours + ":" + minutes + ":" + seconds);
}// end of display
public int calcTotalSeconds()
{
return ((hours*60+minutes)*60+seconds);
}// end calcTotalSeconds
}// end of class Time
------------------------------------------------------------------------------------------------------------
//event class to set date, time and event description
public class Event
{
private OurDate ourDate;
private OurTime ourTime;
private String eventDescription;
public Event(OurDate ourDate,OurTime ourTime, String eventDescription)
{
this.ourDate=ourDate;
this.ourTime=ourTime;
this.eventDescription=eventDescription;
}
//return date
public OurDate getDate()
{
return ourDate;
}
public void displayEvent()
{
ourDate.displayDate();
ourTime.display();
System.out.println("Event Description "+eventDescription);
}
}
------------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Planner
{
private int SIZE;
private Event events[];
private int count;
public Planner()
{
SIZE=500;
events=new Event[SIZE];
count=0;
}
public void addEvent()
{
OurDate ourDate=new OurDate();
ourDate.inputDay();
ourDate.inputMonth();
ourDate.inputYear();
OurTime ourTime=new OurTime();
ourTime.setHoursFromUser();
ourTime.setMinutesFromUser();
ourTime.setSecondsFromUser();
Scanner reader=new Scanner(System.in);
System.out.println("Enter description");
String description=reader.nextLine();
Event event=new Event(ourDate, ourTime, description);
if(count<SIZE)
events[count]=event;
//increament event count
count++;
}
//display events for a day.
public void displayDayActivities()
{
OurDate searchDate=new OurDate();
searchDate.inputDay();
for (int eventIndex = 0; eventIndex < count; eventIndex++)
{
OurDate date=events[eventIndex].getDate();
if(searchDate.getDay()==date.getDay())
events[eventIndex].displayEvent();
}
}//end of the method displayDayActivities
//display events for a month.
public void displayMonthActivities()
{
OurDate searchDate=new OurDate();
searchDate.inputMonth();
for (int eventIndex = 0; eventIndex < events.length; eventIndex++)
{
OurDate date=events[eventIndex].getDate();
if(searchDate.getMonth()==date.getMonth())
events[eventIndex].displayEvent();
}
}//end of the method displayMonthActivities
//display events for a month.
public void deleteActivity()
{
OurDate searchDate=new OurDate();
searchDate.inputDay();
searchDate.inputMonth();
searchDate.inputYear();
boolean deleted=false;
for (int eventIndex = 0; eventIndex < events.length; eventIndex++)
{
OurDate date=events[eventIndex].getDate();
if( searchDate.getDay()==date.getDay()&&
searchDate.getMonth()==date.getMonth()&&
searchDate.getYear()==date.getYear())
//set event to null
{
events[eventIndex]=null;
deleted=true;
}
}
if(deleted)
System.out.println("Event is deleted");
else
System.out.println("Event is not found");
}//end of the method displayMonthActivities
}
------------------------------------------------------------------------------------------------------------------
//Event planner java program that allows
//user to menu choice to add activity, display
//activity for a day and activties for a month
//and delete the activity in a planner and 0 to quit
//Assign4.java
import java.util.Scanner;
public class Assign4
{
public static void main(String[] args)
{
//To read user choice
int userChoice;
//scanner to read user input
Scanner reader=new Scanner(System.in);
//create an instance of Planner
Planner planner=new Planner();
do
{
System.out.println("1: Add an activity to planner");
System.out.println("2: Display activities for a day");
System.out.println("3: Display activites for a week");
System.out.println("4: Delete an activity");
System.out.println("0 to quit");
System.out.println("Enter your choice");
userChoice=reader.nextInt();
if(userChoice==0)
{
System.out.println("Program exit");
System.exit(0);
}
switch (userChoice)
{
case 1:
planner.addEvent();
break;
case 2:
planner.displayDayActivities();
break;
case 3:
planner.displayMonthActivities();
break;
default:
System.out.println("Invalid choice");
break;
}
}while(true);
}
}
---------------------------------------------------------------------------------------------------------------------------
Sample output:
1: Add an activity to planner
2: Display activities for a day
3: Display activites for a week
4: Delete an activity
0 to quit
Enter your choice
1
Enter the day (0-31):
12
Enter the month(0-12):
12
Enter the year (0-2500):
2014
Enter the hours(0-23):
12
Enter the minutes (0-59):
0
Enter the seconds (0-59):
0
Enter description
Manager
1: Add an activity to planner
2: Display activities for a day
3: Display activites for a week
4: Delete an activity
0 to quit
Enter your choice
2
Enter the day (0-31):
12
Inital Date is 12/12/2014
12:0:0
Event Description Manager
1: Add an activity to planner
2: Display activities for a day
3: Display activites for a week
4: Delete an activity
0 to quit
Enter your choice
1
Enter the day (0-31):
13
Enter the month(0-12):
12
Enter the year (0-2500):
2014
Enter the hours(0-23):
12
Enter the minutes (0-59):
0
Enter the seconds (0-59):
0
Enter description
Assistant
1: Add an activity to planner
2: Display activities for a day
3: Display activites for a week
4: Delete an activity
0 to quit
Enter your choice
2
Enter the day (0-31):
12
Inital Date is 12/12/2014
12:0:0
Event Description Manager
1: Add an activity to planner
2: Display activities for a day
3: Display activites for a week
4: Delete an activity
0 to quit
Enter your choice
3
Enter the month(0-12):
Hope this would be helps you