Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the class provided below, identify which elements are part of the class\'s b

ID: 3690265 • Letter: F

Question

For the class provided below, identify which elements are part of the class's behavior and which are part of the class's state.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

public class Message {

    private String msg;

    private String to;

    private String from;

    /**

     * Constructs a new Message object from a source to

     * a destination.

     * @param source the "From" source of the message

     * @param dest the "To" destination of the message

     */

    public Message(String source, String dest) {

        this.from = source;

        this.to = dest;

        this.msg = "";

    }

    /**

     * Returns the source of the message

     * @return the message source

     */

    public String getFrom() {

        return this.from;

    }

    /**

     * Returns the destination of the message

     * @return the message destination

     */

    public String getTo() {

        return this.to;

    }

    /**

     * Adds a line to the end of the message

     * @param the line to add

     */

    public void append(String msg) {

        this.msg = this.msg + msg;

    }

    /**

     * Returns the current text of the message

     * @return the current text

     */

    public String getMessage() {

        return this.msg;

    }

    /**

     * Displays the current message to standard output

     */

    public void displayMessage() {

        System.out.println("To: " + this.to);

        System.out.println("From: " + this.from);

        System.out.println("--------------------------------");

        System.out.println(this.msg);

    }

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

public class Message {

    private String msg;

    private String to;

    private String from;

    /**

     * Constructs a new Message object from a source to

     * a destination.

     * @param source the "From" source of the message

     * @param dest the "To" destination of the message

     */

    public Message(String source, String dest) {

        this.from = source;

        this.to = dest;

        this.msg = "";

    }

    /**

     * Returns the source of the message

     * @return the message source

     */

    public String getFrom() {

        return this.from;

    }

    /**

     * Returns the destination of the message

     * @return the message destination

     */

    public String getTo() {

        return this.to;

    }

    /**

     * Adds a line to the end of the message

     * @param the line to add

     */

    public void append(String msg) {

        this.msg = this.msg + msg;

    }

    /**

     * Returns the current text of the message

     * @return the current text

     */

    public String getMessage() {

        return this.msg;

    }

    /**

     * Displays the current message to standard output

     */

    public void displayMessage() {

        System.out.println("To: " + this.to);

        System.out.println("From: " + this.from);

        System.out.println("--------------------------------");

        System.out.println(this.msg);

    }

}

1 public class Message f private String msg; private String to; private String from; * Constructs a new Message object from a source to *a destination * param source the "From" source of the message * param dest the "To" destination of the message 18 12 13 14 15 16 17 18 19 28 21 public Message(String source, String dest) f this.from = source; this.to = dest; this.msg = ... ; * Returns the source of the message * return the message source public String getFrom() 23 24 25 26 27 return this.from; * Returns the destination of the message * return the message destination 29 39 31 32 public String getTo) f return this.to; 35 * Adds a line to the end of the message * @param the line to add 37 38 39 48 public void append (String msg) this.msg this.msg + msg; 42 43 * Returns the current text of the message * return the current text 45 47 public String getMessage() 1 return this.msg.; 49 50 51 52 53 * Displays the current message to standard output public void displayMessage) 56 57 58 59 60 61 System.out.println("To: " + this.to); System.out.println("From: " + this.from); System.out.println("-- System.out.println(this.msg);

Explanation / Answer

State of the class:

State means what are the objects the class have.

The state of the object is simply a value or a data.

Here, the class Message have the following states;

String msg

String to

String from

Behavior of the class:

Behavior of the class mean it changes the state of the object.

Here, the method aapend() changes the state of the message.

The following are the behavior of the class Message:

/**
   * Constructs a new Message object from a source to a destination.
   *
   * @param source
   * the "From" source of the message
   * @param dest
   * the "To" destination of the message
   */
   public Message(String source, String dest) {
       this.from = source;
       this.to = dest;
       this.msg = "";
   }

   /**
   * Returns the source of the message
   *
   * @return the message source
   */
   public String getFrom() {
       return this.from;
   }

   /**
   * Returns the destination of the message
   *
   * @return the message destination
   */
   public String getTo() {
       return this.to;
   }

   /**
   * Adds a line to the end of the message
   *
   * @param the
   * line to add
   */
   public void append(String msg) {
       this.msg = this.msg + msg;
   }

   /**
   * Returns the current text of the message
   *
   * @return the current text
   */
   public String getMessage() {
       return this.msg;
   }

   /**
   * Displays the current message to standard output
   */
   public void displayMessage() {
       System.out.println("To: " + this.to);
       System.out.println("From: " + this.from);
       System.out.println("--------------------------------");
       System.out.println(this.msg);

}