Question: Create a database that can store texts and filter them. Rules: (already made Text.java) Make a class called DBase (database for text) with these: It

Create a database that can store texts and filter them.

Rules: (already made Text.java)

Make a class called DBase (database for text) with these: It should include one field with "List messages", a constructor, and have the following methods.

1. Text getText(int n) : Returns the nth text where 0 <= n < size of list.

3. List filter(Predicate filter) - Returns the list of texts filtered by the predicate.

4. List getTextBetween(LocalDateTime start, LocalDateTime end) - Returns a list of texts if the time that the text is sent is between the start LocalDateTime and the end LocalDateTime (inclusive). Must use filter method with a lambda expression.

5. Map> sortTextsByContact() - Returns a Map that stores a contact name as a key and a list of messages from that contact as a value. If a text has no associated contact, it should not appear on the Map. Must use filter method with an anonymous inner class in the method body.

6. List getTextsWithKeyword(String keyword) - Returns a list of texts if the body of the text contains the keyword. Must use filter method with an instance of an inner class and it can't be anonymous. Additional: The text doesnt need to match the case.

7. List getTextsWithPriority() - Returns a list of texts if the text is marked as important. Use filter method with a method reference.

Text.java

import java.util.Optional; import java.time.LocalDateTime; public class Message { private String to; private String from; private String body; private LocalDateTime date; private boolean isImportant; private Optional contactName;

public Message(Optional contactName, String to, String from, String body, LocalDateTime date, boolean isImportant) { setTo(to); setFrom(from); setBody(body); setDate(date); setIsImportant(isImportant); setContactName(contactName); }

public String getTo() { return this.to; } public void setTo(String to) { this.to = to; }

public String getFrom() { return this.from; }

public void setFrom(String from) { this.from = from; }

public String getBody() { return this.body; }

public void setBody(String body) { this.body = body; }

public String getDate() { return this.date; }

public void setDate(LocalDateTime date) { this.date = date; }

public boolean getIsImportant() { return this.isImportant; }

public void setIsImportant(boolean isImportant) { this.isImportant = isImportant; }

public Optional getContactName() { return this.contactName; }

public void setContactName(Optional contactName) { this.contactName = contactName; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!