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

Need help with this second part of my calendar assignment that is being down in

ID: 3869254 • Letter: N

Question

Need help with this second part of my calendar assignment that is being down in java on jgrasp. first i will put up the assignment details and then i can post what coding i have done thus far for this assignment. I want to keep everything exactly the same about my calendar with its output still looking just like the image below but with these adds and changes to it. DO NOT USE CODE THAT USES THE CALENDAR application. KEEP MY CODE WITH THE CALENDAR AND IMAGE ABOVE CALENDAR.

What calendaer to still look like this for the layout, as it is already in my code.

Task:

Your task is to build upon your calendar from Assignment 1. You will begin by fixing a few things then adding more functionality to your program. 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 with additional features.

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 October, October 1st should start on Saturday.

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.

Helpful Information:

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.

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 usename.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 creates 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 created. 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.

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. Badly styled code will lose points.

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. We have also use random, and booleans and for loops and while loops and if/else's.

And here is what code i have so far from the first part of the assignment:

import java.util.Scanner;

public class Calendar {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

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

int year = scanner.nextInt();

System.out.print("Enter 1st day of year ( 0 = Sunday, 6 = Satuday ): ");

int getFirstDay = scanner.nextInt();

for ( int month = 1; month <= 12; month++ ){

int days = 0;

String monthName = " ";

switch (month) {

case 1: monthName = "January";

days = 31;

break;

case 2: monthName = "February";

if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){

days = 29;

} else {

days = 28;

}

break;

case 3: monthName = "March";

days = 31;

break;

case 4: monthName = "April";

days = 30;

break;

case 5: monthName = "May";

days = 31;

break;

case 6: monthName = "June";

days = 30;

break;

case 7: monthName = "July";

days = 31;

break;

case 8: monthName = "August";

days = 31;

break;

case 9: monthName = "September";

days = 30;

break;

case 10: monthName = "October";

days = 31;

break;

case 11: monthName = "November";

days = 30;

break;

case 12: monthName = "December";

days = 31;

break;

default: System.out.print("Error: this month does not exist"); System.exit(0);

break;

}

System.out.println(" " + monthName + " " + year);

System.out.println("-----------------------------------");

System.out.println(" Sun Mon Tue Wed Thu Fri Sat");

int i = 0;

int firstDay = 0;

switch(month){

case 1: firstDay=getFirstDay;

break;

case 2: firstDay=getFirstDay+3;

break;

case 3: firstDay=getFirstDay+3;

break;

case 4: firstDay=getFirstDay+6;

break;

case 5: firstDay = getFirstDay + 8;

break;

case 6: firstDay = getFirstDay + 11;

break;

case 7: firstDay = getFirstDay + 13;

break;

case 8: firstDay = getFirstDay + 16;

break;

case 9: firstDay = getFirstDay + 19;

break;

case 10: firstDay = getFirstDay + 21;

break;

case 11: firstDay = getFirstDay + 24;

break;

case 12: firstDay = getFirstDay + 26;

break;

}

if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){

switch(month){

case 1: firstDay=getFirstDay;

break;

case 2: firstDay=getFirstDay+3;

break;

case 3: firstDay=getFirstDay+4;

break;

case 4: firstDay=getFirstDay+7;

break;

case 5: firstDay = getFirstDay + 9;

break;

case 6: firstDay = getFirstDay + 12;

break;

case 7: firstDay = getFirstDay + 14;

break;

case 8: firstDay = getFirstDay + 17;

break;

case 9: firstDay = getFirstDay + 20;

break;

case 10: firstDay = getFirstDay + 22;

break;

case 11: firstDay = getFirstDay + 25;

break;

case 12: firstDay = getFirstDay + 27;

break;

}

}

int dayOfWeek = 0;

if ( (firstDay % 7 ) >= 0 ){

if ( (firstDay % 7 ) == 0 ){

dayOfWeek = 0;

} else if ( (firstDay % 7 ) == 1 ){

dayOfWeek = 1;

System.out.print(" " );

} else if ( (firstDay % 7 ) == 2 ){

dayOfWeek = 2;

System.out.print(" " );

} else if ( (firstDay % 7 ) == 3 ){

dayOfWeek = 3;

System.out.print(" " );

} else if ( (firstDay % 7 ) == 4 ){

dayOfWeek = 4;

System.out.print(" " );

} else if ( (firstDay % 7 ) == 5 ){

dayOfWeek = 5;

System.out.print(" " );

} else if ( (firstDay % 7 ) == 6 ){

dayOfWeek = 6;

System.out.print(" " );

}

}

for ( i = 1; i <= days; i++ ) {

if (i < 10)

System.out.print(" " + i );

else

System.out.print(" " + i );

if ((i + firstDay ) % 7 == 0 )

System.out.println();

}

System.out.println();

}

}

}

what date would you like to look at? 9/20 8 10 12 13 14 l 15 16 17 18 19 2e 21 23 24 25 26 | 27 28 29 30 31 32 34 l 35 Month: 9 Day: 2e

Explanation / Answer

import java.util.Random;
import java.util.Scanner;

public class RockPaperScissors {
private Player player;
private Monitor monitor;
private int playerScore;
private int monitorScore;
private int gameCount;

private enum Change {
ROCK, PAPER, SCISSORS;

public int compareChanges(Change otherChange) {
// condition for tie
if (this == otherChange)
return 0;

switch (this) {
case ROCK:
return (otherChange == SCISSORS ? 1 : -1);
case PAPER:
return (otherChange == ROCK ? 1 : -1);
case SCISSORS:
return (otherChange == PAPER ? 1 : -1);
}
return 0;
}
}

private class Player {
private Scanner scanInp;

public Player() {
scanInp = new Scanner(System.in);
}

public Change getChange() {
// user to select
System.out.print("Rock, paper, or scissors? ");

// Get the selected input
String input = scanInp.nextLine();
input = input.toUpperCase();
char fLetter = input.charAt(0);
if (fLetter == 'R' || fLetter == 'P' || fLetter == 'S') {
// check valid input
switch (fLetter) {
case 'R':
return Change.ROCK;
case 'P':
return Change.PAPER;
case 'S':
return Change.SCISSORS;
}
}

// not valid retry
return getChange();
}

public boolean againPlay() {
System.out.print("Do you want to play again? ");
String userInput = scanInp.nextLine();
userInput = userInput.toUpperCase();
return userInput.charAt(0) == 'Y';
}
}

private class Monitor {
public Change getChange() {
Change[] Changes = Change.values();
Random r = new Random();
int index = r.nextInt(Changes.length);
return Changes[index];
}
}

public RockPaperScissors() {
player = new Player();
monitor = new Monitor();
playerScore = 0;
monitorScore = 0;
gameCount = 0;
}

public void gameToStart() {
// Get change
Change userChange = player.getChange();
Change monitorChange = monitor.getChange();
System.out.println(" You played " + userChange + ".");
System.out.println("Computer played " + monitorChange + ". ");

// determine the winner
int compareChanges = userChange.compareChanges(monitorChange);
switch (compareChanges) {
case 0:
System.out.println("Tie!");
break;
case 1:
System.out.println(userChange + " beats " + monitorChange + ". You won!");
playerScore++;
break;
case -1: //
System.out.println(monitorChange + " beats " + userChange + ". You lost.");
monitorScore++;
break;
}
gameCount++;

// continuous playing
if (player.againPlay()) {
System.out.println();
gameToStart();
} else {
System.exit(0);
}
}
public static void main(String[] args) {
RockPaperScissors play = new RockPaperScissors();
play.gameToStart();
}
}