Question

PART B: DATE BOOK A classic computer application is the electronic date book: a list of daily events stored in a calendar. Write a Java program that can be used as a simple date book. The date book will use a separate array for each month of the year, with one array entry for each day in the month (0 = first day of the month, 1 = second day of the month, etc.). The date book is simple because at most one event will be allowed on each day Your program should include an Event class that will be instantiated for each event in the date book. The Event class consists of three instance variables: the starting time of the event (a String), the name of the event (a String), and the priority of the event (an integer value in the range 1-3, with 3 being the highest priority). Make all your instance variables private and write appropriate instance methods for processing them, including a constructor, toString), and any others needed by your program Each month in the date book will be stored as an array of Events. Days with an event will point to the appropriate Event object, and days without will contain nll Your program will produce three types of output (three views) for each month . A calendar view, listing the days of the week (Sunday to Saturday) horizontally across the top, and the days of the month underneath. Next to each day where there is a scheduled event, print an asterisk . Like in a real calendar, the first day of the month can be any of the weekdays the order that they occur during the month. Do not display lines of output for days without events priority .A list of events, showing the day of the month and the details of the event (using toString). These can be displayed in . A list of the highest-priority events (those with priority 3). List only the names of the events, not the starting time or

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Here the two classes "Event.java" and "DateBook.java":

Event.java:

public class Event {

private String StartingTime;

private String Name;

private int Priority;

public String getStartingTime() {

return StartingTime;

}

public void setStartingTime(String startingTime) {

StartingTime = startingTime;

}

public String getName() {

return Name;

}

public void setName(String name) {

Name = name;

}

public int getPriority() {

return Priority;

}

public void setPriority(int priority) {

Priority = priority;

}

}



DateBook.java:

import java.util.ArrayList;

import java.util.Collections;

public class DateBook {

public static void main(String[] args) {

Event[] september = new Event[30];

Event[] october = new Event[31];

int startingDayOfSeptember = (int)(Math.random()*6);

int startingDayOfOctober = (startingDayOfSeptember+30)%7;

showEvents(september, startingDayOfSeptember);

System.out.println("\n\n");

showEvents(october, startingDayOfOctober);

}

public static void showEvents(Event[] month, int startingDay)

{

String[] nameOfEvents = {"Birthday","Anniversary","Marriage","Engagement"};

int temp=0;

//Get the unique dates for events

ArrayList<Integer> list = new ArrayList<Integer>();

for (int i=0; i<month.length; i++) {

list.add(new Integer(i));

}

  

Collections.shuffle(list);

for (int i=0; i<10; i++) {

int eventDate = list.get(i); // event date

month[eventDate]= new Event();

month[eventDate].setName(nameOfEvents[(int)(Math.random()*3)]+" #"+((int)(Math.random()*100)+1));

month[eventDate].setStartingTime(((int)(Math.random()*12)+1)+":00 PM");

month[eventDate].setPriority((int)(Math.random()*3+1));

}

  

//Print Calendar

System.out.println("Sun\tMon\tTue\tWed\tThu\tFri\tSat");

for (int i=0; i<month.length; i++) {

if(i < startingDay)

{

System.out.print("\t");

temp++;

continue;

}else

break;

}

  

int tempBreakLine = temp;

for (int i=0; i<month.length; i++) {

tempBreakLine++;

if(month[i]!=null)

{

System.out.print(i+1+"*\t");

}

else{

System.out.print(i+1+"\t");

}

if(tempBreakLine%7 == 0) {System.out.println();}

}

  

System.out.println("\n");

System.out.println("Events:");

for (int i=0; i<month.length; i++) {

if(month[i]!=null)

{

System.out.print((i+1)+": "+ month[i].getStartingTime()+": "+month[i].getName()+": (priority "+month[i].getPriority()+")");

System.out.println();

}

}

  

System.out.println();

System.out.println("High-priority events:");

for (int i=0; i<month.length; i++) {

if(month[i]!=null && month[i].getPriority() == 3)

{

System.out.print((i+1)+": "+month[i].getName());

System.out.println();

}

}

}

}


OutPut:

Problems@ JavadocDeclaration Console 3 <terminated> DateBook Java Application] CProgram Files Jarel.8.0 1111binljavaw.exe (Oc17 24* 31 18* 25 19 26* 20 27 21* 28 22* 29 23 30* Events: 5: 7:00 PM: Marriage #5: (priority 1) 10: 12:00 PM: Marriage #46:

Add a comment
Know the answer?
Add Answer to:
PART B: DATE BOOK A classic computer application is the electronic date book: a list of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • Create a class called Date212 to represent a date. It will store the year, month and...

    Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...

  • In C++ array. It should use an int numEvents' to keep track of how many events have been entered in the array. An event should be represented by a struct with several member variables. An event S...

    In C++ array. It should use an int numEvents' to keep track of how many events have been entered in the array. An event should be represented by a struct with several member variables. An event Strings for a name, description, and notes A date and time represented by their own structs. The Date struct should contain an int day, string month, and int year, and the Time struct should contain an int hour, int minute, int second, and bool...

  • Design "MyWeek" class: (1) Data members: the class contains one private data field weekList. "wee...

    Design "MyWeek" class: (1) Data members: the class contains one private data field weekList. "weekList" has datatype of ArrayList, which will contain String objects of week/weekend days. There are no duplicated days in the list. Valid days are "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun". The weekList is not necessarily to be ordered (2) Constructors The instance of MyWeek can be constructed with (a) no argument (initialized weekList to empty), or (b) with one String argument which is one valid...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete...

    Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete the exercise. Make sure that you follow the Program Style and Readability guidelines found in the Start Here Folder. 1. Write a Point class. The Point class should be written as an abstract data type. 2. Include the following instance variables: a. an integer representing the x coordinate b. an integer representing the y coordinate c. The instance variables in your program should only...

  • //Please help me out with this problem.. This problem has to be done in C++ and...

    //Please help me out with this problem.. This problem has to be done in C++ and has to strictly follow the instructions... I have given the expected output of the problem below.   1) Design a class Date: Provide 3 instance variables (int) to store the month, the day number, and the year Provide the following functions Default constructor -sets date to, 1500 Constructor with parameters - if parameters are not valid, set like default constructor setDate if parameters are not...

  • In this hormework, you will implement a simple caledar application The implernentation shauld inc...

    Do that with C++ and please add more comment that make it understandable In this hormework, you will implement a simple caledar application The implernentation shauld include a class narned Calendar, an abstract class named Event and two concrete classes narmed Task and Appointment which irherit from the Evernt class. The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which desigate the tirne of the event. It...

  • Need Help finishing up MyCalendar Program: Here are the methods: Modifier and Type Method Desc...

    Need Help finishing up MyCalendar Program: Here are the methods: Modifier and Type Method Description boolean add​(Event evt) Add an event to the calendar Event get​(int i) Fetch the ith Event added to the calendar Event get​(java.lang.String name) Fetch the first Event in the calendar whose eventName is equal to the given name java.util.ArrayList<Event> list() The list of all Events in the order that they were inserted into the calendar int size() The number of events in the calendar java.util.ArrayList<Event>...

  • **Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class...

    **Only need the bold answered Implement the Athlete, Swimmer, Runner, and AthleteRoster classes below. Each class must be in separate file. Draw an UML diagram with the inheritance relationship of the classes. 1. The Athlete class a. All class variables of the Athlete class must be private. b.is a class with a single constructor: Athlete(String lName, String fName, int birthYear, int birthMonth, int birthDay, char gender). All arguments of the constructor should be stored as class variables. There should only...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT