Assume the existence of a Window class with the following methods : – widen – accepts no arguments;

Assume  the existence of a Window class  with the following methods : – widen – accepts no arguments;

LANGUAGE: Java

CHALLENGE:

Assume the existence of a Window class with the following methods : – widen – accepts no arguments; doubles the width of the window – setHeight – accepts an integer argument corresponding to the new height of the Window – getWidth and getHeight – accept no arguments , return the width and height of the window respectively.

There is also a subclass, TitledWindow whose constructor accepts a width and height (bot integers ), and a title (a string ) — in that order. TitledWindow also has a method, setText that accepts a string , allowing the title of the window to be changed.

Declare a variable , tWindow, of type TitledWindow variable , and initialize it to a window with a width of 50 and a height of 75, and a title of “Rectangular Window”.

Double the width of the window, using widen, set the height of the window so that it is the same as the width, and set the title to the new value “Square Window”.

SOLUTION:

TitledWindow tWindow = new TitledWindow(50, 75, "Rectangular Window");
tWindow.widen();
tWindow.setHeight(tWindow.getWidth());
tWindow.setText("Square Window");

Add comment