Question
Problem 2: Multiple Shapes For this problem you will write a program that interacts with the user to have a Turtle draw multiple shapes at
Problem 2: Multiple Shapes
For this problem you will write a program that interacts with the user to have a Turtle draw multiple shapes at locations and with the size requested by the user. You may either use the drawShape method you wrote for PSA2, write a new drawShape, or use the tashasSquare or drawRectangle method from class.
Download the CreateMultipleShapes.java file and save it in your PSA4/bookClasses directory. This file has a lot of code filled in already with several comments labeled TODO to indicate what parts you should change.
Create a World of size 800x600 and put a single Turtle in it.
Ask the user how many times they want to draw the shape. Modify the code in the CreateMultipleShapes.java to add a loop that will iterate as many times as the user requested. You may use a for loop or a while loop, but a for loop is more natural to use in this situation, since it is counter-controlled repetition.
Each iteration of the loop should
o Print out the shape number (e.g. shape number 1, shape number 2, etc.)
o Ask the user for the starting (x, y) coordinates and the size of the shape
o Move the turtle to the requested location (hint: moveTo, after putting the penUp)
o Draw the shape with the requested size (hint: remember to put the penDown)
Also complete the missing lines that are needed to get the input from the user. You MUST use the Scanner class to do this. You will need to write an import statement (before the line that starts public class), create a Scanner object that can read from the keyboard (System.in) in the initializing variables section, and complete the three lines to actually get the user input (numberShapes = , xCoordinate = , yCoordinate = , size = ). If your drawShape method has more than one parameter (e.g. drawRectangle needs width and height), add more lines to get the user input.
We are Given this:::
/* Filename: CreateMultipleShapes.java * Created by: Partner Name 1 * Date: * * Description: This class is designed to... * */ // TODO: NEED TO FILL IN THE APPROPRIATE import STATEMENT HERE public class CreateMultipleShapes { public static void main(String[] args) { /* Creating a World with one Turtle in it and initializing variables. */ // TODO: FILL IN CODE TO CREATE A Scanner OBJECT CONNECTED TO System.in int xCoordinate, yCoordinate, size; // ask user for number of shapes to draw, and get response System.out.println("How many times do you want to draw the shape?"); int numberShapes = //TODO: NEED TO FILL IN CODE FOR READING THE NUMBER OF SHAPES VALUE HERE // TODO: NEED TO FILL IN THE FOR LOOP HERE { System.out.println("Shape number " + /*TODO: FILL IN THE SHAPE NUMBER HERE, DELETE THIS COMMENT*/); // get the x, y coordinates for where to draw the shape System.out.println("Enter the x-coordinate:"); xCoordinate = // TODO: NEED TO FILL IN CODE FOR READING THE X-COORDINATE VALUE HERE System.out.println("Enter the y-coordinate:"); yCoordinate = // TODO: NEED TO FILL IN CODE FOR READING THE Y-COORDINATE VALUE HERE // get the size to draw the shape System.out.println("Enter the size:"); size = //TODO: NEED TO FILL IN CODE FOR READING THE SIZE VALUE HERE //TODO: FILL IN CODE FOR READING ADDITIONAL SIZE VALUES HERE, IF YOUR DRAWSHAPE HAS MORE THAN ONE PARAMETER // move the turtle to the starting coordinates, without drawing a line // TODO: NEED TO FILL IN THE TURTLE MOVEMENT TO STARTING COORDINATES HERE // draw the shape // TODO: NEED TO MAKE A CALL TO DRAWSHAPE HERE } } }
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