Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description Modify the provided Java program Project3_DrawShapes.java (an application) by using user- defined methods. The provided program is a completed Java application, which ask

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Problem Description Modify the provided Java program Project3_DrawShapes.java (an application) by using user- defined methods. The provided program is a completed Java application, which ask user to decide what shape to draw, the size of the shape, and using what character to draw. Run the program to see how it works. The provided program already includes 3 private user-defined methods: private static void drawSquare(int size, char ch) private static void drawRectangle(int[] size, char ch) private static void drawTriangle(int size, charch) and the method calls for these three methods are also provided in "Draw the chosen shape" section in main method. What you should do with this program is to create 3 public user-defined methods: 1. makeChoice() //to decide what shape to draw 2. requestShapeInfo() //to request the information for the shape to draw 3. drawShapes() //to draw the chosen shape Note: They should all be static since they are called by a static method and have different parameter(s) and return value use the corresponding method calls to replace the statements in main method run the code after you have got the bug-free program o the new program should run in the same way as the old one change Li Ma in the head section on the top to your name change the file name and the class name to include your name Problem-solving Tips 1. Instead of having all statements in main method, using the sub-modules (user-defined methods) will make the main frame very clear (details have been hidden) 2. Watch out the variables a. You need to decide which value to pass into the callee from the caller and which value to pass out to the caller from the callee i. Use the method argument(s) to pass the value(s) into the callee ii. Use the method return value to pass a single value out to the caller iii. Use the array argument to pass multiple values out to the caller b. Declare the needed variables in your methods 3. The isosceles triangles should look like this (assume the shape size is 5 and the shape character is T): TTT TTTTT 4. If you have any questions as you proceed, ask your lab instructor for help. Submission Copy the content in the output window after you successfully run your program and paste it to a plain text file from and save it as Project3_DrawShapes_Your Name.txt into the same folder as your program for this project. Submit both the completed Java program (Project3_DrawShapes_Your Name.java) and the output file Project3 DrawShapes_Your Name.txt to Blackboard via the link Project3 in Assignments section on the course page. Project3_Drawshapes application Use user-defined methods to draw different shapes Program should end upon user's command Created by Li Ma, 2/25/2020 import java.util.Scanner; public class Project3_Drawshapes public static void main(String[] args) //declare needed variables int choice; int[] shapesire - new int [2] char shapeChar: //display message for the program System.out.println(" This program should draw the user-chosen shape"); System.out.println("User should also decide the shape site and the character to drawn ) * Decide what shape to draw Scanner Input - new Scanner(System.in); doc //display the menu for operations System.out.println() System.out.println(" 1. square"); System.out.println("\t 2. rectangle"); System.out.println("\t 3. isosceles triangle System.out.println(); "); request the shape choice System.out.print("Please tell me what shape to draw choice - input.nextInt() ) while(choice3) Request the information for the shape to draw //request the size of the shape if (choices.2) (l/for rectangle System.out.print("Please tell me the height of the rectangle to de shapesizeol - inout.nextInt : %20filename J O URSE Sponse-content-disposition=inline 1(choice ) (H or rectangle System.out.print("Please tell me the height of the rectangle to draw "); shapesizeo) - input.nextInt(); System.out.print("Please tell the length of the rectangle to draw") shapesire[1] = Input.nextInt() %3 else for square or triangle System.out.print("Please tell me the height of the shape to draw:"); shapesire[o] - Input.nextInt(); shapesire 1) shapesize request the character of the shape System.out.printlease tell the character to draw the shapes shapechar - Input.next().charAt(0); * Draw the chosen shape switch(choice) case 1: draquare (shapesire), shapechar); break; case 2: dradectangle(shapesize, shapechar); case 3: dr a ngle(shapesire break; , shapeCha) System.out.println(" ) Hend switch(choice) There must be something wrong!") Hendan method DO NOT RE C UE TO THE FOLLOWING CODE method definition for drouare private static void quare(int sine, charch) System.out.println() forint site fort - size System.out.println(); System.out.println(); /*** DO NOT MAKE ANY CHANGE TO THE FOLLOWING CODE ***/ 388888888888888888888888888 //method definition for drawSquare private static void drawSquare(int size, char ch) { System.out.println(); for(int i ; i3); * Request the information for the shape to draw //request the size of the shape if (choice-2) for rectangle System.out.print("Please tell me the height of the rectangle to draw:"); shapesizeol - Inout.nextInt() CS140 Homewor.docx O * Request the information for the shape to draw //request the size of the shape if (choice2) { //for rectangle System.out.print("Please tell me the height of the rectangle to draw:"); shapeSize[@] - input.nextInt(); System.out.print("Please tell me the length of the rectangle to draw:"); shapesize[1] = input.nextInt(); else { //for square or triangle System.out.print("Please tell me the height of the shape to draw:"); shapesize[@] = input.nextInt(); shapeSize[1] - shapeSize[@]; //request the character of the shape System.out.print("Please tell me the character to draw the shape: "); shapeChar - input.next().charAt(0); * Draw the chosen shape switch(choice) { case 1: drawSquare(shapeSize[], shapeChar); break; case 2: drawRectangle(shapeSize, shapeChar); break; case 3: drawTriangle(shapeSize[@], shapeChar); break; default: System.out.println(" There must be something wrong!"); } //end switch(choice) } //end main method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions