Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A) Read aloud 1. Add notes - Fit to width CD Page view of 5 Introduction The goal of this project is to develop a
A) Read aloud 1. Add notes - Fit to width CD Page view of 5 Introduction The goal of this project is to develop a nontrivial computer program in the Java language by ap- plying elementary programming language concepts learned in Programming I (or an equivalent first programming course). Specifically, the concepts to be used for this project include: simple input/output, selection, and iteration (loops). Do not use arrays. Developing a Java Program for Printing a Calendar Statement of Problem: Develop a Java program to print a calendar for the year that the user will provide as input to the program. Use the Eclipse IDE (on a Windows or Mac machine). Your program must fulfill the following requirements: 1. Your program should prompt and receive as input an integer value representing the year for which the user wishes to have a calendar printed. 2. However, this integer must be in the range from 1780 through 2040. 3. In case the user input a year that is outside this range, your program must print out a message such as "Invalid year. Please input an integer in the range 1780 through 2040." The program must do this repeatedly if necessary until the user provides an acceptable input. 4. Each month of the year must be printed out with proper labels for the week days and the dates aligned properly under the appropriate labels. For your reference, please see the sample output below for the month of May 2019. January 2020 Sun Mon Tue Wed Thu Fri Sat 8. 10 11 12 13 14 15 16 17 18 23 24 19 20 21 25 26 27 28 29 30 31 5. Of course, your program must print out all 12 months of the year specified. Each month must be printed directly below the previous month. 6. The deliverable for this task is your source code file named MyCalendar.java. This document must be submitted on Canvas. CB Page view A of 5 1. Add notes -- Fit to width of 5 Read aloud Page 2 Programming I Project-2 Java Program for Printing a Calendar: Analysis and Design Creating a working program is an iterative process. You may have to repeatedly make changes in your source code for removing syntax errors to begin with. Then you may need to make changes that will address any logical errors that you detect based on the results you obtain. Thus, I would recommend developing your code incrementally. Incremental development would mean writing a few lines of code at a time to complete a simple task that forms part of your final solution and running the program to make sure that those lines of code work. This way, if at any time you add something new an error pops up, you will be able to focus your attention on the latest addition in your code. In essence, you will be dividing the given problem into sub-problems first and solve the sub-problems one by one. This requires carrying out a careful analysis of the problem, followed by an appropriate design formulation for your solution. For this project, the following hints will help in the analysis of the problem so that you are able to appreciate the resulting design and build your code. Another way to look at this is that the analysis will provide an idea of how you may split your task of creating the program into several sub-tasks. Writing code that will help complete each of these sub-tasks in order will amount to incrementally developing the required program. 1. From the sample month shown, it is clear that we need the following information about each month in order to print it properly: a. The day of weck on which the first day on the month falls; and b. The number of days in the month. 2. The number of days in each month is a known quantity, independent of the year, except for February. February has either 28 days or 29 days, depending on whether the given year is a leap year or not. 3. Suppose the year user input is 2016. Then, we need to first figure out on which day of the week did January 1, 2016 fall. Using a formula which we will provide later, we can figure out that January 1, 2016 was a Friday. 4. The above information, coupled with the fact that the month of January has 31 days, will help us figure out that February 1, 2016 was a Monday. Since 2016 is a leap year, the month of February had 29 days. This leads us to the correct conclusion that March 1, 2016 was a Tuesday. 5. The above discussion and the statement of the problem at the beginning have already helped us understand that the following sub-problems need to be handled in the Java code. O Page view A 1. Add notes -- Fit to width of 5 of 5 Read aloud 5. The above discussion and the statement of the problem at the beginning have already helped us understand that the following sub-problems need to be handled in the Java code. a. Prompt the user and receive an input integer representing the year. If the year entered is not in the range from 1780 through 2040, print out a message requesting the user to enter a year in the permissible range. Repeat this until the user inputs an acceptable year. b. Figure out the day of week for January 1 of the input year. For this, with y representing the year input, you will use the following formula: y mod 100 d = ( 28 + y mod 100 + mod 7 4 School of Computing University of North Florida Dr. Asaithambi Programming I Project-2 Page 3 Note that in the above formula, the bracket-like enclosures ([ and ) correspond to the floor function. A result of d = 0 from the above calculation corresponds to Sunday, d = 1 corresponds to Monday, etc., until d = 6 for Saturday. Note that if the above formula yields a negative number as answer, you need to add 7 to the answer to make it an acceptable day of the week. 2000, We obtain For instance, let us consider the year 2000. In other words, y 2000 mod 100 1 (28 ) 2000 2000 d = ( 28 + 2000 mod 100 + mod 7 400 100 + [5] 2(20) = ( 28 +0+ mod 7 = (28 1+5 40) mod 7 = -8 mod 7 = 6 = Saturday A - Fit to width D Page view 1. Add notes of 5 of 5 Read aloud -8 mod 7 = 6 = Saturday c. For each month from January to December (say 1 to 12), print out the calendar for the month, by carrying out the following steps: c.1 Depending on the month, figure out the total number of days to be printed accord- ing to: 31 days in January, March, May, July, August, October, and December; 30 days in April, June, September, and November; and 29 or 28 days in February, depending on whether y represents a leap year or not. c.2 Note that for January 1, the value of d calculated previously will tell you exactly under which column the date January 1 needs to be printed. For instance, if d = 3, then it means January 1 should be a Wednesday. The first row for January in this case will print blanks under Sunday, Monday, and Tuesday, and 1 under Wednesday. This would also mean that the Saturday for the first week will be on the 4th. The second row will then start with the 5th etc. The logic of your program has to be able to handle this uniformly for all months subsequently as well. c.3 For this situation, when January 1 is a Wednesday, the 31st of January will be a Friday. This will tell you that February 1 is a Saturday. In the same manner, the starting day of the week for March can be figured out. This is how the calendar for the entire year can be printed if the day of the week corresponding to January 1 is calculated first. Step-By-Step Instructions for the Initial Setup on Eclipse for the Calendar Program 1. Choose File, New, and Java Project. 2. Type a name like Calendar Project in the Project Name field. 3. Click Finish to create the project. A project named Calendar Project is created. 4. Creating a Class. Choose File, New, and Class. 5. Type MyCalendar in the Name field. 6. Check the option public static void main(String[] args). 7. Click Finish to generate the template for the source code MyCalendar.java. 8. Enter (type the lines of) the source code for MyCalendar.java. Dr. Asaithambi School of Computing University of North Florida -- Fit to width A O Page view 1. Add notes of 5 of 5 Read aloud 9. Compiling and Running. To run the program, click on the icon that looks like the play button on an audio device. The program should be run on the Console pane within the Eclipse IDE and the output displayed there. Code Template for MyCalendar.java import java.util. Scanner; public class MyCalendar { public static void main ( String [] args) { // Stage 1: Enter code for receiving year in the range // 1780 // range year is entered, until the user inputs an // acceptable year. This should be a loop. Check whether // this works before you start to 2040. Prpt again and again if an out of the next stage. // Stage 2: Use the formula for d given above to figure // out the day of the week for January 1 of the given // year. This is // produces the correct result for different input values // for the year at this stage. For instance, if year is // 2000, d should be 6 (Saturday); if year is 2019, d // should be 2 (Tuesday); if year is 2015, d should be // 4 (Thursday), etc. Check whether this works before // you start a crucial step. Check whether your code the next stage. // Stage 3: Write a loop with index ranging from 1 to 12 // and print one month of the calendar at a time, starting // with January, and ending in December. // // Stage 3.1: Print the name of the month and figure out // the number of days in the month. You need to use a // switch for this purpose. Check whether this works // before you start the next stage. // Stage 3.2: You will print out the header showing the // labels Sun, Mon, Tue, etc. -- Fit to width A Read aloud 1. Add notes CB Page view of 5 of 5 // Stage 3.1: Print the name of the month and figure out // the number of days in the month . You need to use a // switch for this purpose. Check whether this works // before you start the next stage. // Stage 3.2: You will print out the header showing the // labels Sun, Mon, , etc. // Stage 3.3: Print the calendar for the current month. // Check whether this works for one month at a time. Note // that Stages 3.1, 3.2, and 3.3 are inside the loop // started at Stage 3. } School of Computing University of North Florida Dr. Asaithambi Programming II Project-2 Page 5 Note that in Stage 3.3, you will need a system of nested loops as the calendar for each month has rows and columns. Additionally, you will first print the calendar for January. The calendar for February will be placed vertically below the calendar for January; March below February; April below March; May below April; June below May; July below June; August below July; September below August; October below September; November below October; and December below November. For your reference, I provide below the calendar for the first three months of 2020. Keep in mind that all of the above discussions, the template, and the sample output are provided as guidance, and not all the details have been covered. It is your responsibility to make sure that the calendar you produce looks like the one shown in the sample output for all 12 months. The details are left for you to figure out and complete as part of the project. CB Page view A of 5 - Fit to width 1. Add notes of 5 Read aloud The details are left for you to figure out and complete as part of the project. January 2020 Sun Mon Tue Wed Thu Fri Sat 7 8 9 10 13 14 15 16 17 18 20 21 22 23 24 11 12 19 25 26 27 28 29 30 31 February 202o Sun Mon Tue Wed Thu Fri Sat 9 10 11 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 29 21 22 March 2020 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 1 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Step-By-Step Instructions for Canvas Submissions You will submit on Canvas the MyCalendar.java file consisting of your program source code. If you click on Assignment P-02, Canvas would provide an option for you to submit your assign- ment including any attachment to be uploaded. You will submit by navigating to the src folder within your project work space for the program (the MyCalendar.java file) you created on Eclipse. Submission of the MyCalendar.java file will be necessary to complete the project. IMPORTANT: There is a grading rubric provided on Canvas for this project. Review this rubric both before you begin and just before you are ready to submit and make sure that your submission will get the maximum possible points. School of Computing University of North Florida Dr. Asaithambi A) Read aloud 1. Add notes - Fit to width CD Page view of 5 Introduction The goal of this project is to develop a nontrivial computer program in the Java language by ap- plying elementary programming language concepts learned in Programming I (or an equivalent first programming course). Specifically, the concepts to be used for this project include: simple input/output, selection, and iteration (loops). Do not use arrays. Developing a Java Program for Printing a Calendar Statement of Problem: Develop a Java program to print a calendar for the year that the user will provide as input to the program. Use the Eclipse IDE (on a Windows or Mac machine). Your program must fulfill the following requirements: 1. Your program should prompt and receive as input an integer value representing the year for which the user wishes to have a calendar printed. 2. However, this integer must be in the range from 1780 through 2040. 3. In case the user input a year that is outside this range, your program must print out a message such as "Invalid year. Please input an integer in the range 1780 through 2040." The program must do this repeatedly if necessary until the user provides an acceptable input. 4. Each month of the year must be printed out with proper labels for the week days and the dates aligned properly under the appropriate labels. For your reference, please see the sample output below for the month of May 2019. January 2020 Sun Mon Tue Wed Thu Fri Sat 8. 10 11 12 13 14 15 16 17 18 23 24 19 20 21 25 26 27 28 29 30 31 5. Of course, your program must print out all 12 months of the year specified. Each month must be printed directly below the previous month. 6. The deliverable for this task is your source code file named MyCalendar.java. This document must be submitted on Canvas. CB Page view A of 5 1. Add notes -- Fit to width of 5 Read aloud Page 2 Programming I Project-2 Java Program for Printing a Calendar: Analysis and Design Creating a working program is an iterative process. You may have to repeatedly make changes in your source code for removing syntax errors to begin with. Then you may need to make changes that will address any logical errors that you detect based on the results you obtain. Thus, I would recommend developing your code incrementally. Incremental development would mean writing a few lines of code at a time to complete a simple task that forms part of your final solution and running the program to make sure that those lines of code work. This way, if at any time you add something new an error pops up, you will be able to focus your attention on the latest addition in your code. In essence, you will be dividing the given problem into sub-problems first and solve the sub-problems one by one. This requires carrying out a careful analysis of the problem, followed by an appropriate design formulation for your solution. For this project, the following hints will help in the analysis of the problem so that you are able to appreciate the resulting design and build your code. Another way to look at this is that the analysis will provide an idea of how you may split your task of creating the program into several sub-tasks. Writing code that will help complete each of these sub-tasks in order will amount to incrementally developing the required program. 1. From the sample month shown, it is clear that we need the following information about each month in order to print it properly: a. The day of weck on which the first day on the month falls; and b. The number of days in the month. 2. The number of days in each month is a known quantity, independent of the year, except for February. February has either 28 days or 29 days, depending on whether the given year is a leap year or not. 3. Suppose the year user input is 2016. Then, we need to first figure out on which day of the week did January 1, 2016 fall. Using a formula which we will provide later, we can figure out that January 1, 2016 was a Friday. 4. The above information, coupled with the fact that the month of January has 31 days, will help us figure out that February 1, 2016 was a Monday. Since 2016 is a leap year, the month of February had 29 days. This leads us to the correct conclusion that March 1, 2016 was a Tuesday. 5. The above discussion and the statement of the problem at the beginning have already helped us understand that the following sub-problems need to be handled in the Java code. O Page view A 1. Add notes -- Fit to width of 5 of 5 Read aloud 5. The above discussion and the statement of the problem at the beginning have already helped us understand that the following sub-problems need to be handled in the Java code. a. Prompt the user and receive an input integer representing the year. If the year entered is not in the range from 1780 through 2040, print out a message requesting the user to enter a year in the permissible range. Repeat this until the user inputs an acceptable year. b. Figure out the day of week for January 1 of the input year. For this, with y representing the year input, you will use the following formula: y mod 100 d = ( 28 + y mod 100 + mod 7 4 School of Computing University of North Florida Dr. Asaithambi Programming I Project-2 Page 3 Note that in the above formula, the bracket-like enclosures ([ and ) correspond to the floor function. A result of d = 0 from the above calculation corresponds to Sunday, d = 1 corresponds to Monday, etc., until d = 6 for Saturday. Note that if the above formula yields a negative number as answer, you need to add 7 to the answer to make it an acceptable day of the week. 2000, We obtain For instance, let us consider the year 2000. In other words, y 2000 mod 100 1 (28 ) 2000 2000 d = ( 28 + 2000 mod 100 + mod 7 400 100 + [5] 2(20) = ( 28 +0+ mod 7 = (28 1+5 40) mod 7 = -8 mod 7 = 6 = Saturday A - Fit to width D Page view 1. Add notes of 5 of 5 Read aloud -8 mod 7 = 6 = Saturday c. For each month from January to December (say 1 to 12), print out the calendar for the month, by carrying out the following steps: c.1 Depending on the month, figure out the total number of days to be printed accord- ing to: 31 days in January, March, May, July, August, October, and December; 30 days in April, June, September, and November; and 29 or 28 days in February, depending on whether y represents a leap year or not. c.2 Note that for January 1, the value of d calculated previously will tell you exactly under which column the date January 1 needs to be printed. For instance, if d = 3, then it means January 1 should be a Wednesday. The first row for January in this case will print blanks under Sunday, Monday, and Tuesday, and 1 under Wednesday. This would also mean that the Saturday for the first week will be on the 4th. The second row will then start with the 5th etc. The logic of your program has to be able to handle this uniformly for all months subsequently as well. c.3 For this situation, when January 1 is a Wednesday, the 31st of January will be a Friday. This will tell you that February 1 is a Saturday. In the same manner, the starting day of the week for March can be figured out. This is how the calendar for the entire year can be printed if the day of the week corresponding to January 1 is calculated first. Step-By-Step Instructions for the Initial Setup on Eclipse for the Calendar Program 1. Choose File, New, and Java Project. 2. Type a name like Calendar Project in the Project Name field. 3. Click Finish to create the project. A project named Calendar Project is created. 4. Creating a Class. Choose File, New, and Class. 5. Type MyCalendar in the Name field. 6. Check the option public static void main(String[] args). 7. Click Finish to generate the template for the source code MyCalendar.java. 8. Enter (type the lines of) the source code for MyCalendar.java. Dr. Asaithambi School of Computing University of North Florida -- Fit to width A O Page view 1. Add notes of 5 of 5 Read aloud 9. Compiling and Running. To run the program, click on the icon that looks like the play button on an audio device. The program should be run on the Console pane within the Eclipse IDE and the output displayed there. Code Template for MyCalendar.java import java.util. Scanner; public class MyCalendar { public static void main ( String [] args) { // Stage 1: Enter code for receiving year in the range // 1780 // range year is entered, until the user inputs an // acceptable year. This should be a loop. Check whether // this works before you start to 2040. Prpt again and again if an out of the next stage. // Stage 2: Use the formula for d given above to figure // out the day of the week for January 1 of the given // year. This is // produces the correct result for different input values // for the year at this stage. For instance, if year is // 2000, d should be 6 (Saturday); if year is 2019, d // should be 2 (Tuesday); if year is 2015, d should be // 4 (Thursday), etc. Check whether this works before // you start a crucial step. Check whether your code the next stage. // Stage 3: Write a loop with index ranging from 1 to 12 // and print one month of the calendar at a time, starting // with January, and ending in December. // // Stage 3.1: Print the name of the month and figure out // the number of days in the month. You need to use a // switch for this purpose. Check whether this works // before you start the next stage. // Stage 3.2: You will print out the header showing the // labels Sun, Mon, Tue, etc. -- Fit to width A Read aloud 1. Add notes CB Page view of 5 of 5 // Stage 3.1: Print the name of the month and figure out // the number of days in the month . You need to use a // switch for this purpose. Check whether this works // before you start the next stage. // Stage 3.2: You will print out the header showing the // labels Sun, Mon, , etc. // Stage 3.3: Print the calendar for the current month. // Check whether this works for one month at a time. Note // that Stages 3.1, 3.2, and 3.3 are inside the loop // started at Stage 3. } School of Computing University of North Florida Dr. Asaithambi Programming II Project-2 Page 5 Note that in Stage 3.3, you will need a system of nested loops as the calendar for each month has rows and columns. Additionally, you will first print the calendar for January. The calendar for February will be placed vertically below the calendar for January; March below February; April below March; May below April; June below May; July below June; August below July; September below August; October below September; November below October; and December below November. For your reference, I provide below the calendar for the first three months of 2020. Keep in mind that all of the above discussions, the template, and the sample output are provided as guidance, and not all the details have been covered. It is your responsibility to make sure that the calendar you produce looks like the one shown in the sample output for all 12 months. The details are left for you to figure out and complete as part of the project. CB Page view A of 5 - Fit to width 1. Add notes of 5 Read aloud The details are left for you to figure out and complete as part of the project. January 2020 Sun Mon Tue Wed Thu Fri Sat 7 8 9 10 13 14 15 16 17 18 20 21 22 23 24 11 12 19 25 26 27 28 29 30 31 February 202o Sun Mon Tue Wed Thu Fri Sat 9 10 11 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 29 21 22 March 2020 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 1 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Step-By-Step Instructions for Canvas Submissions You will submit on Canvas the MyCalendar.java file consisting of your program source code. If you click on Assignment P-02, Canvas would provide an option for you to submit your assign- ment including any attachment to be uploaded. You will submit by navigating to the src folder within your project work space for the program (the MyCalendar.java file) you created on Eclipse. Submission of the MyCalendar.java file will be necessary to complete the project. IMPORTANT: There is a grading rubric provided on Canvas for this project. Review this rubric both before you begin and just before you are ready to submit and make sure that your submission will get the maximum possible points. School of Computing University of North Florida Dr. Asaithambi
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started