Question

Programming Assignment 6 Write a Java program that will implement a simple appointment book. The ...

Programming Assignment 6

Write a Java program that will implement a simple appointment book. The program should have three classes: a Date class, an AppointmentBook class, and a Driver class.

• You will use the Date class that is provided on Blackboard (provided in New Date Class example).

• The AppointmentBook class should have the following:

o A field for descriptions for the appointments (i.e. Doctor, Hair, etc.). This field should be an array of String objects.

o A field for the date of the appointments. This field should be an array of Date objects.

o A field to keep track of the number of appointments.

o A constant field for the maximum number of appointments (this field can be set to any value you like). This will be the size for each array created in the constructor.

o A constructor to create an “empty” appointment book of the appropriate size.

o A method to enter a single appointment.

o A method to sort the appointments by Date in ascending order.

o A method to sort the appointments by Date in descending order.

o A method to display the appointment with the earliest (minimum) date (Note: You may not sort the dates in this method).

o A method to display each appointment, one per line.

• The Driver class should do the following:

o Display a menu of choices to the user. The choices are as follows:

1. Enter a new appointment.

2. Sort appointments in ascending order (first to last) by date.

3. Sort appointments in descending order (last to first) by date.

4. Display the next appointment.

5. Display all appointments.

6. Quit.

o Ask the user to make a choice.

o Carry out each choice.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
import java.io.*;
import static
java.lang.System.exit;
import
java.text.ParseException;
import
java.text.SimpleDateFormat;

class AppointmentBook {
  
String appointments_desc
[];
Date d[];
static int number = 0;
final int max = 20;
  
public AppointmentBook()
{
appointments_desc =
new String [max];
d = new Date[max];
}
  
public void
enterAppointment(){
Scanner sc = new
Scanner(System.in);
System.out.println
("Enter Appointment
Description:\t");
String app =
sc.nextLine();
  
System.out.println
("Enter Date:\t");
String dat = sc.next
();
SimpleDateFormat
dateFormat = new
SimpleDateFormat("dd-MMM-
yyyy");
Date dat2=null;
try {
//Parsing the String
dat2 =
dateFormat.parse(dat);
} catch
(ParseException e) {
// TODO Auto-
generated catch block
e.printStackTrace();
}
  
d[number] = dat2;
appointments_desc
[number] = app;
number ++;
}
  
public void sort_a(){
  
Date temp;
String temp1;
for (int i = 0; i <
number; i++)
{
for (int j = i +
1; j < number; j++)
{
if (d
[i].after(d[j]))
{
temp = d
[i];
d[i] = d
[j];
d[j] =
temp;
  
temp1 =
appointments_desc[i];

appointments_desc[i] =
appointments_desc[j];

appointments_desc[j] = temp1;
}
}
}
}
  
public void sort_d(){
  
Date temp;
String temp1;
for (int i = 0; i <
number; i++)
{
for (int j = i +
1; j < number; j++)
{
if (d
[j].after(d[i]))
{
temp = d
[i];
d[i] = d
[j];
d[j] =
temp;
  
temp1 =
appointments_desc[i];

appointments_desc[i] =
appointments_desc[j];

appointments_desc[j] = temp1;
}
}
}
}
  
public void earliest()
{
int min = 0;

for(int i=0;
i<number; i++ )
{
if(d[i].before(d
[min]))
min = i;
}
System.out.println
("Earliest Record:
\t"+appointments_desc
[min]+"\tDate:\t"+d[min]);
}
  
public void displayAll()
{
for(int i=0;
i<number; i++ )

System.out.println
("Appointment:
\t"+appointments_desc
[i]+"\tDate:\t"+d[i]);
}
}

public class Recruitersa_1 {
  
public static void main
(String args[])
{
System.out.println("Enter
Your Choice:\n1. Enter New
Appointment\n2.Sort
Assignments in Ascending
Order (first to last) by
Date\n3.Sort Assignments in
Descending Order (last to
first) by Date\n4.Display the
next appointment\n5.Display
all appointments\n6.Quit");
Scanner sc = new Scanner
(System.in);
int choice = sc.nextInt
();
  
AppointmentBook a = new
AppointmentBook();
  
while (choice!=6)
{
switch (choice)
{
case 1:
a.enterAppointment();
break;
case 2: a.sort_a();
break;
case 3: a.sort_d();
break;
case 4: a.earliest();
break;
case 5: a.displayAll
();
break;
case 6: exit(0);
}
System.out.println
("Enter Your Choice:\n1.
Enter New Appointment\n2.Sort
Assignments in Ascending
Order (first to last) by
Date\n3.Sort Assignments in
Descending Order (last to
first) by Date\n4.Display the
next appointment\n5.Display
all appointments\n6.Quit");
choice = sc.nextInt
();
}
}
}



run: Enter Your Choice: 1. Enter New Appointment 2.Sort Assignments in Ascending Order (first to last) by Date 3.Sort Assiqnm4.Display the next appointment 5.Display all appointments 6.Quit 2 Enter Your Choice: 1. Enter New Appointment 2.Sort Assignm

COMMENT DOWN FOR ANY QUERIES,

AND LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
Programming Assignment 6 Write a Java program that will implement a simple appointment book. The ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An...

    Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. It writes a method occursOn (int year, int month, int day) that checks whether the appointmentoccurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then it will fill an array of Appointment objects with a mixture of appointments. When the user...

  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • (JAVA) In this assignment, you will implement a superclass Appointment and subclasses Onetime, Daily, and Monthly....

    (JAVA) In this assignment, you will 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 mon.th matches. In your application part, fill an array of Appointment objects with a mixture of appointments. Have the...

  • Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has...

    Programming language: JAVA 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, check whether the day of the month matches. Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • Help me with a python program : Implement a superclass appointment and subclasses Onetime, Daily and...

    Help me with a python program : 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(year, month, 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. Then fill a list of appointment objects with a mixture of appointments. Have the user enter a date and print...

  • 5.Implement a superclass Appointment and subclasses Onetime, Daily and Monthly. An appointment has a description (for...

    5.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(year,month,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 and the appointment date started before the date entered. Then, fill a list of Appointment objects with a mixture of appointments. Have the user enter a date and...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • *PYTHON* Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has the date,...

    *PYTHON* Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has the date, the month, the year, and the description of an appointment (e.g., “see the dentist”). Then, write a method occcursOn(year, month, day) that checks whether the appointment occurs on that date. In the test program, you should create a list of appointments using your subclasses of Onetime, Daily, and Monthly. Once you have those appointments available, allow the user to input day, month, and year...

  • [JAVA] Program: Design a Ship class that the following members: A field for the name of...

    [JAVA] Program: Design a Ship class that the following members: A field for the name of the ship (a string) o A field for the year the the ship was built (a string) o A constructor and appropriate accessors and mutators A toString method that displays the ship's name and the year it was built Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT