代写CS& 141 Calendar Assignment Part 1

2023-10-25 代写CS& 141 Calendar Assignment Part 1

CS& 141

Calendar Assignment

Part 1


Key topics:

Printing, data types, methods, operators, expressions, variables, for loops, parameters, returns, String objects, Scanner objects

Learning Outcomes:

Continue to become familiar with setup, design, execution and testing of basic Java programs

Design and develop a multi-method program in good style

Demonstrate the ability to decompose a problem and reduce redundancy using methods

Apply tools and techniques introduced in class to create a working program

Task:

Your task is to create a basic calendar using Java. You will name the file MyCalendar.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 exact size of your calendar is up to you but I recommend making each box about 15 characters wide. A sample of what the calendar looks like 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 in the format “m/d” or “mm/dd” all as one String. The month of that date should be displayed at the top of the calendar. The month and day inputted 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 another calendar for today’s date followed by the month and day broken up.

For this part of the calendar assignment, all months will look basically the same. They will all start on a Sunday in the top left box of the calendar and continue for an even 35 days. In a later part of this assignment we will change this to accurately match a given month.

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.

You have freedom to make your calendar look how you want. Feel free to replace the horizonal (=) and vertical (|) dividers with any character you like for your own added style.

Example Run:





Creative Portion:

In addition to the functionality of the calendar, your calendar should display some text art (ACSII art) above the calendar in the spirit of what you would see with a typical wall calendar. You have the freedom to choose what you display with these restrictions:

The ACSII art must be your own creation, not something found on the internet or elsewhere.

You must make use of at least one for loop (ideally multiple) to create your design. Make sure there are no infinite loops though.

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 it is clear in your code that you have put in effort, you will receive full points for the creative portion of the assignment. Don’t worry if you feel you are not particularly creative- something pretty basic will do as long as it meets the above requirements.

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 only one week on the calendar (one row). This method is passed an integer representing which row it is displaying. For example, if I wanted the row with numbers 8 through 14 printed, I would call this method with drawRow(2) since it is the second row.

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 will be helpful here. Check the helpful information section below for details on how to use these methods.

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 will be helpful here as well.

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 create 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. Replace name with a different name for your Calendar variable such as javaCal.

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 will also need to make use of several String methods. The indexOf() and substring() methods will come in handy in your monthFromDate() and dayFromDate() methods described above. 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”. (Remember, String indexing starts at 0, not 1.)

The substring() method creates a new String from the given starting index to the given ending index (it does not include the character at the ending index). There is a second version of the same method with a single parameter rather than two parameters with slightly different functionality. If no ending index is given, then a substring from the beginning index to the end of the String is created. If we wanted a substring of “Hello” that just captured “ell” assuming “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.

When you get to the portion where you are attempting to have the correct dates displayed in each cell, you may run into some spacing issues. To find a solution to this I would recommend taking a look at the provided code for programming project 6 at the end of Chapter 2. This can be found on page 195 of the 4th edition of the textbook or page 200 of the 5th edition of the textbook. This example can give you an idea of how you might handle this issue in your own code.

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. There is no formal pre-lab for this assignment but I still encourage you to take time to read the spec, make a plan, and maybe write some pseudocode before you start coding. You are welcome to discuss the concepts from this assignment with your classmates but all code you write must be your own.

Breaking Down the Assignment:

This is a large project, I highly recommend breaking it down into pieces! I have provided you with the methods that need to be included in your final program so this is a great place to start. Tackling this assignment method by method is a good strategy.

Specifically, I recommend starting with the drawRow() method. However, don’t try and just get a full row printed right away. Rather, start by getting one cell displayed (without the number in the cell). Once you get the single cell printed, figure out how to get the full row printed. A full row consists of seven cells (one week). After you get the full row displayed (without numbers in the cells), then begin thinking about how you can modify that to add the numbers in the cells.

Style:

It is important that you get used to writing code in good style. What is demonstrated in class is considered good style and there is a style guide on Canvas for your reference. Code written without proper style may lose points. As with the labs, proper naming conventions, indentation, a class comment, and method comments for all methods are expected.

Do note that only Chapters 1 through 4 and the material found in this specification are valid for this assignment. Other material used on this assignment will be considered advanced material and 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 for this assignment.

1.As stated in the specification above, each calendar month will contain 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 ascii 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.

Grading:

CategoryPoints

Style10

Creativity10

drawMonth() method15

drawRow() method15

displayDate() method15

monthFromDate() method7.5

dayFromDate() method7.5

Program functionality20

Total:100


Please add approximately how many hours you spent working on this assignment to your class comment.