Code:
import java.io.*;
public class Messages
{
public static void main (String[] args)
{
BufferedReader reader = new BufferedReader (new InputStreamReader (System.in));
System.out.println("Enter recipient's name:");
String recipient = reader.readLine();
System.out.println("Enter sender's name:");
String sender = reader.readLine();
//Names message1 = new Greeting(recipient, sender); ?
//System.out.println(message1.printmsg());
}
}
interface Names
{
final String recipient; //
final String sender; //
void printmsg();
}
abstract class MessageTypes implements Names
{
String recipient;
String sender;
protected abstract void printmsg();
}
class Greeting extends MessageTypes
{
Greeting (String r, String s)
{
recipient = r;
sender = s;
}
public void printmsg()
{
System.out.println("Hello " + recipient + ", says " + sender);
}
}
I will output to the screen using an array of objects once my instructor tells us all the classes required. This is only an exercise, but it will be built off of next week.
I was told that we should be able to input into the program, and the only way I could think of doing that would be to put those inputs into the interface.