Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a JES function that allows the user to add an arbitrary number of rectangles on to an empty picture object, using the built-in JES
Write a JES function that allows the user to add an arbitrary number of rectangles on to an empty picture object, using the built-in JES function addRect(picture,x1,y1, width,height). When adding the first rectangle, the user inputs must be validated to ensure that it falls within the bounds of the picture. For subsequent rectangles, you must ensure that they fall within the bounds of the previously entered rectangle. After each rectangle is added and displayed, the user must be asked if they wish to add another rectangle. You must repeat this process until the user decides to stop. Finally, the number of rectangles added must be displayed. More specifically: 1. Allow the user to create an empty picture object based on a width and a height as entered via the keyboard These inputs must be validated (see point #5 below). 2. If the rectangle being added is the first one, ask the user to enter its x1, yl, width and height values and ensure that the rectangle will fall within bounds of the picture. Otherwise, the rectangle must fall within the bounds of the previously rectangle added. (The new rectangle can completely overlap the previous one and it can be the same size). i.e. all of these inputs must be validated (see point #5 below). 3. Ask the user if they wish to add another rectangle onto the picture and repeat from step 2, as necessary. Only 'while' loops should be used, if necessary. The break or return statement must not be used to stop the loop. 4. Finally, print the total number of rectangles added 5. Restrictions on input validation: Use only requestinteger for number inputs. If a user input is invalid, they must be asked to re-enter that value until they enter a correct value (error messages must be shown as appropriate). If an input is invalid, you must ensure that correct input is taken before taking different inputs. You must not use break and/or return statements. Any upper and/or lower limits should be based on what is code-wise valid i.e. they must not based on arbitrary values chosen by the programmer). E.g. In the shown example, the picture is a square picture and 3 rectangles have been added by the user. The largest was the first rectangle added the user. The second largest was the second one added and the smallest was the last rectangle added. i.e. The program has ensured that every rectan s within the previous container. Write a JES function that allows the user to add an arbitrary number of rectangles on to an empty picture object, using the built-in JES function addRect(picture,x1,y1, width,height). When adding the first rectangle, the user inputs must be validated to ensure that it falls within the bounds of the picture. For subsequent rectangles, you must ensure that they fall within the bounds of the previously entered rectangle. After each rectangle is added and displayed, the user must be asked if they wish to add another rectangle. You must repeat this process until the user decides to stop. Finally, the number of rectangles added must be displayed. More specifically: 1. Allow the user to create an empty picture object based on a width and a height as entered via the keyboard These inputs must be validated (see point #5 below). 2. If the rectangle being added is the first one, ask the user to enter its x1, yl, width and height values and ensure that the rectangle will fall within bounds of the picture. Otherwise, the rectangle must fall within the bounds of the previously rectangle added. (The new rectangle can completely overlap the previous one and it can be the same size). i.e. all of these inputs must be validated (see point #5 below). 3. Ask the user if they wish to add another rectangle onto the picture and repeat from step 2, as necessary. Only 'while' loops should be used, if necessary. The break or return statement must not be used to stop the loop. 4. Finally, print the total number of rectangles added 5. Restrictions on input validation: Use only requestinteger for number inputs. If a user input is invalid, they must be asked to re-enter that value until they enter a correct value (error messages must be shown as appropriate). If an input is invalid, you must ensure that correct input is taken before taking different inputs. You must not use break and/or return statements. Any upper and/or lower limits should be based on what is code-wise valid i.e. they must not based on arbitrary values chosen by the programmer). E.g. In the shown example, the picture is a square picture and 3 rectangles have been added by the user. The largest was the first rectangle added the user. The second largest was the second one added and the smallest was the last rectangle added. i.e. The program has ensured that every rectan s within the previous container
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