QuestionQuestion

File Input
Your program will accept two arguments on the command line, which are non-empty strings giving the names of two files in the current directory.
The first file will contain descriptions of blood donors. Each line of the file will contain one record of data. Each record will be represented by several strings, separated by slashes, in the following order:

1. An integer which will serve as a unique identifier for this donor throughout the program.
2. A string representing the donor’s family name (e.g. “Davis”, “Lopez”, “Shen”)
3. A string representing the donor’s given name (e.g. “Alice”, “Bob”, “Chris”)
4. A string representing the donor’s blood type. This string will be two or three characters long: one of the strings “O”, “A”, “B”, or “AB”, followed by a “+” or “-”. (Note that every blood type must have a “+” or “-”.)

The second file will contain descriptions of blood donations. Again, each line of the file will contain one record of data. Each record will be represented by several strings, separated by slashes, in the following order:

1. An integer representing the person making this donation. This integer will match one of the records in the other file.
2. An eight-digit integer representing the date of this donation. The integer will be in the format “yyyymmdd”, where “yyyy” is the four-digit year, “mm” is the two-digit month (01-12), and “dd” is the two-digit date. (For example, the date 14 July 2003 would be represented by the integer 20030714.)

Your program will begin by reading in this information and storing it internally in an appropriate format. (See Internal Requirements.)

Interactive Input
Your program will begin by printing the current date to the screen. (See the accompanying
LocalDate Crib for more information on how to obtain this information.)
Your program will then interact with the user running the program, offering the user a menu of commands. The following commands should be offered at this time:

Print the list of blood donors. If selected, the program should print all blood donors in the database in an appropriate format.
In addition, for each donor, the program should print the date of the latest donation made by the donor (if any), and whether or not the donor is eligible to donate blood today. Donors are eligible to donate blood if their last donation was at least 56 days ago. (Note that donors who have never donated blood are always eligible to donate.)
Search the database for a specific donor. If selected, the program should ask the user for the desired donor’s ID number. Using that name, the program should display the donor in the database with a matching ID number, including the latest donation made by the donor and whether or not the donor is eligible to donate blood today (as in the general print command). Additionally, for that donor, the program should also display all dates of donation. If no donor with a matching ID number can be found, an appropriate message should be displayed.
Search the database for a specific blood type. If selected, the program should ask the user for the desired blood type. Using that value, the program should display all donors (if any) in the database with the identical blood type. For each matching donor, the program should also display the date of last donation and eligibility for donation. If no matching record can be found, an appropriate message should be displayed.
• Exit the program. If selected, the program should terminate.

Internal Requirements
Your program should validate input whenever possible. For example, you should check that the user provides two arguments on the command line, that database entries read from the input file meet the required format, and that the user provides valid options during the interactive phase of the program.
Your program should catch (and handle appropriately) all exceptions generated by any system routines you use, as well as any exceptions you generate yourself. (That is, your main method should not throw any exceptions.)
Your program should be designed with modifiability in mind. You will be revising and extending this program several times throughout the semester; consequently, it is to your benefit to design your program in as modular a fashion as possible. In particular:

You should define a class Donation which contains members corresponding to a given donation, and methods which deal with donations (e.g. getID, getDate).
Important Note: You are strongly enouraged to use LocalDate objects to rep- resent dates. This will make operations dealing with dates much simpler. (See the accompanying LocalDate Crib for more information.)

You should define a class Person which contains members corresponding to a given blood donor, and methods which deal with person objects (e.g. print, getFamilyName).
You should define a class Database which contains methods which allow one to manip- ulate a collection of Person and Donation objects (e.g. search, print). The Database class should never access the internal members of the Person and Donation classes directly.
For this assignment, your Database object should use two unordered arrays: one of Person objects, and one of Donation objects. You should define the sizes of these arrays using final constants and use those constants appropriately.
You should define a class Prog1 with a main method which calls the Database class to perform the required operations. The Prog1 class should never access the internal members of the other classes directly.

You will be replacing these classes several times through the semester as we learn about different data structures and algorithms. Thus, it is to your advantage to make your design as modular as possible. A little bit of extra work now will make your work simpler as the term progresses.

A Sample Session
Here is a sample donor data file which could be read by this program:

3441034/Coleman/Louise/A- 344155515/Gondorff/Henry/AB+ 993383/Snyder/William/O+ 5595/Salino/Loretta/A-

Here is a sample donation data file which could be read by this program:

344155515/20040421
5595/20171119
344155515/20050103
993383/20180108
344155515/20041102
993383/20170605
993383/20170928

And here is a sample interactive session:
nova -: java Prog1 personfile donationfile

Welcome to the CS-102 Blood Donor Database Program. Today’s date is 1/12/2018.

Current available commands:
1 --> Print all donors
2 --> Search for a donor
3 --> Search for a blood type
9 --> Exit Your choice? 1

Louise Coleman (3441034) Blood Type: A-
Last Donation Date: none Eligible to donate today: yes

Henry Gondorff (344155515) Blood Type: AB+
Last Donation Date: 1/3/2005 Eligible to donate today: yes

William Snyder (993383) Blood Type: O+
Last Donation Date: 1/8/2018 Eligible to donate today: no

Loretta Salino (5595) Blood Type: A-
Last Donation Date: 11/19/2017 Eligible to donate today: no

Current available commands:
1 --> Print all donors
2 --> Search for a donor
3 --> Search for a blood type
9 --> Exit Your choice? 2
Donor ID Number? 344155515 Henry Gondorff (344155515)
Blood Type: AB+
Last Donation Date: 1/3/2005

Eligible to donate today: yes Donations:
4/21/2004
1/3/2005
11/2/2004

Current available commands:
1 --> Print all donors
2 --> Search for a donor
3 --> Search for a blood type
9 --> Exit Your choice? 3

Blood type? A-

Louise Coleman (3441034) Blood Type: A-
Last Donation Date: none Eligible to donate today: yes

Loretta Salino (5595) Blood Type: A-
Last Donation Date: 11/19/2017 Eligible to donate today: no

Current available commands:
1 --> Print all donors
2 --> Search for a donor
3 --> Search for a blood type
9 --> Exit Your choice? 9

Notice that this is a sample run; your run may operate differently (and appear differently) as long as it fulfills the requirements outlined above.
You should create several input files in order to test your program thoroughly; do not assume that simply testing the program on the input file shown above is sufficient to test your program. (What happens if the input file is empty? What if it contains too many entries? How will you handle these cases?)

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.io.*;
import java.time.LocalDate;

/*
* Database class
*/
public class Database {

final int NUMBER_OF_PERSONS = 100;
final int NUMBER_OF_DONATIONS = 100;

private Person[] persons;
private Donation[] donations;

// Constructor
public Database() {
    persons = new Person[NUMBER_OF_PERSONS];
    donations = new Donation[NUMBER_OF_DONATIONS];
}

// Method to add person to Database
public void addPerson(Person person) {
    for (int i = 0; i < NUMBER_OF_PERSONS; i++) {
      if (persons[i] == null) {
       persons[i] = person;
       return;
      }
    }
}

// Method to load Person objects from file to Database
public void loadPersons(String personsFile) {
    try(BufferedReader br = new BufferedReader(new FileReader(personsFile))) {
      for(String line; (line = br.readLine()) != null; ) {
       String[] params = line.split("/");
       int ID = Integer.parseInt(params[0]);
       String lastName = params[1];
       String firstName = params[2];
       String bloodType = params[3];
       Person person = new Person(ID, lastName, firstName, bloodType);
       addPerson(person);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
}

// Method to add Donation to database
public void addDonation(Donation donation) {
    for (int i = 0; i < NUMBER_OF_DONATIONS; i++) {
      if (donations[i] == null) {
       donations[i] = donation;
       return;
      }
    }
}

// Method to load Donation objects from file to Database
public void loadDonations(String donationsFile) {
    try(BufferedReader br = new BufferedReader(new FileReader(donationsFile))) {
      for(String line; (line = br.readLine()) != null; ) {
       String[] params = line.split("/");...

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

50% discount

Hours
Minutes
Seconds
$70.00 $35.00
for this solution

or FREE if you
register a new account!

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.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
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