Lab 6
Nov 7 by 11:59pm
INSTRUCTIONS
-
In an Eclipse project, set up files hierarchy and names following these instructions:
-
Package name: labs.lab6
-
Add classes:
-
Bank
-
BankAccount
-
Mailbox
-
Message
-
MessagingSystem
-
Product
-
ProductDB
-
Student
-
TextImprover
-
Make sure your methods pass all the examples/test cases suggested. Keep in mind that for grading, we will test other additional values to the ones provided here.
-
For submission:
-
Upload Bank.java, BankAccount.java, Mailbox.java, Message.java, MessagingSystem.java, Product.java, ProductDB.java, Student.java, and TextImprover.java to the Gradescope assignment. Run the sample autograder (which uses the below JUnit test file) as many times as you wish up until the deadline. The test file used for grading will be similar to this one, but will contain different test cases, as well as additional test cases. So be sure to carefully and thoroughly do your own testing of your code as well.
-
Be sure to read the Lab Submission Checklist before submitting your code to Gradescope.
JUNIT TEST FILE FOR LAB6: Lab6Test.java (note: all the
input files used by the test file are available in Files -> Lab6 -> res)
PROBLEM PROMPTS Part A:
Problem 1 and 2: TextImprover (20 pts)
There are some words that people tend to overuse when writing documents, such as "amazing," "literally," "actually," "absolutely," etc. For this problem, you will implement a class that searches for overused words and replaces them with better choices. Implement a class TextImprover that provides a method for improving the text in a text file (let's call it the "input file") by replacing overused words with better choices of words, based on another text file (let's call it "word map") that maps overused words to non-overused words. Use this template: TextImprover.java A few notes: Assume the words in the word map will always be in all lower case and consist of only letters. TextImprover must preserve word case. But you can assume all words in the input file are either in all lower case, leading upper case, or all caps. Assume every word in the input file consists of at least one letter and also include punctuation characters, and there is exactly one space in between each word in a line. TextImprover must preserve the punctuation of the input file. You must catch any FileNotFoundException that is thrown and print out a message in the format: "File: [filename] not found", e.g., File: overused1.txt not found Example: // all examples use overused-words.txt as the file containing overused words and their replacements TextImprover ti = new TextImprover("overused-words.txt"); // overused1.txt starts out like this: overused1.txt
ti.improveText("overused1.txt"); // overused1.txt now looks like this: overused1-after.txt
// overused2.txt starts out like this: overused2.txt
ti.improveText("overused2.txt"); // overused2.txt now looks like this: overused2-after.tx
Problem 3: Student (10 pts)
Given a Student class (Student.java), modify the class to throw an IllegalArgumentException under the following two conditions:
- The account is constructed with a negative student ID (exception message: "ID cannot be negative")
- An attempt is made to drop a class in which the student is not enrolled (exception message: "Cannot drop class [CLASSNAME] because student is not enrolled in it") Example:
try { Student george = new Student("George Glass", -1234);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
} // The above prints out "ID cannot be negative"
Student robert = new Student("Robert Navarro", 1234);
robert.addClass("ICS 45J");
robert.addClass("Ballet I");
robert.addClass("Chem 51C");
try { robert.dropClass("ICS 10");
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
} // The above prints out "Cannot drop class ICS 10 because student is not enrolled in it"
Problem 4: Product and ProductDB (10 pts)
Robert recently went into business for himself with a pet store! However, he spends so much time sleeping on his couch that he is unaware of modern technology. So in his store, they keep all the data about their products in a text file. Each line in this text file contains the following, separated by semicolons: The name of the product The price of the product The quantity of product Sample file here: products.txt
Implement a class Product that is represented by a name, price, and quantity. Use this template: Product.java
Also implement a class ProductDB that reads in data from a text file and provides methods for searching and adding products. Use this template: ProductDB.java
You must catch any FileNotFoundException that is thrown and print out a message in the format: "File: [filename] not found", e.g., File: products1.txt not found Example:
ProductDB db = new ProductDB("products.txt db.findProduct("Blue plaid bow tie collar"); // returns the product "Blue plaid bow tie collar" with price 29.95 and quantity 6
db.findProduct("Red bandana"); // returns the product "Red bandana" with price 3.99 and quantity 16
db.findProduct("White porcelain food and water bowl set"); // returns the product "White porcelain food and water bowl set" with price 23.00 and quantity 8
db.findProduct("XL tan fluffy dog bed"); // returns the product "XL tan fluffy dog bed" with price 75.25 and quantity 2
db.findProduct("stuffed sloth"); // returns null
db.addProduct("stuffed sloth", 9.99, 4);
db.findProduct("stuffed sloth"); // returns the product "stuffed sloth" with price 9.99 and quantity 4
db.addProduct("stuffed sloth", 10.99, 16);
db.addProduct("stuffed sloth", 0.99, 1);
db.findProduct("stuffed sloth"); // returns the product "stuffed sloth" with price 9.99 and quantity 4
// products.txt now looks like this: products-after.txt
Problem 5: BankAccount and Bank (10 pts) Implement a class BankAccount that is represented with an account number and balance. Use this template: BankAccount.java
Also implement a class Bank that contains a number of bank accounts, read from a file, and provides a method for returning the account with the lowest balance. Use this template: Bank.java
The Bank class must read a file with the format of these sample files: accounts1.dat, accounts2.dat, accounts3.dat, accounts4.dat
Namely, the format is: accountNumber1 balance1 accountNumber2 balance2 . . . You can assume that all input files are in the correct format. You must catch any FileNotFoundException that is thrown and print out a message in the format: "File: [filename] not found", e.g., File: accounts1.dat not found Example:
Bank bank = new Bank(); bank.readFile("accounts1.dat"); bank.getLowestBalanceAccount(); // returns account #2 bank.readFile("accounts2.dat"); bank.getLowestBalanceAccount(); // returns account #4
Part B:
Problems 6-10: Email (50 pts)
Implement a simple e-mail messaging system. A message has a recipient, a sender, and a message text. A mailbox can store messages. Each user has a mailbox. Your program will take four commands: Log in, log out, send, read, and quit. When logging in, the program will ask for just a username. When asking to send a message, the program will ask for the recipient's username and the test of the message. When asking to read messages, the system will display all of the user's messages. The driver / user interface class for the email system, EmailUI, has already been implemented as is given here: EmailUI.java. Your task is to implement the Message, Mailbox, and MessagingSystem classes, using these templates: Message.java, Mailbox.java, MessagingSystem.java. Notice the templates have more details about each class.
Example: emailOutput.txt
download_frd=1)
This tool needs to be loaded in a new browser window The session for this tool has expired. Please reload the page to access the tool again