Question
Playing Polymorphically with Windows (WindowApp) Using the classes you've developed in Labs 5.1-4, write an app that loads window data from a file, creates the
Playing Polymorphically with Windows (WindowApp)
Using the classes you've developed in Labs 5.1-4, write an app that loads window data from a file, creates the proper window object, loading them up into an array of type Window, and then traversing the array performing Window-level actions (displaying, settingvisibility, resizing).
The Details
The window.data file contains window data for the various (concrete) Window subclasses (ColoredWindow and BorderedWindow). THe problem is detecting what kind of window data is coming up next the read method of ColoredWindowtakes a width, height, and background color character, while the read method of BorderedWindow takes only a width and height. There are several ways of resolving this; hat we will do is prefix the data for a window with an indicator (or sentinel) that indicates the type of window whose data follows a C for ColoredWindow, and a B for BorderedWindow.i You can seen a example of this in the sample run below. When your application reads in the objects from the file, it (the application) reads in the indicator, and then based on its value (C or B) calls the proper read method and loads the returned (Window) object into the array. Your application should:
declare and create an array of element type Window (create the array with 25 elements)
open the file window.data
Using the technique described above, call the appropriate (static) read method of one of the Window subclasses to read in and return a newly created object of the proper type, and displaying it
Iterate through the array, turning on visibility, and displaying each window
Iterate through the array resizing (flip the width and height), and displaying each window
Iterate through the array minimizing, and displaying each window
You are not getting any code from me in this exercise; the interface and classes are those from 5.1-4.
Sample Test Run
For example if the file window.data contains:
C 4 9 O C 3 4 ; B 4 6 C 2 3 + B 5 7
your application should produce:
Creating window data from file data, loading it into an array, and displaying --- Window 0: a 4x9 window with background color 'O' (Nothing to see here) --- Window 1: a 3x4 window with background color ';' (Nothing to see here) --- Window 2: a 4x6 window with a border (Nothing to see here) --- Window 3: a 2x3 window with background color '+' (Nothing to see here) --- Window 4: a 5x7 window with a border (Nothing to see here) Turning on visibility --- Window 0: a 4x9 window with background color 'O' OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO --- Window 1: a 3x4 window with background color ';' ;;; ;;; ;;; ;;; --- Window 2: a 4x6 window with a border +----+ | | | | | | | | | | | | +----+ --- Window 3: a 2x3 window with background color '+' ++ ++ ++ --- Window 4: a 5x7 window with a border +-----+ | | | | | | | | | | | | | | +-----+ Resizing (flipping width and height) and displaying --- Window 0: a 9x4 window with background color 'O' OOOOOOOOO OOOOOOOOO OOOOOOOOO OOOOOOOOO --- Window 1: a 4x3 window with background color ';' ;;;; ;;;; ;;;; --- Window 2: a 6x4 window with a border +------+ | | | | | | | | +------+ --- Window 3: a 3x2 window with background color '+' +++ +++ --- Window 4: a 7x5 window with a border +-------+ | | | | | | | | | | +-------+ Minimizing and Displaying --- Window 0: a 9x4 window with background color 'O' [a 9x4 window with background color 'O' (minimized)] --- Window 1: a 4x3 window with background color ';' [a 4x3 window with background color ';' (minimized)] --- Window 2: a 6x4 window with a border [a 6x4 window with a border (minimized)] --- Window 3: a 3x2 window with background color '+' [a 3x2 window with background color '+' (minimized)] --- Window 4: a 7x5 window with a border [a 7x5 window with a border (minimized)]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started