Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

1. Assignment detail

The initial screen shows the current month looking like this. It also highlights today's date, for example, using a pair of brackets. (It is not straightforward to highlight on console. It is fine to use a pair of brackets for this purpose.)
February 2017
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 [27] 28 <--- it is ok if [27] is sticking out.

The initial screen comes with a main menu with following options: View by, Create, Go to, Event list, Delete, and Quit. After the function of an option is done, the main menu is displayed again for the user to choose the next option.
Select one of the following options:
[L]oad [V]iew by [C]reate, [G]o to [E]vent list [D]elete [Q]uit
The user may enter one of the letter highlighted with a pair of bracket to choose an option. For example,
V
will choose the View by option.
[L]oadThe system loads events.txt to populate the calendar. If there is no such file because it is the first run, the load function prompts a message to the user indicating this is the first run. You may use Java serialization this function.
[V]iew byUser can choose a Day or a Month view. If a Day view is chosen, the calendar displays the current date. If there is an event(s) scheduled on that day, display them in the order of start time of the event. With a Month view, it displays the current month and highlights day(s) if any event scheduled on that day. After a view is displayed, the calendar gives the user three options: P, N, and M, where P, N, and M stand for previous, next, and main menu, respectively. The previous and next options allow the user to navigate the calendar back and forth by day if the calendar is in a day view or by month if it is in a month view. If the user selects m, navigation is done, and the user gets to access the main menu again.
[D]ay view or [M]view ?

If the user selects D, then
Tuesday, Feb 27, 2017
Dr. Kim's office hour 9:15 - 10:15

[P]revious or [N]ext or [M]ain menu ?

If the user selects M, then
February 2017
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28

[P]revious or [N]ext or [M]ain menu ?

[C]reateThis option allows the user to schedule an event. The calendar asks the user to enter the title, date, starting time, and ending time of an event. For simplicity, we consider one day event only. Also, let's assume there is no conflict between events that user entered, and therefore your program doesn't have to check if a new event is conflict with existing events. Please stick to the following format to enter data:
Title: a string (doesn't have to be one word)
date: MM/DD/YYYY
Starting time and ending time: 24 hour clock such as 06:00 for 6 AM and 15:30 for 3:30 PM. The user may not enter ending time if an ending time doesn't make sense for the event (e.g. leaving for Korea event may have a starting time but no ending time.)
[G]o toWith this option, the user is asked to enter a date in the form of MM/DD/YYYY and then the calendar displays the Day view of the requested date including any event scheduled on that day in the order of starting time.
[E]vent listThe user can browse scheduled events. The calendar displays all the events scheduled in the calendar in the order of starting date and starting time. An example presentation of events is as follows:
2017
Friday March 17 13:15 - 14:00 Dentist
Tuesday April 25 15:00 - 16:00 Job Interview
2017
Friday June 2 17:00 Leave for Korea

[D]eleteUser can delete an event from the Calendar. There are two different ways to delete an event: Selected and All. Other type of deletion will not be considered for simplicity.
[S]elected: all the events scheduled on the selected date will be deleted.
[A]ll: all the events scheduled on this calendar will be deleted.
[S]elected or [A]ll ?

If the user enters s, then the calendar asks for the date as shown below.
Enter the date.

06/03/2016

[Q]uit saves all the events scheduled in a text file called "events.txt" in the order of starting date and starting time. You may use Java serialization if you don't want to persist data in a text file.
The main menu will be displayed after each option is done. It is crucial to have a user friendly interface for the user to enter input. For example, if the calendar needs a date from the user, suggest a specific format of the date for the user to use. Our class grader will be the user to operate your calendar, and you don't want to frustrate the user with a confusing interface.

--------CODE---------------------
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class CalenderAssignment {
private static BufferedReader fileReader;
private static BufferedWriter filewriter;
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private static int year;
private static int month;
private static int day;
private static int date;
static {
int[] tmp = getDayDate(new Date());
year = tmp[0];
month = tmp[1];
day = tmp[2];
date = tmp[3];
}
private static int[] getDayDate(Date dateObj) {
Calendar cal = Calendar.getInstance();
cal.setTime(dateObj);
int[] tmp = new int[4];
tmp[0] = cal.get(Calendar.YEAR);
tmp[1] = cal.get(Calendar.MONTH) + 1;
tmp[2] = cal.get(Calendar.DAY_OF_MONTH);
tmp[3] = cal.get(Calendar.DATE);
return tmp;
}
private static List eventsList;
public static void main(String[] args) throws Exception {
String option = "";
while (!"Q".equalsIgnoreCase(option)) {
System.out
.println("Select one of the following options:n[L]oad [V]iew by [C]reate, [G]o to [E]vent list [D]elete [Q]uitn");
printMonth(year, month, date);
option = reader.readLine();
switch (option) {
case "L":
load();
break;
case "V":
view();
break;
case "C":
create();
break;
case "G":
System.out.println("Enter the date : ");
String s = reader.readLine();
go(s);
break;
case "E":
printEvents("N/A");
break;
case "D":
delete();
break;
case "Q":
return;
default:
System.out.println("Wrong option please select valid one!.");
break;
}
}
}
private static void load() {
if (fileReader == null) {
System.out
.println("nThis is first time run!. Nothing is there!n");
try {
File file = new File("event.txt");
file.createNewFile();
fileReader = new BufferedReader(new FileReader(file));
filewriter = new BufferedWriter(new FileWriter(file));
} catch (Exception e) {
System.out
.println("This is first time run!. Nothing is there!");
}
} else {
eventsList.clear();
String line = null;
try {
while ((line = fileReader.readLine()) != null) {
System.out.println(line);
eventsList.add(line);
}
System.out.println("nnEvents are loaded successfully!.n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
private static void view() throws Exception {
System.out.println("[D]ay view or [M]view ?");
String op = reader.readLine();
String searchStr = getMonthName(month);
if ("D".equalsIgnoreCase(op)) {
System.out.println(getCurrentDateDetails());
searchStr += getDate();
}
printEvents(searchStr);
System.out.println("[P]revious or [N]ext or [M]ain menu ?");
return;
}
private static void printEvents(String searchStr) {
boolean check = true;
if (searchStr.equalsIgnoreCase("N/A")) {
check = false;
}
for (int i = 0; i < eventsList.size(); i++) {
if (check && eventsList.get(i).contains(searchStr)) {
System.out.println(eventsList.get(i));
}
}
}
private static String getCurrentDateDetails() {
return getDayName(day) + "," + getMonthName(month) + " " + getDate()
+ "," + getYear();
}
private static void create() throws Exception {
System.out.println("Enter a Title: ");
String title = reader.readLine();
System.out.println("Enter a date: ");
String date = reader.readLine();
System.out.println("Enter a Timing: ");
String timing = reader.readLine();
System.out.println("Enter a Event: ");
String event = reader.readLine();
SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/yyyy");
Date d = sdf.parse(date);
int[] tmp = getDayDate(d);
int yearLocal = tmp[0];
String monthLocal = getMonthName(tmp[1]);
String dayLocal = getDayName(tmp[2]);
int dateLocal = tmp[3];
date = yearLocal + " " + dayLocal + " " + monthLocal + " " + dateLocal
+ " " + timing + " " + event;
eventsList.add(date);
filewriter.write(date);
}
private static void go(String date) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/yyyy");
Date d = sdf.parse(date);
int[] tmp = getDayDate(d);
String monthLocal = getMonthName(tmp[1]);
int dateLocal = tmp[3];
String searchStr = monthLocal + " " + dateLocal;
printEvents(searchStr);
System.out.println("");
}
private static void delete() throws Exception {
System.out.println("[S]elected or [A]ll ?");
String op = reader.readLine();
if ("S".equalsIgnoreCase(op)) {
System.out.println("Enter date : ");
String date = reader.readLine();
SimpleDateFormat sdf = new SimpleDateFormat("MM/DD/yyyy");
Date d = sdf.parse(date);
int[] tmp = getDayDate(d);
String monthLocal = getMonthName(tmp[1]);
int dateLocal = tmp[3];
String searchStr = monthLocal + " " + dateLocal;
for (int i = 0; i < eventsList.size(); i++) {
if (eventsList.get(i).contains(searchStr)) {
eventsList.remove(i);
}
}
}
}
private static int getDay() {
return day;
}
private static int getMonth() {
return month;
}
private static int getYear() {
return year;
}
private static int getDate() {
return date;
}
private/** Print the calendar for a month in a year */
static void printMonth(int year, int month, int todayDate) {
// Get start day of the week for the first date in the month
int startDay = getStartDay(year, month);
// Get number of days in the month
int numOfDaysInMonth = getNumOfDaysInMonth(year, month);
// Print headings
printMonthTitle(year, month);
// Print body
printMonthBody(startDay, numOfDaysInMonth, todayDate);
}
/** Get the start day of the first day in a month */
static int getStartDay(int year, int month) {
// Get total number of days since 1/1/1800
int startDay1800 = 3;
long totalNumOfDays = getTotalNumOfDays(year, month);
// Return the start day
return (int) ((totalNumOfDays + startDay1800) % 7);
}
/** Get the total number of days since Jan 1, 1800 */
static long getTotalNumOfDays(int year, int month) {
long total = 0;
// Get the total days from 1800 to year -1
for (int i = 1800; i < year; i++)
if (isLeapYear(i))
total = total + 366;
else
total = total + 365;
// Add days from Jan to the month prior to the calendar month
for (int i = 1; i < month; i++)
total = total + getNumOfDaysInMonth(year, i);
return total;
}
/** Get the number of days in a month */
static int getNumOfDaysInMonth(int year, int month) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
|| month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;
if (month == 2)
if (isLeapYear(year))
return 29;
else
return 28;
return 0; // If month is incorrect.
}
/** Determine if it is a leap year */
static boolean isLeapYear(int year) {
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return true;
return false;
}
/** Print month body */
static void printMonthBody(int startDay, int numOfDaysInMonth, int todayDate) {
// Pad space before the first day of the month
int i = 0;
for (i = 0; i < startDay; i++)
System.out.print(" ");
for (i = 1; i <= numOfDaysInMonth; i++) {
String tmp = String.valueOf(i);
String space = "";
if (i == todayDate) {
tmp = "[" + tmp;
}
if (i < 10) {
if (tmp.contains("[")) {
space = " ";
} else {
space = " ";
}
} else {
if (tmp.contains("[")) {
space = " ";
} else {
space = " ";
}
}
System.out.print(space + tmp);
if (i == todayDate) {
System.out.print("]");
}
if ((i + startDay) % 7 == 0)
System.out.println();
}
System.out.println();
}
/** Print the month title, i.e. May, 1999 */
static void printMonthTitle(int year, int month) {
System.out.println(" " + getMonthName(month) + ", " + year);
System.out.println("-----------------------------------");
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
}
/** Get the English name for the month */
static String getMonthName(int month) {
String monthName = null;
switch (month) {
case 1:
monthName = "January";
break;
case 2:
monthName = "February";
break;
case 3:
monthName = "March";
break;
case 4:
monthName = "April";
break;
case 5:
monthName = "May";
break;
case 6:
monthName = "June";
break;
case 7:
monthName = "July";
break;
case 8:
monthName = "August";
break;
case 9:
monthName = "September";
break;
case 10:
monthName = "October";
break;
case 11:
monthName = "November";
break;
case 12:
monthName = "December";
}
return monthName;
}
static String getDayName(int dayLocal) {
String dayName = null;
switch (dayLocal) {
case 1:
dayName = "Sunday";
break;
case 2:
dayName = "Monday";
break;
case 3:
dayName = "Tuesday";
break;
case 4:
dayName = "Wednessday";
break;
case 5:
dayName = "Thursday";
break;
case 6:
dayName = "Friday";
break;
}
return dayName;
}
}

Java, Programming

  • Category:- Java
  • Reference No.:- M92397626
  • Price:- $15

Priced at Now at $15, Verified Solution

Have any Question?


Related Questions in Java

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As