Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 15.1 Suppose you write a program to keep track of daily appointments. Create a project in your NetBeans, and import the source files: Time.java

Lab 15.1

Suppose you write a program to keep track of daily appointments.

Create a project in your NetBeans, and import the source files:

Time.java

Lab15_Main.java

post it down below

codes are at the bottom

Lab 15.2

Add an Appointment class to your project; make sure your Appointment class implements the Comparableinterface and includes:

Time data field for the start time

Time data field for the end time

constructor that initializes the data fields to start Time and end Timeparameters

the overridden toString method that returns the Appointment as the string "hh1:mm1 - hh2:mm2", where "hh1:mm1" is the start Time as a string, and "hh2:mm2" is the end Time as a string

the overridden compareTo(Appointment other)method that returns the result of calling the compareTo method for thisAppointment's start Time with the other Appointment's start Time as the argument

Lab 15.3

Complete the code in Lab15_Main.java (main method):

Add the code to randomly create Appointments and add each to the apptBook priority queue.

Add the code to output the apptBookpriority queue.

Add the code to remove each Appointment form the apptBookpriority queue and add it to the sortedBook linked list.

Add the code to use a for-each (enhanced for) loop to display the sortedBook linked list, one Appointment per line.

Sample output:

Appointments (priority queue): [00:00 - 05:45, 01:15 - 16:46, 01:57 - 21:11, 03:25 - 11:09, 02:19 - 20:47, 04:09 - 07:16, 06:57 - 09:19, 11:36 - 19:16, 05:24 - 12:55, 02:30 - 09:23, 06:19 - 18:44, 08:03 - 09:12, 04:35 - 13:43, 12:01 - 23:51, 18:44 - 21:41, 18:23 - 20:29, 20:20 - 23:42, 09:06 - 22:11, 17:15 - 19:18, 14:38 - 15:47] Appointments: 00:00 - 05:45 01:15 - 16:46 01:57 - 21:11 02:19 - 20:47 02:30 - 09:23 03:25 - 11:09 04:09 - 07:16 04:35 - 13:43 05:24 - 12:55 06:19 - 18:44 06:57 - 09:19 08:03 - 09:12 09:06 - 22:11 11:36 - 19:16 12:01 - 23:51 14:38 - 15:47 17:15 - 19:18 18:23 - 20:29 18:44 - 21:41 20:20 - 23:42

Time:

/* * Time.java * * represents a time as numbers of hours and minutes * in a 24-hour clock (0 hours == midnight) */ public class Time implements Comparable

Main:

/* * Lab15_Main.java * * CPS 151.02 * Fall 2017 * Lab Project 15: Java Collections Framework (Priority Queues) * * name: */ import java.util.*; public class Lab15_Main { public static void main(String[] args) { final int NUM_APPTS = 20; final Random rand = new Random(); Time nextStart, nextEnd; Appointment nextAppt; PriorityQueue apptBook = new PriorityQueue(); LinkedList sortedBook = new LinkedList(); /* * Lab 15.3: add NUM_APPTS Appointments to the apptBook priority queue by * randomly generating start and end times. Make sure the start * time is prior to the end time for each appointment. * * *** ADD CODE AFTER THE FOLLOWING LINE *** */ /* * Lab 15.3: output the apptBook. In what order are the appointments listed? * Copy/paste the output into the space provided on the lab project page. * * *** ADD CODE AFTER THE FOLLOWING LINE *** */ System.out.println("Appointments:"); /* * Lab 15.3: remove each Appointment from the apptBook and add it to the * sortedBook linked list. * * *** ADD CODE AFTER THE FOLLOWING LINE *** */ /* * Lab 15.3: use a for-each (enhanced for) loop to display the sortedBook, * such that one Appointment is output per line * * *** ADD CODE AFTER THE FOLLOWING LINE *** */ } // end main } // end Lab15_Main 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

1. Who will you assemble on the team?

Answered: 1 week ago

Question

4. Who would lead the group?

Answered: 1 week ago