Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Voice.Java package code; public interface Voice { public String subject(); public String verb(); public String object(); } /* * Study the class Active, which implements

Voice.Java

package code;

public interface Voice {

public String subject();

public String verb();

public String object();

}

/*

* Study the class Active, which implements Voice.

* Define a similar class named Passive which creates a PASSIVE VOICE sentence:

* maps agent and patient to object and subject roles respective in the sentence, and inserts "was" and "by" correctly:

*

* In the following active sentence Mary is the agent and appears as the subject, while John is the patient and appears as the object:

*

* Mary taught John.

*

* In the following passive sentence Mary is the agent and appears as the object, while John is the patient and appears as the subject:

*

* John was taught by Mary.

*

*/

Sentence.java

package code;

public interface Sentence {

public void setVoice(Voice v);

public String agent();

public String verb();

public String patient();

}

/*

* Study the class English, which implements Sentence.

*

* Define a similar class named Yoda which creates sentences like Yoda (http://www.imdb.com/character/ch0000015) might speak.

*

*

* In the following English sentence Mary is the agent and appears as the subject, while John is the patient and appears as the object.

* The basic word order is subject-verb-object.

*

* Mary taught John.

*

* In the following Yoda sentence Mary is the agent and appears as the subject, while John is the patient and appears as the object.

* The basic word order is object-subject-verb.

*

* John Mary taught.

*

*/

Tester.java

package code;

public class Tester {

public static void main(String[] args) {

Sentence s1 = new English("Mary","taught","John");

s1.setVoice(new Active(s1));

System.out.println(s1);

}

}

NullVoice.java

package code;

public class NullVoice implements Voice {

@Override

public String subject() {

return "";

}

@Override

public String verb() {

return "";

}

@Override

public String object() {

return "";

}

@Override public String toString() { return "(null)"; }

}

Active.java

package code;

/*

* Creates an ACTIVE VOICE sentence:

* maps agent and patient to subject and object roles respective in the sentence.

*/

public class Active implements Voice {

private Sentence sentence;

public Active(Sentence s) {

sentence = s;

}

public String subject() {

return sentence.agent();

}

public String verb() {

return sentence.verb();

}

public String object() {

return sentence.patient();

}

@Override public String toString() { return "ACTIVE"; }

}

English.java

package code;

/*

* Creates an English sentence with subject-verb-object word order.

*

*/

public class English implements Sentence {

private String agent;

private String verb;

private String patient;

private Voice voice;

public English(String s, String v, String o) {

agent = s;

verb = v;

patient = o;

voice = new NullVoice();

}

public void setVoice(Voice v) {

voice = v;

}

public String agent() { return agent; }

public String verb() { return verb; }

public String patient() { return patient; }

@Override public String toString() {

return voice.subject() + " " + voice.verb() + " " + voice.object();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions