In this programming assignment, you will demonstrate your knowledge of dynamic data structures (in particular, binary search trees) by revising the blood donor database program from Programming Assignment 3 to incorporate a new dynamic data structure.

New Internal Requirements
For this assignment, you should replace your Database class with another implementation which uses a dynamic binary search tree of dynamic linked lists to organize the information within the database. That is, your database will contain a binary search tree of donors; each donor will contain a corresponding dynamic linked list of donations for that donor. The sort order for the upper binary search tree is the same as used in previous assignments (i.e. sorted first by family name, then by given name, in standard dictionary order).

As before, you may use any variations on binary search trees (dummy head nodes, extra pointers, etc.) which you might find useful. You are required to use your hand-built dynamic linked lists from Programming Assignment 2 as the linked list for this data structure, not the built-in java. util.LinkedList.

New Functional Requirements
Your program will be an extension of Programming Assignment 3, and thus should operate in the same manner as that assignment, unless otherwise specified herein. In particular, this means that any errors present in your submissions for Programming Assignment 3 should be fixed for this assignment.

The following new requirements should be implemented as well:
A new option should be added to the main menu which allows the user to write the entire contents of the database to disk. If selected, the program should prompt the user for the names of two files in the current directory to be used for writing the desired information.

The program should then write all records from the database to those files, in the same format used for input. That is, it should be possible to use the output of this command as input to the program at some future time.

The donor tree should be written using a pre-order traversal of the binary search tree. (This permits the read-from-file command to recreate the tree using the same structure.)

A new option should be added to the main menu which allows the user to re-initialize the database. If selected, the program should prompt the user for two file names. If either file does not exist, an error message should be issued and the program should leave the current database unmodified. If the files do exist, the program should delete the current (internal) database and create a new database based upon the files, as if the program had been originally started with those files as command-line arguments.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.time.LocalDate;
import java.util.Scanner;

* Prog4 class
* - Revised structure to use Binary Search Tree of Persons
* - Revised structure to use Dynamic Linked List of Donations
* - Added option to save persons and donations to file
* - Added options to load persons and donations from file
public class Prog4 {

// Method to display menu
public static int displayMenu(Scanner s) {
    System.out.println("Current available commands:");
    System.out.println("1 --> Print all donors");
    System.out.println("2 --> Search for a donor");
    System.out.println("3 --> Search for a blood type");
    System.out.println("4 --> Add new donor");
    System.out.println("5 --> Add new donation");
    System.out.println("6 --> Find compatible blood donors");
    System.out.println("7 --> Write database to files");
    System.out.println("8 --> Load database from files");
    System.out.println("9 --> Exit");
    while (true) {
      System.out.print("Your choice? ");
      String input = s.nextLine();
      if (input.equals("1")) return 1;
      else if (input.equals("2")) return 2;
      else if (input.equals("3")) return 3;
      else if (input.equals("4")) return 4;
      else if (input.equals("5")) return 5;
      else if (input.equals("6")) return 6;
      else if (input.equals("7")) return 7;
      else if (input.equals("8")) return 8;
      else if (input.equals("9")) return 9;
      else System.out.println("Error: Invalid choice\n");

// Main method for program execution
public static void main(String[] args) {
    if (args.length < 2) {
      System.out.println("Error: Please specify personfile donationfile");
    //args = new String[2];
    //args[0] = "personfile";
    //args[1] = "donationfile";
    Database database = new Database();
    // Load persons file
    if (args.length >= 1)
    // Load donations file
    if (args.length >= 2)...

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats