Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java Create a program that draws a rectangle on a grid that starts at (0,0) and then moves around the screen based on inputs
In java
Create a program that draws a rectangle on a grid that starts at (0,0) and then moves around the screen based on inputs from the user. Create a Rect class in its own file: Rect.java) with the following properties: Instance Variables Methods 1. X 1. Constructor - pass w and h, sets width and height. 2. y 2. getX and getY returns x and y value respectively. 3. width 3. getWidth and getHeight returns the width and height. 4. height 4. translate - pass in dx and dy, then add to x and y. In a separate file (Main.java), create a Main class and a main method. Then create a 20x20 2D array of characters (the grid), then prompt the user to enter the width and height of the rectangle (1-5). Construct a Rect object using the width and height entered. Create the following methods: 1. displayGrid pass in the grid, then display the contents of the grid. 2. placeRect pass in the grid and the rectangle. Go to the location in the grid at the rectangle's x and y location, then, using '*'s, fill in the grid using the rectangle's width and height to draw the rectangle on the grid. 3. resetGrid - pass in the 2D array, and fill the grid with 's. 4. menu - display the menu below, prompt the user for their input and return it. Reset the grid, place the rectangle on it, display the grid, and then display the menu. Allow the user to choose which direction to move the rectangle. Do not allow the user to move any part of the rectangle outside of the bounds of the grid. If an edge of the rectangle reaches a wall, then it should not be able to move any farther in that direction. Repeat until the user decides to quit the program. You can use the CheckInput class functions to make sure that all user inputs are valid and within the bounds of the input. Make sure you're using the Rect class that you created for all rectangles constructed in your program (not the Rectangle class in java.awt). Document all methods using Javadocs style comments. Example Output: Enter rectangle width (1-5)? W Invalid input. Enter rectangle width (1-5)? 3 Enter rectangle height (1-5): 2 Create a program that draws a rectangle on a grid that starts at (0,0) and then moves around the screen based on inputs from the user. Create a Rect class in its own file: Rect.java) with the following properties: Instance Variables Methods 1. X 1. Constructor - pass w and h, sets width and height. 2. y 2. getX and getY returns x and y value respectively. 3. width 3. getWidth and getHeight returns the width and height. 4. height 4. translate - pass in dx and dy, then add to x and y. In a separate file (Main.java), create a Main class and a main method. Then create a 20x20 2D array of characters (the grid), then prompt the user to enter the width and height of the rectangle (1-5). Construct a Rect object using the width and height entered. Create the following methods: 1. displayGrid pass in the grid, then display the contents of the grid. 2. placeRect pass in the grid and the rectangle. Go to the location in the grid at the rectangle's x and y location, then, using '*'s, fill in the grid using the rectangle's width and height to draw the rectangle on the grid. 3. resetGrid - pass in the 2D array, and fill the grid with 's. 4. menu - display the menu below, prompt the user for their input and return it. Reset the grid, place the rectangle on it, display the grid, and then display the menu. Allow the user to choose which direction to move the rectangle. Do not allow the user to move any part of the rectangle outside of the bounds of the grid. If an edge of the rectangle reaches a wall, then it should not be able to move any farther in that direction. Repeat until the user decides to quit the program. You can use the CheckInput class functions to make sure that all user inputs are valid and within the bounds of the input. Make sure you're using the Rect class that you created for all rectangles constructed in your program (not the Rectangle class in java.awt). Document all methods using Javadocs style comments. Example Output: Enter rectangle width (1-5)? W Invalid input. Enter rectangle width (1-5)? 3 Enter rectangle height (1-5): 2Step 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