Steve E.

asked • 02/24/19

Drawing a half arrow (Java)

Is anyone able and willing to help me? Here is the task:

This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width.

(1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt)


(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base. (1 pt)


(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow head. (2 pts)


(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt)

while (arrowHeadWidth <= arrowBaseWidth) {
// Prompt user for a valid arrow head value
}



I need help figuring out how to make this half arrow work with inputs of: arrow base height: 5, arrow base width: 2, and arrow head width:4

I am close, but it one row to tall, to start with, and I'm not sure what else is wrong.

Someone please help.



public class DrawHalfArrow {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int arrowBaseHeight = 0;

int arrowBaseWidth = 0;

int arrowHeadWidth = 0;

System.out.println("Enter arrow base height:");

arrowBaseHeight = scnr.nextInt();


System.out.println("Enter arrow base width:");

arrowBaseWidth = scnr.nextInt();


System.out.println("Enter arrow head width:");

arrowHeadWidth = scnr.nextInt();


for (int i = 0; i <= arrowBaseHeight; i++) {

for (int j = 0; j < arrowBaseWidth; j++) {

System.out.print("*");

}

System.out.println();

}



for (int i = 0; i < arrowHeadWidth; i++) {

for (int j = arrowHeadWidth; j>i; j--) {

System.out.print("*");

}

System.out.println();

}

}

}

1 Expert Answer

By:

Patrick B. answered • 02/24/19

Tutor
4.7 (31)

Math and computer tutor/teacher

Steve E.

Thank you for responding. The code I have is mostly working, with a couple changes to the code I posted here. But I still am having problems with the end of the problem. Apparently, need to do something with this step: (4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt) And maybe use this "while" statement? while (arrowHeadWidth <= arrowBaseWidth) { // Prompt user for a valid arrow head value } I've been playing with it, but no luck yet. I hope your still available for help. Thanks again. My revised code follows. System.out.println("Enter arrow base height:"); arrowBaseHeight = scnr.nextInt(); System.out.println("Enter arrow base width:"); arrowBaseWidth = scnr.nextInt(); System.out.println("Enter arrow head width:"); arrowHeadWidth = scnr.nextInt(); System.out.println(); // I added this for spacing for (int i = 0; i < arrowBaseHeight; i++) { // I remove the = after the < for (int j = 0; j < arrowBaseWidth; j++) { System.out.print("*"); } System.out.println(); } for (int i = 0; i < arrowHeadWidth; i++) { for (int j = arrowHeadWidth; j>i; j--) { System.out.print("*"); } System.out.println();
Report

02/25/19

Patrick B.

It's there. In the method INPUT you will see the prompt for the arrow head width continues until a value LARGER than the arrow base width is input
Report

02/26/19

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.