In Java can you help me fix what is missing MailBox - client:String - emails: Email[] - actualSize: int + Mailbox() + Mailbox(client:String) + getClient(): String + getEmail(int index): Email + getActualSize(): int + addEmail(email: Email): void + sortEmailsByDate(): void + findEmail(year:int: Email + countUrgent():int + toString(): String public class Mailbox { private String bradsInbox; private Email[] emails; privateintactualSize; public Mailbox() { Email[] emails = new Email[15]; actualSize = 0; } public Mailbox(String bradsInbox) { this.bradsInbox = bradsInbox; } public String getBradsInbox() { returnbradsInbox; } public Email[] getEmails() { returnemails; } publicint getActualSize() { returnactualSize; } publicvoid addEmail(Email email) { if (this.actualSize >= 15) { System.out.println("You have reached maximum capacity. Upgrade your account. "); } } publicvoid sortEmailsByDate() { } public Email findEmail(intyear) { for (inti = 0; i < this.actualSize; i++) { if (this.emails[i].getDate().getYear() == year) { returnthis.emails[i]; } } returnnull; } publicint countUrgent() { intnumberOfEmails = 0; for (inti = 0; i < this.actualSize; i++) { if (this.emails[i].isUrgent()) { numberOfEmails++; } } returnnumberOfEmails; } @Override public String toString() { return"Mailbox [bradsInbox=" + bradsInbox + ", emails=" + Arrays.toString(emails) + ", actualSize=" + actualSize + "]"; } } Write java code for all the methods shown on the class diagram. Below are the details needed for the different methods: a. The default constructor will assign the client a default name (any value of your choice). Keep in mind that a single mailbox (e.g., gmail) can handle a maximum of 15 emails, but it can hold less, which is the actual size of the emails array. So, the constructor should instantiate the emails array instance variable by creating an array of size 15. It should also set the actualSize variable to 0. b. The MailBox (String client) constructor should call the default constructor using chaining. It should then initialize the client variable using the client parameter. c. The toString method will format the mailbox information, including the client (e.g., gmail), a count of the urgent emails by calling the countUrgent method, and a list of emails in the the emails array (see sample output). Each element in the emails array represents an email object, so the toString() method of the Mailbox should call the toString method of the Email class (see Email class below). d. The findEmail method that takes the year as a search key and returns the email in the emails array that meets the criteria. For example, findEmail(2022) returns the email that was received in 2022. e. The addEmail method takes an Email object and adds it to the emails array at the next available location keeping the maximum size into account. If the max size is reached it should display “You have reached maximum capacity. Upgrade your account”. f. countUrgent method should return how many emails in the emails array are urgent.
In Java can you help me fix what is missing
MailBox
- client:String
- emails: Email[]
- actualSize: int
+ Mailbox()
+ Mailbox(client:String)
+ getClient(): String
+ getEmail(int index): Email
+ getActualSize(): int
+ addEmail(email: Email): void
+ sortEmailsByDate(): void
+ findEmail(year:int: Email
+ countUrgent():int
+ toString(): String
public class Mailbox
{
private String bradsInbox;
private Email[] emails;
privateintactualSize;
public Mailbox()
{
Email[] emails = new Email[15];
actualSize = 0;
}
public Mailbox(String bradsInbox)
{
this.bradsInbox = bradsInbox;
}
public String getBradsInbox()
{
returnbradsInbox;
}
public Email[] getEmails()
{
returnemails;
}
publicint getActualSize()
{
returnactualSize;
}
publicvoid addEmail(Email email)
{
if (this.actualSize >= 15)
{
System.out.println("You have reached maximum capacity. Upgrade your account. ");
}
}
publicvoid sortEmailsByDate()
{
}
public Email findEmail(intyear)
{
for (inti = 0; i < this.actualSize; i++)
{
if (this.emails[i].getDate().getYear() == year)
{
returnthis.emails[i];
}
}
returnnull;
}
publicint countUrgent()
{
intnumberOfEmails = 0;
for (inti = 0; i < this.actualSize; i++)
{
if (this.emails[i].isUrgent())
{
numberOfEmails++;
}
}
returnnumberOfEmails;
}
@Override
public String toString()
{
return"Mailbox [bradsInbox=" + bradsInbox + ", emails=" + Arrays.toString(emails) + ", actualSize="
+ actualSize + "]";
}
}
Write java code for all the methods shown on the class diagram. Below are
the details needed for the different methods:
a. The default constructor will assign the client a default name (any value of
your choice). Keep in mind that a single mailbox (e.g., gmail) can handle a
maximum of 15 emails, but it can hold less, which is the actual size of the
emails array. So, the constructor should instantiate the emails array
instance variable by creating an array of size 15. It should also set the
actualSize variable to 0.
b. The MailBox (String client) constructor should call the default constructor
using chaining. It should then initialize the client variable using the client
parameter.
c. The toString method will format the mailbox information, including the
client (e.g., gmail), a count of the urgent emails by calling the countUrgent
method, and a list of emails in the the emails array (see sample output).
Each element in the emails array represents an email object, so the
toString() method of the Mailbox should call the toString method of the
Email class (see Email class below).
d. The findEmail method that takes the year as a search key and returns the
email in the emails array that meets the criteria. For example,
findEmail(2022) returns the email that was received in 2022.
e. The addEmail method takes an Email object and adds it to the emails
array at the next available location keeping the maximum size into
account. If the max size is reached it should display “You have reached
maximum capacity. Upgrade your account”.
f. countUrgent method should return how many emails in the emails array
are urgent.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images