Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this java project, please: Add a new method to the Library class called addRequest , which has a parameter of type

I need help with this java project, please:

Add a new method to the Library class called addRequest, which has a parameter of type Request. The method makes a copy of the parameter and adds it to the listOfRequests instance variable.

Below is the method header:

/**

* The addRequest method adds a request to the library's list of requests.

* @param requestObj the Request object to be added to the list.

*/

public void addRequest(Request requestObj)

{

//provide implementation

}

Modify the LibrarySystem_ExtraCredit class to add a new static method called processLineOfData that has a String parameter and the return type is void.

The parameter represents comma separated data which could be data for a Member or a Request. See the note below for the expected format for each type of data.

Im providing you with an algorithm below:

public static void processLineOfData(String line) throws Exception

{

// Split the line parameter on the comma.

// Get the first field to determine the record type:

// M -> Member

// R -> Request

// If the line has Member data, create a Member object and add it to

// the librarys listOfMembers variable (use the addMember method of

// the Library class).

// If the line has Request data, create a Request object and add it

// to the librarys listOfRequests variable (use the addRequest

// method of the Library class).

// If the line is none of those two types, throw an Exception

// object with the message Bad record.

}

After running the program, the output generated should match that in the LibrarySystem_ExtraCredit_0utput.txt file.

The following is the expected format for the string that may be passed to the processLineOfData method:

Member:

M,id,first,last,phone

Request:

R,member id,item id,date,status

Here is the code for modifying:

package librarysystem_phase2;

import java.util.ArrayList;

public class LibrarySystem_ExtraCredit

{

private static Library theLibrary;

public static void main(String[] args)

{

ArrayList members = new ArrayList<>();

ArrayList requests = new ArrayList<>();

theLibrary = new Library("The Great Library", members, null, requests);

try

{

processLineOfData("M,1,John,Smith,305-565-5656");

processLineOfData("M,2,Amy,Doe,305-111-1111");

processLineOfData("M,3,Robert,Brown,305-565-5446");

processLineOfData("R,1,5,08/06/2018,Download Complete");

processLineOfData("R,2,2,07/01/2018,Checked Out");

processLineOfData("R,3,1,08/21/2018,Checked Out");

processLineOfData("R,2,3,07/06/2018,Download Complete");

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

System.out.println(" **********************************");

System.out.println("* Displaying library information *");

System.out.println("**********************************");

System.out.println(theLibrary);

}

public static void processLineOfData(String line) throws Exception

{

// provide implementation

}

}

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

Why do people behave unethically?

Answered: 1 week ago