Question 5 [15] Consider the following classes, illustrating the Strategy design pattern: import java.awt.*; abstract class Text { protected TextApplet tA; protected Text(TextApplet tApplet) { tA = tApplet; } abstract public void draw(Graphics g); } class PlainText extends Text { protected PlainText(TextApplet tApplet) { super(tApplet); } public void draw(Graphics g) { g.setColor(tA.getColor()); g.setFont(new Font("Sans-serif", Font.PLAIN, 12)); g.drawString(tA.getText(), 20, 20); } } class CodeText extends Text { protected CodeText(TextApplet tApplet) { super(tApplet); } public void draw(Graphics g) { g.setColor(tA.getColor()); g.setFont(new Font("Monospaced", Font.PLAIN, 12)); g.drawString(tA.getText(), 20, 20); } } public class TextApplet extends java.applet.Applet { protected Text text; protected String textVal; protected Color color; public String getText() { return textVal; } public Color getColor() { return color; } public void init() { textVal = getParameter("text"); String textStyle = getParameter("style"); String textColor = getParameter("color"); if (textStyle == "code") text = new CodeText(this); else text = new PlainText(this); if (textColor == "red") color = Color.RED; else if (textColor == "blue") color = Color.BLUE; else color = Color.BLACK; } public void paint(Graphics g) { text.draw(g); 10 } } The Text class is more complicated than it should be (there is too much coupling between the Text and TextApplet classes). By getting rid of the reference to a TextApplet object in the Text class and setting the colour in the paint() method, one could turn the Text class into an interface and simplify the strategy classes considerably. 5.1 Rewrite the Text and PlainText classes to do what is described above. (6) 5.2 Explain the consequent changes that are necessary to the TextApplet class. (4) 5.3 Write an additional strategy class called FancyText (to go with your simplified strategy classes) to allow fancy text to be displayed for the value "fancy" provided for the style parameter. It should use the font Font ("Serif", Font.ITALIC, 12). (3) 5.4 Explain what changes are necessary to the TextApplet class for this. (2)
2280to write a number in words eg. FIVE requires 10 straight lines. what is the number which requires the same number of lines as that of the number itself
13 21016WHAT IS THE SIGNIFICANCE OF VECTOR GROUPS IN TRANSFORMER? WHAT WILL BE EFFECT WHEN PHASE DISPLACEMENT CHANGES IN TRANSFORMER?WHAT IS THE NEED TO BE PHASE SHIFT CHANGE BETWEEN THE PRIMARY AND SECONDARY WINDING
1789Common UI for Multiple web applications. Suppose there are 35 websites using same third party controls.These 3rd party controls are made together that all 35 websites can use these controls.If we put all 3rd party controls and use its dll in 35 websites,only class files will be accessable. But I want to use CSS,images also in all 35 websites. how I can design the N-tier solution for this project.
2704Can anyone explain me the operating principle of the megger tester?( I just know that its diflection relates with the ratio of currents of control & diflecting coil. I need more information as breif as possible)
1 4408what will come in place of the question mark(?)in the following alphabet series? AC DC EF IG? 1)MI 2)IL 3) IM 4)LI 5)None of These plz ans hurry and with detail
4 15239How to validate the entry in Screen & dialog proframming?? Is there any way to send the error??
2 6949Post New TCS Interview Questions
Does Pig give any warning when there is a type mismatch or missing field?
Who were james watson, francis crik and maurice wilkins?
Why asset classes are important in sap?
How do you do backup and recovery in teradata?
Which database does facebook use?
What are the types of important programs that are used in the cics?
Do you prefer COD or online payment?
What are all the various Estimation Techniques available ?
How is it possible in java programming for two string objects with identical values not to be equal under the == operator?
Explain the difference between jsp and servlet?
I got an offer from TCS as a software engineer, But it says I will work for TCS BPO, Is there any difference in policies of TCS BPO and TCS-IT Services.How is the Working enviornment and appriasal procedure
How to conduct solubility study of highly degrading product in aqueous medias (pH 1 to 6.8)
hi, could u tell me how to sell a pen in hindi
Can a Search can be done on a table with or without Index?
How data flows from pp into fi & copa? : co-pa