QuestionQuestion

Problem Description
In this homework, you will be creating a database that can store text messages and filter those messages based on certain constraints!
• Message
o A representaton of a text message.
• Database
o A database of past Messages that have been sent.
Solution Description
Classes:
• Message
o Fields:
Optional<String> contactName
String to
String from
String body
LocalDateTime date
boolean isImportant
o Methods:
Getter methods for all 6 fields.
o Constructor with the following signature.
public Message(Optional<String> contactName, String to, String from, String body, LocalDateTime date, boolean isImportant)
• Database
o Fields:
List<Message> messages
o Methods:
Message getMessage(int n) - Returns the nth message where 0 <= n < size of list.
List<Message> getMessages() - Returns all the messages stored in the database.
List<Message> filter(Predicate<Message> filter) - Returns the list of messages filtered by the predicate. Must not change messages field.
List<Message> getMessagesBetween(LocalDateTime start, LocalDateTime end) - Returns a list of messages if the time that the message is sent is between the start LocalDateTime and the end LocalDateTime (inclusive). Must not change messages field. Must call filter with a lambda expression.
Map<String, List<Message>> sortMessagesByContact() - Returns a Map that stores a contact name as a key and a list of messages from that contact as a value. If a message has no associated contact, it should not appear in the Map. Must not change messages field. Must call filter with an anonymous inner class in the method body.
List<Message> getMessagesWithKeyword(String keyword) - Returns a list of messages if the body of the message contains the keyword. Note: The messages don’t need to match the case of the keyword (ex. “LOL” would match “lol”). Must not change messages field. Must call filter with an instance of an inner class. The inner class must not be anonymous.
List<Message> getMessagesWithPriority() - Returns a list of messages if the message is marked as important. Must not change messages field. Must call filter with a method reference.
o Constructor with the following signature.
public Database(List<Message> messages)
Important: getMessagesBetween(LocalDateTime start, LocalDateTime end), sortMessagesByContact(), getMessageWithKeyword(String keyword), and getMessagesWithPriority() must use filter with a lambda expression, an anonymous inner class, an inner class, and a method reference respectively.
Make the visibility of all the methods and fields as you see best fits good programming style.

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.util.Optional;
import java.time.LocalDateTime;

/*
* Message class
*/
public class Message {
   
    private Optional<String> contactName;
    private String to;
    private String from;
    private String body;
    private LocalDateTime date;
    private boolean isImportant;

    // Constructor
    public Message(Optional<String> contactName, String to, String from, String body, LocalDateTime date, boolean isImportant) {
       this.contactName = contactName;
       this.to = to;
       this.from = from;
       this.body = body;
       this.date = date;
       this.isImportant = isImportant;
    }
   
    // Method to get contactName field
    public Optional<String> getContactName() {
       return contactName;
    }
   
    // Method to get to field
    public String getTo() {
       return...

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

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
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