logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Write an accessor method, getMessage, that takes a parameter of type int to represent the index of any given message in the ArrayList.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Instructions for Part 1:

1. Please find the Code Check page for this project: Chapter 8 Project

2. Using your IDE (jGrasp, Eclipse, other), create a new project folder called Message

1. Inside this project folder, create a class file named Message.java

3. Write the Class comment describing the class and @author and @version tags

4. Declare and initialize 3 instance variables for:

1. The recipient as type String

2. The sender as type String

3. The messageText as type String

Remember to declare them "private" instead of "public".  Also, please make sure to use the "this" keyword anytime you use your instance variables after declaring them.

5. Create a Constructor that takes a recipient and sender as parameters of type String.

1. Inside the constructor, initialize the recipient and sender instance variables with the parameters.  The messageText instance variable can be initialized as an empty String "".

6. Write a mutator method, append, that takes a String line of text as a parameter

1. Inside this method, append (i.e. add onto) the String line of text to the existing messageText separated by a newline, \n.  (This is a bit like total = total + "\n" + value except with Strings)

7. Write a toString method that returns the entire message in the form:

o From: Mark Fowler   //sender instance variable

To: Samantha Jones  //recipient instance variable

 

Dear Samantha,  //All of this is the message text

It is my great pleasure to

offer you a position in the company.

Sincerely, Mark  //Part of message text

o You can do all of this in one line of code using your instance variables, the words "To", "From", and newline escape sequence, "\n" (or in multiple lines of code).  Just remember that you are returning one String object from the method - you are not printing the String.

8. Write a method, print, that prints the output of a call to the toString method.

9. Once you have written all methods of the Message Class, please test your methods by downloading and saving the following tester file (you can right-click and save as if it does not automatically download): MessageTester.java   This file needs to be in the same project folder as Message.java in order to run correctly.  Run MessageTester and check for errors in your Message class.

10. We will copy our code over to Code Check for testing and submission after Part 2.

PART 2: 

Mailbox.java

This class will model an email mailbox that stores email messages.  We will be using an ArrayList to store the messages created in the Message class.

UML Diagram

 Instructions for Part 2:

1. Again, we will be using the Code Check site:  Chapter 8 Project

2. In the same project folder from Part I, create a new class file named Mailbox.java

3. Write the Class comment and @author and @version tags

4. Create one instance variable of type ArrayList<Message> to hold the messages.

5. Write a Constructor that takes no parameters

o Inside the constructor, initialize the messages instance variable as a new, empty ArrayList of type Message.

6. Write a mutator method, addMessage, that takes a parameter of type Message (object) to represent a new message.  (Hint: This is just like String message, except the object type is Message instead of String)  *Remember, we wrote the Message class to represent an email message, just as Java developers wrote the String class for us to use.

o Inside this method, add the message parameter to the instance variable ArrayList.

7. Write an accessor method, getMessage, that takes a parameter of type int to represent the index of any given message in the ArrayList.

o Inside this method, get and return the message located at the given index of the ArrayList instance variable (there is an ArrayList method for this!).

8. Write a mutator method, removeMessage that takes a parameter of type int to represent the index of any given message in the ArrayList.

o Inside this method, remove the message located at the given index from the ArrayList instance variable (there is an ArrayList method for this!).

9. Once you have written all methods of the Mailbox Class, please test your classes by adding the lines in this text file, mailbox.txt (right-click and "save as"), to your existing MessageTester.java class (you can right-click and select save as and then cut and paste).  You can add these lines to the end of the statements already in the class.  Do not delete any lines.  Run MessageTester.java and check for errors in your Mailbox class.

10. Now that you have written both classes, go to the Code Check website and copy your code into the ... inside the code.  I have included the opening and closing { } for each class - please do not duplicate.  When you submit your code, it will be tested with the given data, and you will have a chance to error check and correct your code.

 

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

872 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

849 Answers

Hire Me
expert
Husnain SaeedComputer science

907 Answers

Hire Me
expert
Atharva PatilComputer science

774 Answers

Hire Me

Get Free Quote!

345 Experts Online