Question

In: Computer Science

Programming Project #1 – Day Planner In this project we will develop classes to implement a...

Programming Project #1 – Day Planner

In this project we will develop classes to implement a Day Planner program. Be sure to develop the code in a step by step manner, finish phase 1 before moving on to phase 2.

Phase 1

The class Appointment is essentially a record; an object built from this class will represent an Appointment in a Day Planner . It will contain 5 fields: month (3 character String), day (int), hour (int), minute (int), and message (String no longer then 40 characters).

Write 5 get methods and 5 set methods, one for each data field. Make sure the set methods verify the data. (E.G. month is a valid 3 letter code). Simple error messages should be displayed when data is invalid, and the current value should NOT change.

Write 2 constructor methods for the class Appointment . One with NO parameters that assigns default values to each field and one with 5 parameters that assigns the values passed to each field. If you call the set methods in the constructor(s) you will NOT need to repeat the data checks.

Write a toString method for the class Appointment . It should create and return a nicely formatted string with ALL 5 fields. Pay attention to the time portion of the data, be sure to format it like the time should be formatted ( HH : MM ) , a simple if-else statement could add a leading zero, if needed.

Write a method inputAppointment () that will use the class UserInput from a previous project, ask the user to input the information and assign the data fields with the users input. Make sure you call the UserInput methods that CHECK the min/max of the input AND call the set methods to make sure the fields are valid.

Write a main() method, should be easy if you have created the methods above, it creates a Appointment object, calls the inputAppointment () method to input values and uses the method toString() print a nicely formatted Appointment object to the screen. As a test, use the constructor with 5 parameters to create a second object (you decide the values to pass) and print the second object to the screen. The primary purpose of this main() method is to test the methods you have created in the Appointment class.

Phase 2

Create a class Planner , in the data area of the class declare an array of 20 Appointment objects. Make sure the array is private (data abstraction).

In this project we are going to build a simple Day Planner program that allow the user to create various Appointment objects and will insert each into an array. Be sure to insert each Appointment object into the array in the proper position, according to the date and time of the Appointment . This means the earliest Appointment object should be at the start of the array, and the last Appointment object at the end of the array.

Please pre load your array with the following Appointment objects:

          Mar 4, 17:30 Quiz 1
          Apr 1, 17:30 Midterm
          May 6, 17:30 Quiz 2
          Jun 3, 17:30 Final

Notice how the objects are ordered, with the earliest date at the start of the array and the latest at the end of the array.

The program will display the following menu and implement these features:

A)dd Appointment , D)elete Appointment , L)ist Appointment , E)xit

Some methods you must implement in the Planner class for this project:

  • Planner () constructor that places the 4 default Appointment objects in the array
  • main() method the creates the Planner object, then calls a run method
  • run() method that displays the menu, gets input, acts on that input
  • compareAppointment (Appointment A1, Appointment A2) method that returns true if A1 < A2, false otherwise
  • insertAppointment (Appointment A1) places A1 in the proper (sorted) slot of the array
  • listAppointment () method lists all Appointment objects in the array (in order) with a number in front
  • deleteAppointment () delete an object from the array using the number listAppointment () outputs in front of the item
  • addAppointment () calls inputAppointment () from the Appointment class and places it in the proper position of the array. Use an algorithm that shifts objects in the array (if needed) to make room for the new object. DO NOT sort the entire array, just shift objects

You may add additional methods to the Planner and Appointment classes as long as you clearly document 'what' and 'why' you added the method at the top of the class. The Appointment class could use one or more constructor methods. DO NOT in any way modify the UserInput class. If it so much as refers to a day or month or anything else in the Planner or Appointment class there will be a major point deduction.

Solutions

Expert Solution

Working code implemented in Java and appropriate comments provided for better understanding:

Here I am attaching code for these files:

  • Appointment.java
  • Planner.java
  • UserInput.java

Source code for Appointment.java:

/*
* This Appointment.java file uses different methods to make appointments. It uses get and set methods for
* each aspect of the appointment and then pulls from the UserInput.java file to get user input and make
* sure all the inputs are valid for the appointment.
*/

public class Appointment {
private String month, message;
private int day, hour, minute;
  
public Appointment(){
day = 1;
hour = 1;
minute = 1;
month = "Jan";
message = "Default";
}
public Appointment (int day, int hour, int minute, String month, String message){
setDay(day);
setHour(hour);
setMinute(minute);
setMonth(3, 3, month);
setMessage(0, 40, message);
}
  
public String getMonth(){
return month;
}
  
public void setMonth(int min, int max, String s){
if (s.length() >= min && s.length() <= max)
month = s;
}
  
public String getMessage(){
return message;
}
  
public void setMessage(int min, int max, String s) {
if (s.length() >= min && s.length() <= max)
message = s;   
}
  
public int getDay(){
return day;
}
public void setDay(int x){
if (x >= 1 && x <= 31)
       day = x;
else
       System.out.println("Invalid day value.");
}
  
public int getHour(){
return hour;
}
  
public void setHour(int x){
if (x >= 1 && x <= 24)
hour = x;
else
System.out.println("Invalid hour value.");
}
  
public int getMinute(){
return minute;
}
  
public void setMinute(int x){
if (x >= 0 && x <= 60)
minute = x;
  
else
System.out.println("Invalid minute value.");
}

public String toString(){
String date;
if (hour < 10 && minute < 10)
date = "Your appointment for " + message + " is on " + month + " " + day + " at " + " 0" + hour + ":" + "0" + minute;
else if (minute < 10)
date = "Your appointment for " + message + " is on " + month + " " + day + " at " + hour + ":" + "0" + minute;
else if (hour > 10 && minute < 10)
date = "Your appointment for " + message + " is on " + month + " " + day + " at " + hour + ":" + "0" + minute;
else if (hour < 10 && minute > 10)
date = "Your appointment for " + message + " is on " + month + " " + day + " at " + "0"+ hour + ":" + minute;
else
date = "Your appointment for " + message + " is on " + month + " " + day + " at " + hour + ":" + minute;
return date;
}
public void inputAppointment(){
System.out.println("Please enter a month for your appointment.");
setMonth(3, 3, UserInput.getString(3, 3));
  
System.out.println("Please enter a day for your appointment.");
setDay(UserInput.getInt(1, 31));
  
System.out.println("Please enter a hour for your appointment.");
setHour(UserInput.getInt(0, 24));
  
System.out.println("Please enter a minute for your appointment.");
setMinute(UserInput.getInt(0, 59));
  
System.out.println("Please enter a message for your appointment.");
setMessage(0, 40, UserInput.getString(0, 40));
}


public static void main(String[] args) {
Appointment a1 = new Appointment();
a1.inputAppointment();
System.out.println(a1.toString());
  
Appointment a2 = new Appointment(1, 1, 1, "Jan", "Hello World!");
System.out.println(a2);
}


}


Source code for Planner.java:

/*
* This Planner.java file takes the Appointment.java file and puts all new months into an array that is sorted
* by the order in which the appointments are. In this .java file you can list all the appointments you have,
* insert new appointments, delete appointments, and add new appointments. This file also compares the different
* appointments to determine where to insert new appointemnts.
*/

public class Planner {
  
private Appointment[] planner = new Appointment[20];
private String[] months = new String[12];
int numAppointments;
  
  
public Planner () {
Appointment a = new Appointment(4, 17, 30, "Mar", "Quiz1");
Appointment a2 = new Appointment(1, 17, 30, "Apr", "Midterm");
Appointment a3 = new Appointment(6, 17, 30, "May", "Quiz 2");
Appointment a4 = new Appointment(3, 17, 30, "Jun", "Final");
  
planner[0] = a;
planner[1] = a2;
planner[2] = a3;
planner[3] = a4;
  
  
months[0] = "Jan";
months[1] = "Feb";
months[2] = "Mar";
months[3] = "Apr";
months[4] = "May";
months[5] = "Jun";
months[6] = "Jul";
months[7] = "Aug";
months[8] = "Sep";
months[9] = "Oct";
months[10] = "Nov";
months[11] = "Dec";
  
numAppointments = 4;
}
  
public void run() {
  
  
boolean exitMenu = false;
  
do {
System.out.println("A)dd Appointment, D)elete Appointment, L)ist Appointment, E)xit");

char value = UserInput.getChar();
value = Character.toUpperCase(value);
  
switch (value) {
case 'A':
addAppointment();
break;
case 'D':
deleteAppointment();
break;
case 'L':
listAppointment();
break;
case 'E':
exitMenu = true;
break;
default:
  
}
} while (!exitMenu);
}
  
public boolean compareAppointment(Appointment A1, Appointment A2) {
  
String a1Month = A1.getMonth();
String a2Month = A2.getMonth();
int a1Value = 0;
int a2Value = 0;
  
if (A1.getMonth() != A2.getMonth()){
for (int i = 0; i < months.length; i++){
if (a1Month == months[i])
a1Value = i;
}
for (int i = 0; i < months.length; i++){
if (a2Month == months[i])
a2Value = i;
}
if (a1Value < a2Value)
return true;
else
return false;
}
else if (A1.getDay() != A2.getDay()){
if (A1.getDay() < A2.getDay())
return true;
else
return false;
}
else if (A1.getHour() != A2.getHour()) {
if (A1.getHour() < A2.getHour())
return true;
else
return false;
}
else if (A1.getMinute() != A2.getMinute()){
if (A1.getMinute() < A2.getMinute())
return true;
else
return false;
}
else
System.out.println("Appointments are identical.");
return true;
}
  
public void insertAppointment(Appointment A1){
int index = 0;
  
for (int i = 0; i < numAppointments; i++){
if (compareAppointment(A1, planner[i]))
index = i - 1;
}
numAppointments++;
Appointment temp1 = planner[index];
planner[index] = A1;
for (int i = index; i < numAppointments; i++){
Appointment temp = planner[i+1];
planner[i+1] = temp1;
temp1 = temp;

}
  
}
  
public void listAppointment(){
int number = 1;
  
for(int i = 0; i < numAppointments; i++) {
System.out.println(number + ". " + planner[i].toString());
number++;
}
  
}
  
public void deleteAppointment(){
listAppointment();
System.out.println("Please select an appointment to delete.");
int value = UserInput.getInt();
  
numAppointments--;   
for (int i = value - 1; i < numAppointments; i++){
if (i + 1 <= numAppointments)
planner[i] = planner[i + 1];
}
}
  
public void addAppointment(){
Appointment A1 = new Appointment();
A1.inputAppointment();
insertAppointment(A1);
}
  
public static void main(String args[]) {
Planner p1 = new Planner();
p1.run();
}
  
}

Source code for UserInput.java:

/*
* This UserInput.java file is going to be used for all the projects we have in this class.
* this is used for all user input so we do not have to make new scanners everytime we are gettin
* input from the user.
*/

import java.util.Scanner;


public class UserInput {
  
static Scanner scanner = new Scanner(System.in);

public static int getInt (){
System.out.print("Integer input: ");
return Integer.parseInt(scanner.nextLine());
}

public static int getInt(int min, int max){
boolean userValue = true;
int x;
do {
System.out.print("Enter an integer between " + min + " and " + max + ". ");
x = getInt();
if (x >= min && x <= max){
userValue = true;
}
else {
System.out.println ("Error. Input must be between " + min + " and " + " " + max + ". ");
userValue = false;
}
} while (!userValue);
return x;

}

public static char getChar(){
System.out.print("Char input: ");
return scanner.nextLine().charAt(0);

}
  
public static char getChar(char min, char max) {
min = Character.toUpperCase(min);
max = Character.toUpperCase(max);
boolean userValue = true;
char x;
do{
System.out.println("Please enter a character between " + min + " and " + max + ". ");
x = getChar();
char temp = x;
temp = Character.toUpperCase(temp);
if (temp >= min && temp <= max){
userValue = true;
}
else {
System.out.println ("Error. Input must be between " + min + " and " + max + ". ");
userValue = false;
}
} while (!userValue);
return x;

}
  
public static double getDouble(){
System.out.print ("Double input: ");
return Double.parseDouble(scanner.nextLine());
}
  
public static double getDouble(double min, double max) {
boolean userValue = true;
double x;
do {
System.out.print("Enter an double value between " + min + " and " + max + ". ");
x = getDouble();
if (x >= min && x <= max){
userValue = true;
}
else {
System.out.println ("Error. Input must be between " + min + " and " + " " + max + ". ");
userValue = false;
}
} while (!userValue);
return x;
}
  
public static String getString(){
System.out.println("String: ");
return scanner.nextLine();
}

public static String getString(int min, int max){
boolean userValue = true;
String x;
do {
System.out.print("Enter an String between " + min + " and " + max + " characters: ");
x = getString();
if (x.length() >= min && x.length() <= max){
userValue = true;
}
else {
System.out.println ("Error. Input must be between " + min + " and " + " " + max + " characters. ");
userValue = false;
}
} while (!userValue);
return x;

}
  
public static void main(String args[]) {
  
System.out.println(getInt(0, 30));
  
System.out.println(getChar('a', 'z'));
  
System.out.println(getDouble(0.0, 30.0));
  
System.out.println(getString(0, 40));
}
}
  

Sample Output Screenshots:

Hope it helps, if you like the answer give it a thumbs up. Thank you.


Related Solutions

This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample runs below. Sample run...
Project 3 – Project - Situational Analysis Managers must develop and implement strategies to ensure that...
Project 3 – Project - Situational Analysis Managers must develop and implement strategies to ensure that difficulties in workplace relationships are promptly identified and constructively resolved. While people know problem-solving skills, they are critical to their daily work, many people do not know how to resolve work difficulties effectively and avoid dealing with them. Conflict should be dealt with sensitively and quickly. However, you should suppress any tendency to use your authority to make a unilateral decisions too quickly or...
This week, you will create and implement an object-oriented programming design for your project. You will...
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it. Submit a screen shot from Visual Studio with your explanation into a Word...
JAVA PROGRAMMING Implement a class Purse. A purse contains a collection of coins. For simplicity, we...
JAVA PROGRAMMING Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList<String>. Supply a method void addCoin(String coinName). Add a method toString to the Purse class that prints the coins in the purse in the format Purse[Quarter,Dime,Nickel,Dime]. Write a method reverse that reverses the sequence of coins in a purse. Implement a TestPurse class with a main method in it. It will use the toString method to...
Kernal Modul Programing Quenstion : Implement the following 4 conditions in kernel module programming. 1. Implement...
Kernal Modul Programing Quenstion : Implement the following 4 conditions in kernel module programming. 1. Implement a timer module using the timer function provided by the file LINUX/timer.h 2. In module_init, the timer is initialized using setup_timer and called mod_timer to start the timer. 3. Call back function my_timer_callback when timer expires. 4. When you remove a module, delete the timer.
C++In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must...
C++In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must quickly...
In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
In this project we will implement the Minesweeper game. Minesweeper is played on a rectangle grid....
In this project we will implement the Minesweeper game. Minesweeper is played on a rectangle grid. When the game starts, a number of bombs are hidden on random positions on the field. In every round, the player "touches" a cell of the field. If the cell contains a bomb, it explodes, the game ends, and the player loses. Otherwise, the cell is uncovered to show the number of bombs in the vicinity, that is, the number of neighboring cells that...
Programming Project – Deques, Stacks & Queues General Description: Design and develop array based and linked...
Programming Project – Deques, Stacks & Queues General Description: Design and develop array based and linked list-based implementations for the Dequeue ADT. Your implementation must support generic data types using C++ templates. Develop Adapter Files to provide Stack and Queue functionality for the Deques. Definitions: You should implement the ADTs precisely as described in the following partial header files. Deque.h template class Deque { public:         Deque();                    //constructor         ~Deque();                 //destructor         void insertFront(const E& e);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT