Question

In: Computer Science

i have a skeleton class and i have to fill some methods of this class. i...

i have a skeleton class and i have to fill some methods of this class. i am having difficulties especially with the findAppointment method. so this is the problem.

Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An Appointment has a description (for example “see the dentist”) and a date. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches.   You must write: • Appointment.java • Daily.java • Monthly.java • OneTime.java
You need to write AppointmentBook.java file – a skeleton and a sample run of the program is given to you. This file has a main method

I have done all the first part. the appointment, monthly, daily, OneTime. they work fine. the appointmentBook i havent finished. here is the skeleton. please use ArrayList and i want it in java.

**************AppointmentBook******************.

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
Build on the Appointment hierarchy.
Give the user the option to add new appointments.
The user must specify the type of the appointment and
description, and then, if required, the day or date.
*/
public class AppointmentBook
{ ................ }

/**
Adds a new Appointment object based on user input.
@param in the Scanner to read from.
*/
public void addAppointment(Scanner in)
{ ......................

}

/**
Method to print all appointments on a certain date.
@param in the Scanner to read from.
*/ public void findAppointments(Scanner in)
{ .....................}

// Just to test the appointment book
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
AppointmentBook ab = new AppointmentBook();

System.out.println("Welcome to the Appointment Book");
System.out.println("-------------------------------");

boolean done = false;
while (!done)
{
System.out.print("Appointments: (F)ind, (A)dd, or (Q)uit: ");
String choice = in.next();
if (choice.equals("F") || choice.equals("f"))
{
ab.findAppointments(new Scanner(System.in));
}
else if (choice.equals("A") || choice.equals("a"))
{
ab.addAppointment(new Scanner(System.in));
}
done = choice.equals("Q") || choice.equals("q");
}
System.out.println("Good bye. Have a nice day!");
in.close();
}
}

***********this is the output*********

Welcome to the Appointment Book
-------------------------------
Appointments: (F)ind, (A)dd, or (Q)uit: A
Enter type [(D)aily, (M)onthly, (O)netime] and description: D Exercise
Appointments: (F)ind, (A)dd, or (Q)uit: A
Enter type [(D)aily, (M)onthly, (O)netime] and description: D Eat dinner
Appointments: (F)ind, (A)dd, or (Q)uit: A
Enter type [(D)aily, (M)onthly, (O)netime] and description: M Pay Bills
Enter the day of the appointment: 1
Appointments: (F)ind, (A)dd, or (Q)uit: A
Enter type [(D)aily, (M)onthly, (O)netime] and description: M Pay Rent
Enter the day of the appointment: 10
Appointments: (F)ind, (A)dd, or (Q)uit: A
Enter type [(D)aily, (M)onthly, (O)netime] and description: O Visit Patagonia
Enter the date of the appointment (mm dd yyyy) : 12 01 2020
Appointments: (F)ind, (A)dd, or (Q)uit: a
Enter type [(D)aily, (M)onthly, (O)netime] and description: O Visit Norway
Enter the date of the appointment (mm dd yyyy) : 07 01 2020
Appointments: (F)ind, (A)dd, or (Q)uit: F
Enter the date (mm, dd, yyyy) to search: 09 10 2019
Exercise
Eat dinner
Pay Rent
Appointments: (F)ind, (A)dd, or (Q)uit: F
Enter the date (mm, dd, yyyy) to search: 07 01 2020
Exercise
Eat dinner
Pay Bills
Visit Norway
Appointments: (F)ind, (A)dd, or (Q)uit: f
Enter the date (mm, dd, yyyy) to search: 12 01 2020
Exercise
Eat dinner
Pay Bills
Visit Patagonia
Appointments: (F)ind, (A)dd, or (Q)uit: q
Good bye. Have a nice day!

Solutions

Expert Solution

Hi,

Step

We can have a private variable something like appointmentList
to maitain the list of appointments.

private ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();

Step

Add logic to the method addAppointment()
Build an Appointment object and add the object to the list based on the user input.

Step

Add logic to the method findAppointments()
Iterate through the appointment list and find the appointments based on the user input.


Sample Methods Below

////////////////////////////


import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
Build on the Appointment hierarchy.
Give the user the option to add new appointments.
The user must specify the type of the appointment and
description, and then, if required, the day or date.
*/
public class AppointmentBook
{
   private ArrayList<Appointment> appointmentList = new ArrayList<Appointment>();

