In this assignment you will practice
In this homework, you will be creating a database that can store text messages and filter those messages based on certain constraints!
Message
Database
Message
s that have been sent.Classes:
Message
Optional<String> contactName
String to
String from
String body
LocalDateTime date
boolean isImportant
public Message(Optional<String> contactName, String to, String from, String body, LocalDateTime date, boolean isImportant)
Database
List<Message> messages
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.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.
If anything seems confusing, read through the entire description and instructions again. As always, feel free to contact your TAs, post on Piazza, or come in for TA office hours. In addition, here are some tips specific to this homework:
Import java.util.function.Predicate
, java.util.Optional
, java.time.LocalDateTime
, java.util.List
, java.util.Map
, and any class that implements List or Map. Do not import anything that oversimplifies the assignment.
If there are any classes that you are unfamiliar with (e.g. Predicate, LocalDateTime, Optional), look them up in the Java API.
Test things out in JShell!
Submit code that compiles!!!
Non compiling code will receive an automatic zero.
Message (15 points)
Database (85 points)
messages
is correctly declared and assignedgetMessage(int n)
getMessages()
getMessagesBetween(LocalDateTime start, LocalDateTime end)
sortMessagesByContact()
getMessageWithKeyword(String keyword)
getMessagesWithPriority()
filter(Predicate<Message> filter)
For each of your homework assignments we will run checkstyle and deduct one point for every checkstyle error.
For this homework the checkstyle cap is 100, meaning you can lose up to 100 points on this assignment due to style errors.
java -jar <path-to-checkstyle.jar> -a *.java
.When completing homeworks for CS 1331 you may talk with other students about:
OKAY: “Hey, I’m really confused on how we are supposed to implement this part of the homework. What strategies/resources did you use to solve it?”
BY NO MEANS OKAY: “Hey… the homework is due in like 20 minutes… Can I see your code? I promise won’t copy it directly!”
In addition to the above rules, note that it is not allowed to upload your code to any sort of public repository. This could be considered an Honor Code violation, even if it is after the homework is due.
Submit each of your Java source files necessary for Database to compile on Canvas as separate attachments. When you’re ready, double-check that you have submitted and not just saved a draft. Download each file and compile them to assure that nothing went wrong with the submission process.
Files needed:
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.