Question
In java please. Construct a UML diagram of the code provided below. Be sure to include all attributes, constructors, and methods. Denote visibility modifiers, multiplicity,
In java please.
Construct a UML diagram of the code provided below. Be sure to include all attributes, constructors, and methods. Denote visibility modifiers, multiplicity, and associations. You do not have to specify between aggregation and composition, but if the association is one way, indicate with an arrow.
The assignment will be graded on: 1. Completeness of methods and attributes listed. 2. Static attributes denoted with an underline. 3. Visibility modifiers properly noted. 4. Associations are shown with direction and name of association. 5. Multiplicity of associations are shown.
Provided code:
Mainclass.java provided code:
public class Main { public static void main(String args[]) { Mailbox mailbox = new Mailbox(10); for(int i = 0; i < 5; i ++){ Mail m = new Mail("brian", "This is message " + i); boolean success = mailbox.receiveMail(m); if(!success && !m.getPostMarked()){ System.out.println("Failed to send message."); } else { System.out.println("Sent message."); } } System.out.println(""); System.out.println("The mailbox now has " + mailbox.getNumMail() + " mails."); System.out.println(""); mailbox.showMailBox(); System.out.println(""); System.out.println(mailbox.readMail(0)); System.out.println(mailbox.readMail(3)); System.out.println(mailbox.readMail(100)); System.out.println(mailbox.readMail(8)); System.out.println(""); mailbox.showMailBox(); System.out.println(""); } }
Mailbox.java provided code:
public class Mailbox { private int boxSize; private Mail[] box; Mailbox(int boxSize){ this.boxSize = boxSize; box = new Mail[boxSize]; } public int getNumMail(){ int num = 0; for( int i = 0; i < this.boxSize; i++ ){ if ( box[i] != null ){ //checking if null is a hint num++; } } return num; } public boolean receiveMail(Mail m){ for( int i = 0; i < this.boxSize; i++ ){ if ( box[i] == null ){ m.postMark(); box[i] = m; return true; //this concept of breaking early may need hint } } return false; } public String readMail(int i){ if(i < 0 || i >= this.boxSize){ return "Invalid mail slot!"; } else { if(box[i] == null){ return "No mail at this slot."; } else { return box[i].getMessage(); } } } public void showMailBox(){ System.out.println("========"); for (int i = 0; i < this.boxSize; i++){ if (box[i] != null){ String read = "u"; if(box[i].getRead() == true){ read = "r"; } System.out.printf("%d %s %s ", i, read, box[i].getFrom()); } else { System.out.println("Empty."); } } System.out.println("========"); } }
mail.java provided code:
public class Mail { private boolean postMarked; private boolean read; private String message; private String from; Mail(){ this.message = ""; this.from = ""; } Mail(String from, String message){ this.message = message; this.from = from; } public boolean getRead(){ return this.read; } public String getMessage(){ this.read = true; return this.message; } public String getFrom(){ return this.from; } public boolean getPostMarked(){ return this.postMarked; } public void postMark(){ this.postMarked = true; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started