Question: Please finish this by using java Create an interface called Message. It should have a constant string called defaultMessage whose value is Some people are

Please finish this by using java

Create an interface called Message. It should have a constant string called "defaultMessage" whose value is "Some people are nice". It should have two methods - positiveMessage and negativeMessage, both of which return nothing and accept no parameters

Create a class called MyMessage that implements Message. It should have 3 instance data, a number and two strings. The strings contain the positive and negative messages. The number is used to count how many message each instance of MyMessage has output. Your constructor should set the two instance data messages and initialize the number to 0. In addition to the instance data, MyMessage should have a static variable called allNumber which counts the number of messages output by all MyMessage objects.

MyMessage should have a method called variableMessage that outputs the positiveMessage when passed a 1, the negativeMessage when passed a 2, and the defaultMessage (from the Message interface - do not recreate it) when any other number is passed. MyMessage should also have a method called getNumber to return the number of messages output by that MyMessage object, as well as a getAllNumber method that returns the number of messages output by all MyMessage objects (the sum of them).

public class MessageTester { public static void main(String args[]) { MyMessage m1 = new MyMessage("Dr. Lee is nice","Dr. Lee is not nice"); MyMessage m2 = new MyMessage("Dr. Benoit is nice", "Dr. Benoit is not nice"); m1.variableMessage(1); m2.variableMessage(2); m1.variableMessage(222); System.out.println("M1 has put out " + m1.getNumber() + " messages"); System.out.println("M2 has put out " + m2.getNumber() + " messages"); System.out.println("There have been " + m1.getAllNumber() + " total messages"); } }

Please finish this by using java Create an interface called Message. It

> run MessageTester Dr. Lee is nice Dr. Benoit is not nice Some people are nice M1 has put out 2 messages M2 has put out 1 messages There have been 3 total messages

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!