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)    {...
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.
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...
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...
I did a glass bottle lab where I have to fill the right amounts of water...
I did a glass bottle lab where I have to fill the right amounts of water to play certain notes. To find frequency, I used f = n (v/4L) where 340 is the constant velocity. My lengths are 17.3 cm, 15.5 cm, and 20.3 cm. I know n is nodes, but I don’t know what numbers to use for it. Please help. Also, this is a open closed system, so n was said to deal with odd numbers. Thanks in...
I have a term paper that I have to write for my microeconomics class. Economics is...
I have a term paper that I have to write for my microeconomics class. Economics is super new to me, this is the first class I've ever taken related to it. My subject is the economic impacts of the opioid epidemic. My outline is due next week and I have no idea what to even do research on or which direction to go. Where do I even start?
I have questions on how to do this in R/Rstudio or smoothing methods. I have been...
I have questions on how to do this in R/Rstudio or smoothing methods. I have been struggling with using the codes. I have been practicing and tryign to do it, but I am really unsure at where I am with it. Just need something to compare it too! I don't understand why there isn't any information under the demand section! (1) A memo written to the Chief Operations Officer of Transantiago that describes the model and method and presents the...
Part I: Have a program class named TestArrays This class should have a main() method that...
Part I: Have a program class named TestArrays This class should have a main() method that behaves as follows: Have an integer array of size 10. Using a loop, fill the elements with increments of 5, starting with 5 in the first element. Using the array elements, sum the second, fifth and seventh elements. Display the sum with a label. Change the fourth element to 86. Subtract 9 from the ninth element. Using a loop, display the elements of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT