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

I need help to write this JAVA program. Problem Description Develop a tool to ke

ID: 3662849 • Letter: I

Question

I need help to write this JAVA program.

Problem Description

Develop a tool to keep track of events – a basic electronic planner of sorts. The Planner 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. The planner is able to calculate how many days exist between events. An Event will be stored in an array (set maximum size for now to be 10). There can only be one Event for a given date. Sorting, deleting and retrieving elements (in this case, the elements are references to Event objects) 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. Every Event will contain a date (day, month, year) and an activity description (String). All input entered from the keyboard must be fully edited for valid data. In the case of this assignment, if a user attempts to enter data that is outside of the appropriate range, by default the field will be set to the first day, month or year of the acceptable range of values. For example if a user attempts to set a day to 34, it will automatically be set to 1. NOTE: Only Planner interacts with the user, no other classes should use Scanner or println (etc.)

• Assign1 contains only a main method, which instantiates one Planner and calls runMenu().

• Planner has a private int constant which is used for the maximum amount of events, an array for Event references (10 references), an int and an OurDate reference, one constructor and six methods:

§ runMenu() - shows the menu, interacts with the user for menu selection, loops till they exit.

§ addEvent().

§ verifies that the maximum number of events is already in the Planner

§ loops through the array to confirm that an event for the date specified is not already taken.

§ If there is not already an event on the date specified, add the event to the array and add one to the numEvents counter.

§ enterDate() – fetches the date from the user and assigns values to the fields of each reference by invoking methods of the OurDate class.

§ displayOneDay() - displays the event for the date specified.

§ displaySevenDays() – displays seven days of events by invoking displayOneDay() seven times, starting with the event with the date specified.

§ deleteEvent()

§ loops through the events array, searching for event by the date.

§ If the event is found, delete it and move all the event references up one, so as not to leave a null element in the middle of the array. Remove one element from the numEvents counter.

• Event has an OurDate reference, a String reference, three constructors and six methods:

§ Two overloaded setDate() methods.

§ setDescription().

§ getDate().

§ getDescription().

§ toString() - returns a String representation of the Event reference.

• OurDate has three fields, day, month and year, three constructors, and eleven methods:

§ setDay(), setMonth(), setYear(), each must verify that the day, month or year respectively is valid.

§ getDay(), getMonth(), getYear(), returns day, month or year, respectively.

§ isEqual() - compares two dates to see if they are equal..

§ toString() - returns a String representation of the OurDate reference.

§ addOne() – adds one day to the current date, checks for boundaries such as last day month, year, etc..

§ isLeapYear() - determines if the year specified is a leap year or not – you may use an existing algorithm (found online ?) for this, BUT…be certain to reference the source in a comment.

§ calculateDays() - calculates the amount of days from a base year (in this case January 1, 2000) to the date specified. Invokes the isLeapYear() method.

Heres how it should be formatted (Program Design) –

Assign1 class

+main(args: String[]): void

Planner class

-        MAXEVENTS: int = 10(readonly)

-        Events: Event{}

-        numEvents: int

-        date:OurDate

+Planner()

+runMenu(): void

+addEvent(): void

+enterDate(): void

+displayOneDay(): void

+displaySevenDays(): void

+deleteEvent(): void

OurDate Class

-        day: int

-        month: int

-        year: int

+OurDate()

+OurDate(day: int, month: int, year: int)

+OurDate(date: OurDate)

+getDay(): int

+getMonth(): int

+getYear(): int

+setDay(day: int): void

+setMonth(month: int): void

+setYear(year: int): void

+isEqual(date: OurDate): Boolean

+addOne(): void

+toString(): String

+calcDays(date :OurDate): int

+isLeapYear(year :int): Boolean

Event Class

-        date: OurDate

-        description: String

+Event()

+Event(date: OurDate, description: String)

+Event(day: int, month: int, year: int description: String)

+setDate(date: OurDate): void

+setDate(day: int, month: int, year: int): void

+setDescription(description: String: void)

+getDate():OurDate

+getDescription(): String

+toString (): String

Sample Program Run (user inputs):

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 1

Enter event description: rock concert

Enter event date: Enter year: 2015

Enter month: 3

Enter day: 4

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 1

Enter event description: work

Enter event date:

Enter year: 2015

Enter month: 3

Enter day: 3

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 1

Enter event description: dinner at folks

Enter event date:

Enter year: 2015

Enter month: 3

Enter day: 5

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 1

Enter event description: movie night

Enter event date:

Enter year: 2015

Enter month: 3

Enter day: 4

You already have an activity for that date and time...cannot be entered

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 2

Enter date to display:

Enter year: 2015

Enter month: 3

Enter day: 5

Your events for 2015/3/5 are:

2015/3/5 - dinner at folks

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 3

Enter starting date to display:

Enter year: 2015

Enter month: 3

Enter day: 1

Your events for the week starting 2015/3/1 are:

Your events for 2015/3/1 are:

Your events for 2015/3/2 are:

Your events for 2015/3/3 are:

2015/3/3 - work

Your events for 2015/3/4 are:

2015/3/4 - rock concert

Your events for 2015/3/5 are:

2015/3/5 - dinner at folks

Your events for 2015/3/6 are:

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 4

Enter date to delete event from:

Enter year: 2015

Enter month: 3

Enter day: 4

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 3

Enter starting date to display:

Enter year: 2015

Enter month: 3

Enter day: 1

Your events for the week starting 2015/3/1 are:

Your events for 2015/3/1 are:

Your events for 2015/3/2 are:

Your events for 2015/3/3 are:

            2015/3/3 - work

Your events for 2015/3/4 are:

Your events for 2015/3/5 are:

2015/3/5 - dinner at folks

Your events for 2015/3/6 are:

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit: 0

Goodbye

Explanation / Answer

Note:

            The given methods and variable names are used without any changes.

Program:

// import require packages

import java.io.*;

import java.util.*;

// class assign to with main method

public class Assign2

{

     // main method

     public static void main(String[] args)

     {

          Scanner input = new Scanner(System.in);

          Planner activity = new Planner();

          OurDate date = new OurDate();

          String Iopt = "1";

          String desc;

System.out.println("Welcome to your Activity Planner!");

          while (Integer.parseInt(Iopt) != 0)

          {

              do

              {

                   activity.runMenu();

                   Iopt = input.nextLine();

              } while (Integer.parseInt(Iopt) < 0 || Integer.parseInt(Iopt) > 4);

             

              switch(Iopt) {

                   case "1": // Code for an activity to the planner

                   System.out.println("Enter event description:");

                   desc=input.nextLine();

                   activity.enterDate();

                  

                   break;

              case "2": // Code for display activities of one day

                   activity.enterDate();

                   activity.displayOneDay();

                   break;

              case "3": // Code for display activities of seven days

                   activity.enterDate();

                   activity.displaySevenDays();

                   break;

              case "4": // Code to delete an event at a date and time

                   activity.enterDate();

                   activity.deleteEvent();

                   break;

              }

          }   

          if (Integer.parseInt(Iopt) == 0)

          {

              System.out.print("Goodbye.");

          }

     }

}

// OurDate.java

//class ourData

class OurDate{

     //Declare the required variables

   int day;

   int month;

   int year;

   // constructor

   public OurDate()

   {

       day = 1;

       month = 1;

       year = 2000;

   }

   // constructor

   public OurDate(int day, int month, int year)

   {

       day = day;

       month = month;

       year = year;

   }

   // constructor

   public OurDate (OurDate date)

   {

          day = date.day;

          month = date.month;

          year = date.year;

   }

     // method to set day

   public void setDay(int day)

   {

       if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)

        {

           if(day > 31 || day <= 0) day = 1;

           else day = day;

       }

       else if(month == 2)

        {

           if(year % 4 == 0)

             {

               if(day > 29 || day < 0) day = 1;

               else day = day;

           }

           else

             {

               if(day > 28 || day < 0) day = 1;

               else day = day;             

           }

       }

       else

        {

           if(day > 30 || day <= 0) day = 1;

           else day = day;

       }

   }

   // method to set month

     public void setMonth(int month)

     {

       if(month > 12 || month < 0) month = 1;

       else month = month;

    }

   // method to set year

     public void setYear(int year)

     {

       year = year;

     }

   // method to get day

   public int getDay(){ return day; }

   // method to get month

   public int getMonth(){ return month; }

   // method to get year

   public int getYear(){ return year; }

   // method to check date is equal

   public boolean isEqual(OurDate date)

   {

       if(day == date.day && month == date.month && year == date.year) return true;

       else return false;

   }

   // method to print the date

   public String toString(){ return year + "/" + month + "/" + day; }

   // method to addOne

   public void addOne(){

       day++;

       if(month == 2){

           if(year % 4 == 0){

               if(day == 30){

                   month++;

                   day = 1;

               }

           }

           else{

               if(day == 29){

                   month++;

                   day = 1;

               }              

           }

           if(month == 13){

               month = 1;

               year++;

           }

       }

       else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){

           if(day == 32){

               month++;

               day = 1;

           }

           if(month == 13){

               month = 1;

               year++;

           }         

       }

       else{

           if(day == 31){

               month++;

               day = 1;

           }

           if(month == 13){

               month = 1;

               year++;

           }

       }

   }

   // method to check year is leaf year

   public boolean isLeapYear(int year){

       if(year % 4 == 0) return true;

       else return false;

   }

   // method to calculateDays

   public int calculateDays(){

       int num = 0;

       for(int li = 2000; li < year; li++){

           if(li != year){

               if(isLeapYear(li)) num += 366;

               else num += 365;

           }

           else{

               if(month <= 1) num += 31;

               if(month <= 2){

                   if(isLeapYear(li)) num += 29;

                   else{

                       num += 28;

                   }

               }

               if(month <= 3) num += 31;

               if(month <= 4) num += 30;

               if(month <= 5) num += 31;

               if(month <= 6) num += 30;

               if(month <= 7) num += 31;

               if(month <= 8) num += 31;

               if(month <= 9) num += 30;

               if(month <= 10) num += 31;

               if(month <= 11) num += 30;

               if(month <= 12) num += 31;

           }

       }

       return num;

   }

}

// Event.java

//class Event

class Event{

     //declare the required variables

   OurDate date;

   String description;

// constructor

   public Event() { }

   // constructor

     public Event(OurDate date,String description)

     {

          date=date;

          description=description;

     }

     // constructor

     public Event(int day,int month,int year, String description)

     {

          date.day=day;

          date.month=month;

          date.year=year;

          this.description=description;

     }

     // method to set the date

   public void setDate(OurDate date){

       date = date;

   }

   // method to set the date

   public void setDate(int day,int month,int year)

     {

          date.day=day;

          date.month=month;

          date.year=year;

     }

     // method to set the description

   public void setDescription(String day){

       description = day;

   }

   // method to get the date

   public OurDate getDate(){

       return date;

   }

   // method to get the description

   public String getDescription(){

       return description;

   }

   // method to print the content

   public String toString(){

       return "Your events for " + date + " are: " + date + " - " + description;

   }

}

// Planner.java

//class planner

class Planner

{

     // declare the required variables

   int MAXEVENTS=10;

   Event Events[];

   int numEvents;

   OurDate date;

   //constructor

   public Planner()

   {

       Events = new Event[10];

   }

   // method to display run menu

   public void runMenu(){

       while(true){

           int choice;

           System.out.println("Make a selection:");

           System.out.println("1. Add event to planner");

           System.out.println("2. Display event for a day");

           System.out.println("3. Display events for a week");

           System.out.println("4. Delete an event");

           System.out.print("0 to quit: ");

           Scanner in = new Scanner(System.in);

           choice = in.nextInt();

           if(choice == 0) break;

       }

   }

   // method to add Event

   public void addEvent(Event e){

       for(int li = 0; li < numEvents; li++){

           if(Events[li].getDate().equals(e.getDate())){

               System.out.println("You already have an activity for that date and time...cannot be entered");

               return;

           }

       }

       Events[numEvents++] = e;

   }

   // method to enter date

   public void enterDate(){

       Scanner in = new Scanner(System.in);

       OurDate x = new OurDate();

       System.out.print("Enter event date: ");

       System.out.print("Enter year: ");

       x.year = in.nextInt();

       System.out.print("Enter month: ");

       x.month = in.nextInt();

       System.out.print("Enter day: ");

       x.day = in.nextInt();

       date = x;

   }

   // method to display one day

   public void displayOneDay()

   {

       for(int li = 0; li < numEvents; li++){

           if(Events[li].getDate().equals(date)){

               System.out.println(Events[li]);

           }

       }     

   }

   // method to displaySevenDays

   public void displaySevenDays() {

          System.out.println("Your activities for the week starting " +date.toString() +" are: ");

          for (int li = 0; li < 7; li++) {

              displayOneDay();

              date.addOne();

          }

     }

     // method to delete the event

     public void deleteEvent() {

          boolean booleanFoundEvent = false;

          int li;

          // code to search the activity and it is found then it set as true

          for (li = 0; li < numEvents; li++) {

              if (Events[li].getDate().isEqual(date)) {

                   booleanFoundEvent = true;

                   break;

              }

          }

          // code to delete that index from the array,

          if (booleanFoundEvent){

              Events[li] = Events[numEvents - 1];

              numEvents--;

              System.out.println("Activity deleted. That date and time slot is now free.");

          }

          else {

              System.out.println("There is no activity for that date and time!");

          }

     } // end method deleteEvent

}

Result:

Welcome to your Activity Planner!

Make a selection:

1. Add event to planner

2. Display event for a day

3. Display events for a week

4. Delete an event

0 to quit:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote