Please help me with this lab question, thanks **This is the IO.java it says to d
ID: 3857266 • Letter: P
Question
Please help me with this lab question, thanks
**This is the IO.java it says to download**
1. Download Calendarjava, from Sakai > Resources > Labs > Lab5. Also download IO java, if you don't already have it in the folder where you put Calendar java 2. Calendar.java is a program that implements a simplified event calendar. o The calendar will be for one month only o We will assume every month has 31 days. will assume every month has 31 days We will record at most one event per day 3. An event will be represented by a String. 4. A calendar will be represented by an array of 32 Strings, with the String at index d of the array representing the event, if any, for the date d. E.g., index 5 holds the event for the fifth of the month. Index 0 of the array will not be used. If there is no event recorded for a date, the corresponding element of the array will be nu The method addEvent takes 3 arguments: a calendar (i.e., an array of strings), an event (i.e., a String), and a date (i.e., an int). If there is already an event scheduled for the date, addEvent does not change the array, and returns false. If there is no event scheduled for the date yet, addEvent stores the event in index date of the calendar array and returns true. If the date is erroneous, i.e. less than 1 or more that 31, addEvent just returns false. Your first task for this Lab is to replace the line with the comment "/ replace this with your code" so that addEvent does those things The method printCalendar takes one argument, a calendar (i.e. an array of Strings), and prints it. printCalendar is already written for you The method main calls the other methods in order to test them. Your second task for this Lab is to replace the comment "/I add your test calls here" with your own calls to addEvent and to printCalendar in order to test all aspects of addEvent.Explanation / Answer
Hi Let me know if you need more implementation/information:-
=====================================================
public class Calendar {
public static boolean addEvent(String[] calendar, String event, int date) {
if (date < 1 && date >= 31)//checking if date crossed its range
return false;
if (calendar[date] == null || calendar[date].equals("")) {//Checking if alreay exist
calendar[date] = event;//adding it to actual array
return true;
}
return false; // replace this with your code
}
// bug in printCalendar fixed 7/4/2014 LS
public static void printCalendar(String[] calendar) {
for (int d = 1; d < 32; d++) { // calendar[0] is not used
IO.outputStringAnswer(d + " " + calendar[d]);
}
}
public static void main(String[] args) {
// 31 days + 1 unused element = 32 elements in a calendar array
String[] calendar1 = new String[32];
boolean result1 = addEvent(calendar1, "party", 5);
IO.outputBooleanAnswer(result1);
printCalendar(calendar1);
System.out.println("===========================================");
System.out.println("Enter date:");//manual reading from user
int date = IO.readInt();
System.out.println("Enter event:");//manual reading from user
String event = IO.readString();
//Test one
result1 = addEvent(calendar1,event, date);
IO.outputBooleanAnswer(result1);
printCalendar(calendar1);
System.out.println("===========================================");
result1 = addEvent(calendar1,event, date);//passing same values it should return false as that record alreay present.
IO.outputBooleanAnswer(result1);
printCalendar(calendar1);
System.out.print("Enter "yes" or "no": ");
while(IO.readBoolean()){//This will take care till you enter yes/no to proceed further
System.out.println("Enter date:");//manual reading from user
date = IO.readInt();
System.out.println("Enter event:");//manual reading from user
event = IO.readString();
//Test one
result1 = addEvent(calendar1,event, date);
IO.outputBooleanAnswer(result1);
printCalendar(calendar1);
System.out.print("Enter "yes" or "no": ");
}
// add your test calls here
}
}
====================
IO.java
=======================
import java.io.*;
public class IO {
private static BufferedReader kb = new BufferedReader(
new InputStreamReader(System.in));
public static String readString() {
while (true) {
try {
return kb.readLine();
} catch (IOException e) {
// should never happen
}
}
}
public static int readInt() {
while (true) {
try {
String s = kb.readLine();
return Integer.parseInt(s);
} catch (NumberFormatException e) {
System.out.print("That is not an integer. Enter again: ");
} catch (IOException e) {
// should never happen
}
}
}
public static double readDouble() {
while (true) {
try {
String s = kb.readLine();
return Double.parseDouble(s);
} catch (NumberFormatException e) {
System.out.print("That is not a number. Enter again: ");
} catch (IOException e) {
// should never happen
}
}
}
public static char readChar() {
String s = null;
try {
s = kb.readLine();
} catch (IOException e) {
// should never happen
}
while (s.length() != 1) {
System.out.print("That is not a single character. Enter again: ");
try {
s = kb.readLine();
} catch (IOException e) {
// should never happen
}
}
return s.charAt(0);
}
public static boolean readBoolean() {
String s = null;
while (true) {
try {
s = kb.readLine();
} catch (IOException e) {
// should never happen
}
if (s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y")
|| s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t")) {
return true;
} else if (s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n")
|| s.equalsIgnoreCase("false") || s.equalsIgnoreCase("f")) {
return false;
} else {
System.out.print("Enter "yes" or "no": ");
}
}
}
public static void outputStringAnswer(String s) {
System.out.println("RESULT: "" + s + """);
}
public static void outputIntAnswer(int i) {
System.out.println("RESULT: " + i);
}
public static void outputDoubleAnswer(double d) {
System.out.println("RESULT: " + d);
}
public static void outputCharAnswer(char c) {
System.out.println("RESULT: '" + c + "'");
}
public static void outputBooleanAnswer(boolean b) {
System.out.println("RESULT: " + b);
}
public static void reportBadInput() {
System.out.println("User entered bad input.");
}
}
================================
OUTPUT:-
==================================
RESULT: true
RESULT: "1 null"
RESULT: "2 null"
RESULT: "3 null"
RESULT: "4 null"
RESULT: "5 party"
RESULT: "6 null"
RESULT: "7 null"
RESULT: "8 null"
RESULT: "9 null"
RESULT: "10 null"
RESULT: "11 null"
RESULT: "12 null"
RESULT: "13 null"
RESULT: "14 null"
RESULT: "15 null"
RESULT: "16 null"
RESULT: "17 null"
RESULT: "18 null"
RESULT: "19 null"
RESULT: "20 null"
RESULT: "21 null"
RESULT: "22 null"
RESULT: "23 null"
RESULT: "24 null"
RESULT: "25 null"
RESULT: "26 null"
RESULT: "27 null"
RESULT: "28 null"
RESULT: "29 null"
RESULT: "30 null"
RESULT: "31 null"
===========================================
Enter date:
3
Enter event:
abc
RESULT: true
RESULT: "1 null"
RESULT: "2 null"
RESULT: "3 abc"
RESULT: "4 null"
RESULT: "5 party"
RESULT: "6 null"
RESULT: "7 null"
RESULT: "8 null"
RESULT: "9 null"
RESULT: "10 null"
RESULT: "11 null"
RESULT: "12 null"
RESULT: "13 null"
RESULT: "14 null"
RESULT: "15 null"
RESULT: "16 null"
RESULT: "17 null"
RESULT: "18 null"
RESULT: "19 null"
RESULT: "20 null"
RESULT: "21 null"
RESULT: "22 null"
RESULT: "23 null"
RESULT: "24 null"
RESULT: "25 null"
RESULT: "26 null"
RESULT: "27 null"
RESULT: "28 null"
RESULT: "29 null"
RESULT: "30 null"
RESULT: "31 null"
===========================================
RESULT: false
RESULT: "1 null"
RESULT: "2 null"
RESULT: "3 abc"
RESULT: "4 null"
RESULT: "5 party"
RESULT: "6 null"
RESULT: "7 null"
RESULT: "8 null"
RESULT: "9 null"
RESULT: "10 null"
RESULT: "11 null"
RESULT: "12 null"
RESULT: "13 null"
RESULT: "14 null"
RESULT: "15 null"
RESULT: "16 null"
RESULT: "17 null"
RESULT: "18 null"
RESULT: "19 null"
RESULT: "20 null"
RESULT: "21 null"
RESULT: "22 null"
RESULT: "23 null"
RESULT: "24 null"
RESULT: "25 null"
RESULT: "26 null"
RESULT: "27 null"
RESULT: "28 null"
RESULT: "29 null"
RESULT: "30 null"
RESULT: "31 null"
Enter "yes" or "no": yes
Enter date:
7
Enter event:
hjui
RESULT: true
RESULT: "1 null"
RESULT: "2 null"
RESULT: "3 abc"
RESULT: "4 null"
RESULT: "5 party"
RESULT: "6 null"
RESULT: "7 hjui"
RESULT: "8 null"
RESULT: "9 null"
RESULT: "10 null"
RESULT: "11 null"
RESULT: "12 null"
RESULT: "13 null"
RESULT: "14 null"
RESULT: "15 null"
RESULT: "16 null"
RESULT: "17 null"
RESULT: "18 null"
RESULT: "19 null"
RESULT: "20 null"
RESULT: "21 null"
RESULT: "22 null"
RESULT: "23 null"
RESULT: "24 null"
RESULT: "25 null"
RESULT: "26 null"
RESULT: "27 null"
RESULT: "28 null"
RESULT: "29 null"
RESULT: "30 null"
RESULT: "31 null"
Enter "yes" or "no": YES
Enter date:
5
Enter event:
SHJS
RESULT: false
RESULT: "1 null"
RESULT: "2 null"
RESULT: "3 abc"
RESULT: "4 null"
RESULT: "5 party"
RESULT: "6 null"
RESULT: "7 hjui"
RESULT: "8 null"
RESULT: "9 null"
RESULT: "10 null"
RESULT: "11 null"
RESULT: "12 null"
RESULT: "13 null"
RESULT: "14 null"
RESULT: "15 null"
RESULT: "16 null"
RESULT: "17 null"
RESULT: "18 null"
RESULT: "19 null"
RESULT: "20 null"
RESULT: "21 null"
RESULT: "22 null"
RESULT: "23 null"
RESULT: "24 null"
RESULT: "25 null"
RESULT: "26 null"
RESULT: "27 null"
RESULT: "28 null"
RESULT: "29 null"
RESULT: "30 null"
RESULT: "31 null"
Enter "yes" or "no": YES
Enter date:
20
Enter event:
BCD
RESULT: true
RESULT: "1 null"
RESULT: "2 null"
RESULT: "3 abc"
RESULT: "4 null"
RESULT: "5 party"
RESULT: "6 null"
RESULT: "7 hjui"
RESULT: "8 null"
RESULT: "9 null"
RESULT: "10 null"
RESULT: "11 null"
RESULT: "12 null"
RESULT: "13 null"
RESULT: "14 null"
RESULT: "15 null"
RESULT: "16 null"
RESULT: "17 null"
RESULT: "18 null"
RESULT: "19 null"
RESULT: "20 BCD"
RESULT: "21 null"
RESULT: "22 null"
RESULT: "23 null"
RESULT: "24 null"
RESULT: "25 null"
RESULT: "26 null"
RESULT: "27 null"
RESULT: "28 null"
RESULT: "29 null"
RESULT: "30 null"
RESULT: "31 null"
======================
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.