Answer to Question #197641 in Java | JSP | JSF for Muqeet Waraich

Question #197641

Suppose you are employed by a advertisement agency to design a system to send advertisements in different languages and to different modes such as sms, email, in-mail, cable-tv, etc. (more can be added later or).

The process of sending an advertisement is always the same irrespective of the language or the mode of the advertisement. The process is as follows:

1. The text of the advertisement is received as text

2. The text is then translated into a desired language.

3. The translation depends upon the mode of advertisement

4. The translated text is then proof-read for consistency

5. And then the text is advertised on the required mode

Your task is the following:

• Identify the design pattern that can be used over here

• Justify your choice

• Make a class diagram (using UML Notation)

• Implement the classes in JAVA

• Test your implementation



1
Expert's answer
2021-05-24T04:11:10-0400

//Pattern Bridge is chosen because of the usage of the multiple variants of the same entity classificated by the different features at the same time.



import java.util.HashMap;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Advertisement {
	
boolean validate(String text) {
		boolean isValid = false;
		String reg1 = "[(A-Za-z)||(\\d)]+";
		String reg2 = "[\\S]+";
		Pattern p2 = Pattern.compile(reg2);
		Matcher matcher = p2.matcher(text);
		while (matcher.find()) {
			if (matcher.group().matches(reg1))
				isValid = true;
			else
				return false;
		}
		return isValid;
	}


	String translate(String text) {
		return text;


	};
	
	


interface Translator {
	String translate(String text);
}


interface Advertiser {


	String advertise(String text);
}


class SMS implements Advertiser {
	String destination;


	@Override
	public String advertise(String text) {
		return "Sending on the number " + destination + " the message : \n" + text;
	}
}


class Email implements Advertiser {
	String destination;


	@Override
	public String advertise(String text) {
		return "Sending to the " + destination + " email: \n" + text;
	}
}


class CableTV implements Advertiser {
	String destination;


	@Override
	public String advertise(String text) {
		return "This text will be shown on channel " + destination + " : \n" + text;
	}
}


class French implements Translator {
	private HashMap<String, String> french = new HashMap<>();


	@Override
	public String translate(String text) {
		String reg1 = "[A-Za-z]+";
		Pattern p2 = Pattern.compile(reg1);
		Matcher matcher = p2.matcher(text);
		while (matcher.find()) {
			if (matcher.group().matches(reg1)) {
				String group = matcher.group();
				if (french.containsKey(group))
					matcher.replaceAll(french.get(group));
			}
		}
		return text;
	}
}


class Italian implements Translator {
	private HashMap<String, String> italian = new HashMap<>();


	@Override
	public String translate(String text) {
		String reg1 = "[A-Za-z]+";
		Pattern p2 = Pattern.compile(reg1);
		Matcher matcher = p2.matcher(text);
		while (matcher.find()) {
			if (matcher.group().matches(reg1)) {
				String group = matcher.group();
				if (italian.containsKey(group))
					matcher.replaceAll(italian.get(group));
			}
		}
		return text;
	}
}


class German implements Translator {
	private HashMap<String, String> german = new HashMap<>();


	@Override
	public String translate(String text) {
		String reg1 = "[A-Za-z]+";
		Pattern p2 = Pattern.compile(reg1);
		Matcher matcher = p2.matcher(text);
		while (matcher.find()) {
			if (matcher.group().matches(reg1)) {
				String group = matcher.group();
				if (german.containsKey(group))
					matcher.replaceAll(german.get(group));
			}
		}
		return text;
	}
}}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS