Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to build upon your calendar from Assignment 1 to fix a few things and add more functionality to your program. (****************************************** HERE

Your task is to build upon your calendar from Assignment 1 to fix a few things and add more functionality to your program.

(****************************************** HERE IS ASSIGNMENT 1 THAT WE ARE ADDING TO:

Your task is to make a basic calendar using Java. Over the course of the quarter, we will be adding to this very basic calendar to make it more functional and robust. For this part, you will be drawing the calendar to the console. The calendar's size should be scalable using class constants. You have some creative freedom with designing the calendar. What characters you use for the outline of the calendar and where you place the date in each calendar cell is up to you. An example of what a calendar might look like with a size of 10 after completing this assignment is on the next page. Functional Rundown: Upon executing your program, the console should ask what date you would like to look at, as seen in the example below. The user should be able to input a date. The month of that date should be displayed at the top of the calendar. The month and day input by the user should be broken up and displayed at the bottom of the calendar as shown below. After asking the user for a date and printing the calendar for that date, your program should print a calendar for today's date followed by the month and day broken up. Ultimately, after execution, your calendar should display a prompt to get a date from the user, a calendar for that month from the user input, the month and day input by the user broken up, a second calendar for the current month, and finally the month and day for the current day broken up. For now, you may have every month that the calendar displays have 35 days instead of the actual number. We will change that in a later part of the assignment. Example Run: Scalability: Your program should produce output like this if the size is 10. However, as stated above, you have the freedom to choose what characters you use for the calendar (the "|" and "=" in the example above) and the exact location of the number in each cell. Below is an example of a calendar produced with a size of 5: Creative Portion: In addition to the functionality of the calendar, your calendar should display some text art (ACSII art) above the calendar, like what you would see with a typical wall calendar. You have the freedom to choose what you display with these restrictions: The ACSII art should be your own creation, not something found on the internet or elsewhere You should make use of for loops to make your design and reduce redundancy within its code, but make sure there are no infinite loops The picture should be appropriate and not include hateful, offensive, or inappropriate images You should not use advanced material beyond what we have learned in class so far For this portion of the assignment, you will get credit for completing something that demonstrates you have put some effort into it. If you follow the guidelines above and have demonstrated in your code that you have put a decent amount of effort into it, you will receive full points for the creative portion of the assignment. Additional information about ASCII art can be found online by googling "ASCII art." Implementation Details: You program must include the following methods: public static void drawMonth(int month) This method takes in an integer representing the month and displays the month and a graphical representation of the calendar as seen in the examples above. public static void drawRow(int row) This method should be called in your drawMonth method. It should display one week on the calendar (one row). This method is passed an integer representing which row it is displaying. public static void displayDate(int month, int day) This method is passed the month and the day as integer values and displays the date information as seen in the above example underneath the graphical representation of the calendar. public static int monthFromDate(String date) This method should extract an integer value for the month and return it when passed a given date as a String. Using the indexOf and substring methods may be helpful with this. public static int dayFromDate(String date) This method should extract an integer value for the day and return it when passed a given date as a String. Using the indexOf and substring methods may be helpful with this. Helpful Information: For this assignment, you may want to use a few tools that we have not gone over in class. To get today's date, you will likely want to make use of a Calendar object that is already implemented by Java. This object stores basic information that we can access. To use this object, you will want to make a new Calendar object (be careful that your class is also not named Calendar or Java will get confused). The code for that would look like Calendar name = Calendar.getInstance(). This gets the current date and stores it in this Calendar object. To access the information we want, we need to use the Calendar's get method. For instance, if we wanted the month we would use name.get(Calendar.MONTH), or if we wanted the day we would use name.get(Calendar.DATE). Calendar.MONTH and Calendar.DATE are just ways to refer to the locations where those values are stored. You also may make use of several String methods. The indexOf and substring methods could be of use. The indexOf method finds the index of the first occurrence of the given character in the String you call the method on. For example, if we had "Hello" store in a variable x, calling x.indexOf("l") would return a value of 2 since the first "l" is located at index 2 in the String "Hello". The substring method makes a new string from the starting index given to the ending index given (it does not include the character in the ending index). If not ending index is given, then a substring from the beginning index to the end of the String is made. If we wanted a substring of "Hello" that just captured "ell" and if "Hello" was stored in variable x, we could call x.substring(1, 4). If we wanted just "llo", we could call x.substring(2). Finally, you may find it useful to convert a number as a String into an integer value. To get this done, we can call Integer.parseInt(String), where String is the String value of the integer we want. I strongly encourage you to tackle this assignment in parts and practice iterative design. Work on a few things and then test them to make sure they work. Then, add some more and test those. Make sure that you come up with a plan before you start coding. Writing pseudocode can also be very helpful. I encourage you to speak with your classmates about your development plan for this assignment. I am also available to discuss how you might approach this assignment. Feel free to reach out to me with any questions or concerns. Style: It is important that you get used to writing code in good style. What is demonstrated in examples in class is considered good style. Additionally, you should look at the style guide located on Canvas. Code written not in good style will lose points. Extra Credit Opportunities (Optional): You can choose to do as many or as few of these as you would like. Each one completed successfully and in good style will earn some extra credit points towards this assignment. 1. As stated above in the specification, you can allow your calendar run to 35 days. For an added challenge, you can limit the number of days to 31. Completing this task successfully and in good style will result in extra credit. 2. If your accii art is truly remarkable, Additional extra credit may be awarded. The complexity, uniqueness, and apparent time commitment poured into the art will be taken into consideration. In CAS123A there are a few examples hanging on the wall.)

********************************************************************************************

Back to the final look for this assignment, continued from the first sentence:

Over the course of the quarter, we will be adding to this calendar to make it more functional and robust. For this part, you will be adding more functionality to make it more usable and user friendly. At the end of this assignment, your calendar should still work as intended for Assignment 1, but will additionally add other features and fixes. The first part of this assignment will be to add a user menu. The user of your program should be able to interact with your program through the console. You should include these commands for the user: "q" to quit the program, "n" to display the next month, "p" to display the previous month, "e" for the user to enter a date and display the calendar for that month, "t" to get today's date and display a calendar for this month. To implement this user menu, you will need to have a while loop in your main. If the user enters an unknown command, your program should prompt them to enter a valid command. An image of the menu and the behavior for unknown commands is to the right: If the user has not already displayed a month, the next month and previous month commands should tell the user that they need to have a calendar displayed first. Your program should not crash in this instance. Additionally, if the calendar displayed is 12 or 1 and next month or previous month are called, your calendar should proceed accordingly wrapping around to 1 and 12 like a regular calendar would. The user should be able to select several different commands in one run of your program. After each command is finished running, the menu should be displayed again and wait for the user's next command. This should continue until the user selects "q" to quit the program. In addition to the menu, you should add a few fixes to our first calendar. At the end of this assignment, your calendar should display the correct number of days for each month. Also, each month displayed should start on the correct day of the week. For example, if you were printing out the calendar to display June, June 1 st should start on Friday. As the user enters a specific date and today is a specific date, your calendar should also have some sort of indication on the user's date or today (depending on what command the user gave). You might draw something in the cell to indicate that date or write "date" in the cell. It is up to you how you provide the indication of the date, but some sort of visual indication must be made in the cell of the specific date. Implementation Details: Your program should include all the methods from the previous assignment. You may introduce your own new methods as well. You will need to modify some of the methods you have written to add the new functionality for this assignment. You may use different parameters and returns the methods. Much of this assignment will consist of modifying your previous code to add the new functionality. Helpful Information: For this assignment, you may want to use a few tools that we have not explicitly gone over in class. To get today's date, you will likely want to make use of a Calendar object that is already implemented by Java. This object stores basic information that we can access. To use this object, you will want to make a new Calendar object (be careful that your class is also not named Calendar or Java will get confused). The code for that would look like Calendar name = Calendar.getInstance(). This gets the current date and stores it in this Calendar object. To access the information we want, we need to use the Calendar's get method. For instance, if we wanted the month we would use name.get(Calendar.MONTH), or if we wanted the day we would use name.get(Calendar.DATE). Calendar.MONTH and Calendar.DATE are just ways to refer to the locations where those values are stored. You also may make use of a number of String functions. The indexOf and substring methods could be of particular use. The indexOf method finds the index of the first occurrence of the given character in the String you call the function on. For example, if we had "Hello" store in a variable x, calling x.indexOf("l") would return a value of 2 since the first "l" is located at index 2 in the String "Hello". The substring method makes a new string from the starting index given to the ending index given (it does not include the character in the ending index). If not ending index is given, then a substring from the beginning index to the end of the String is made. If we wanted a substring of "Hello" that just captured "ell" and if "Hello" was stored in variable x, we could call x.substring(1, 4). If we wanted just "llo", we could call x.substring(2). Finally, you may find it useful to convert a number as a String into an integer value. To do this, we can call Integer.parseInt(String), where String is the String value of the integer we want. I strongly encourage you to tackle this assignment in parts and practice iterative design. Work on a few things and then test them to make sure they work. Then, add some more and test those. Make sure that you come up with a plan before you start coding. Writing pseudocode can also be very helpful. I encourage you to speak with your classmates about your development plan for this assignment. I am also available to discuss how you might approach this assignment. Feel free to reach out to me with any questions or concerns. Style: It is important that you get used to writing code in good style. What is demonstrated in examples in class is considered good style. Additionally, you should look at the style guide located on Canvas. Code written not in good style will lose points. You should not be using any global variables for this assignment. You also should not be using any additional features of Java's Calendar object other than those described in the helpful information section. Specifically, you should not be using Java's Calendar object to determine how many days are in a particular month or to determine what day of the week a particular month starts on. You may not use material beyond Chapter 5 for this assignment. You may make use of the tools we have learned up through Chapter 5 and those stated in the Helpful Information section on this specification. String, Math, Scanner and other objects and their functionality that we have gone over in class and that are covered in the book through Chapter 5 are acceptable to use. Advanced material and material not within this scope will lose points. Extra Credit Opportunities (Optional): You can choose to do as many or as few of these as you would like. Each one completed successfully and in good style will earn some extra credit points towards this assignment. 1. For extra credit, you may produce a different ASCII art for each month displayed. To receive this extra credit, every month must have a different piece of ASCII art. This should work with the previous and next month commands that the user chooses as well. 2. Users don't like programs that crash and don't function properly even if they misuse your program. For extra credit, you may ensure that the user can't crash your program based on their user input for the date. This means that you will need to check the format and validity of the date entered. If the date format is not valid or if it is not a valid date, you should prompt the user to enter a new valid date in the correct format and not alow your program to crash or behave improperly.

Step by Step Solution

3.45 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

Heres the improved Java code for your calendar program with user menu date handling and visual indication Java import javautilCalendar import javautil... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Science The Art Of Modeling With Spreadsheets

Authors: Stephen G. Powell, Kenneth R. Baker

4th Edition

978-1118517376, 9781118800348, 1118517377, 1118800346, 978-1118582695

More Books

Students also viewed these Programming questions