   /**
Adds a new Appointment object based on user input.
@param in the Scanner to read from.
   * @throws ParseException
   */
   public void addAppointment(Scanner in) throws ParseException
   {
       System.out.print("Enter Type: [(D)aily, (M)onthly,(O)neTime] and description: ");
       String choice = in.next();
       Appointment a;
       try {
           if (choice.equals("D") || choice.equals("d"))
           {
               String desc= in.next();
               a= new Daily(desc);
           }
           else if (choice.equals("M") || choice.equals("m"))
           {
               String desc= in.next();
               System.out.print("Enter the day of the appointment: ");
               int day =in.nextInt();
               a= new Monthly(desc,day);

           }
           else {
               String desc= in.next();
               System.out.print("Enter the day of the appointment: ");
               int day =in.nextInt();
               int month=in.nextInt();
               int year=in.nextInt();
               a= new OneTime(desc,day,month,year);
           }
           // Adding to the appointment
           appointmentList.add(a);
       } catch (Exception e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
   }

   /**
Method to print all appointments on a certain date.
@param in the Scanner to read from.
   */ public void findAppointments(Scanner in)
   {
       System.out.print("Enter the dd mm yyyy: ");
       int day = in.nextInt();
       int month = in.nextInt();
       int year = in.nextInt();
       System.out.printf("\nYou have the following appointments on (%s/%s/%s):\n", day, month, year);
       for (Appointment a : appointmentList) {
           //Check if the appointment id Daily
           if (a instanceof Daily) {
               System.out.println(a);
           }
           //Check if the appointment id Monthly
           else if(a instanceof Monthly) {
               Monthly m = (Monthly)a;
               if (day == m.getDay()) {
                   System.out.println(a);
               }
           }
           //Check if the appointment id OneTime
           else if (a instanceof OneTime) {
               OneTime ot = (OneTime)a;
               if (day == ot.getDay() && month == ot.getMonth() && year == ot.getYear()) {
                   System.out.println(a);
               }
           }
       }
   }

   // Just to test the appointment book
   public static void main(String[] args) throws ParseException
   {
       Scanner in = new Scanner(System.in);
       AppointmentBook ab = new AppointmentBook();

       System.out.println("Welcome to the Appointment Book");
       System.out.println("-------------------------------");

       boolean done = false;
       while (!done)
       {
           System.out.print("Appointments: (F)ind, (A)dd, or (Q)uit: ");
           String choice = in.next();
           if (choice.equals("F") || choice.equals("f"))
           {
               ab.findAppointments(new Scanner(System.in));
           }
           else if (choice.equals("A") || choice.equals("a"))
           {
               ab.addAppointment(new Scanner(System.in));
           }
           done = choice.equals("Q") || choice.equals("q");
       }
       System.out.println("Good bye. Have a nice day!");
       in.close();
   }
}

///////////////////////////////////////////////////////

Hope this helps.


Related Solutions

I have a table to fill out for a Healthcare Finance class and I'm really struggling...
I have a table to fill out for a Healthcare Finance class and I'm really struggling with the TOTAL UNITS column of the first table and the other colums of the tables after that. Help? Activity Annual Costs Total Units1 Unit Alloc Rate Cost Driver Test A Test B Test C Test D Receive specimen 10,000 5000 Tests 2.00 No. Tests 2,000 1,500 1,000 500 Equipment setup 25,000 Minutes 8.33 Minutes per test 5 5 10 10 Run test 100,000...
JAVA CODE FILL IN THE BLANKS you are to complete the skeleton program by completing *...
JAVA CODE FILL IN THE BLANKS you are to complete the skeleton program by completing * the To Do sections. I would suggest doing this a * little bit at a time and testing each step before you * go on to the next step. * *           Add whatever code is necessary to complete this assignment *********************************************************************/ //Add whatever code is necessary to complete this assignment public class Methods {    public static void main(String[] args)    {...
Python Programming I have a skeleton code here for this project but do not know exactly...
Python Programming I have a skeleton code here for this project but do not know exactly where to start. My task is to implement a reliable File Transfer Protocol (FTP) service over UDP. I need help to write the reliable FTP client and server programs based on an Alternating Bit Protocol (ABP) that will communicate with a specially designated server. In socket-level programming as well... # program description # Library imports from socket import * import sys import time #...
I have code for an AVL tree. I Have have a node class and tree class....
I have code for an AVL tree. I Have have a node class and tree class. I need a  node object that refrences the root(top) of the tree. my current code throws NullPointerException when I try to access the root properties. here is the important snippets of my code, it is in java. public class Node { private Node left=null,right=null; public int height=1; private String Item; private int balance=0; Node(String item) { this.Item=item; } } -------------------------------------------------- public class AVLTree { public...
Purpose Purpose is to implement some single linked list methods. Add methods to the List class...
Purpose Purpose is to implement some single linked list methods. Add methods to the List class In the ‘Implementation of linked lists’ lecture, review the ‘Dynamic implementation of single linked list’ section. You will be adding new methods to the List class. Eight new methods are required: new constructor – creates a new single linked list from an array of integers e.g. int a[] = {1, 2, 3, 4}; List list = new List(a); toString() – returns a string representing...
What is Inflation rate? ***I have to write a report for finance class, would like some...
What is Inflation rate? ***I have to write a report for finance class, would like some ideas to help me out please.
The todo section in java please LinkedStack class (provided as a skeleton) is to implement TextbookStackInterface...
The todo section in java please LinkedStack class (provided as a skeleton) is to implement TextbookStackInterface using chain of nodes to manage the data (see the textbook implementation). The instance variable topNode is defined as chain head reference. The empty stack should have this variable set to null. Skeleton of LinkedStack class is provided. Please note that in addition to all the methods defined in the TextbookStackInterface there are two methods: displayStack and remove that you also need to implement:...
I have a homework class, but I don't really understand anything and I have to submit...
I have a homework class, but I don't really understand anything and I have to submit my homework next week. Homework must be written in C ++ program language. Can someone help me please... Working with classes (everything written below is one task): Define a class Date that contains integer variables for day, month, and year. 1.1. Create the necessary methods for the class: set, get, default constructor, constructor with arguments. 1.2. Create a method that calculates the number of...
I have defined the class. Rectangle in Python. How do I define a class Canvas with...
I have defined the class. Rectangle in Python. How do I define a class Canvas with the following description: Class Canvas represents a collection of Rectangles. It has 8 methods. In addition, to the constructor (i.e. __init__ method) and two methods that override python's object methods (and make your class user friendly as suggested by the test cases), your class should contain 5 more methods: add_one_rectangle, count_same_color, total_perimeter, min_enclosing_rectangle, and common_point.
Hi, I want to implement the following methods with a driver class In the comment block...
Hi, I want to implement the following methods with a driver class In the comment block for add, give the best possible big-O of the worst-case running time for executing a single add operations and give the best possible big-O of the total worst-case running time of executing a sequence of N add operations. here is the Implement class: import java.util.Iterator; // Do not modify the given code. @SuppressWarnings("unchecked") // Given public class MyArrayList { private T[] data; // Given...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT