Question

In: Computer Science

Program: Drawing a half arrow This program outputs a downwards facing arrow composed of a rectangle...

Program: Drawing a half arrow

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
}

Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:

Enter arrow base height:
5
Enter arrow base width:
2
Enter arrow head width:
4

**
**
**
**
**
****
***
**
*

Solutions

Expert Solution

If you have any doubts, please give me comment...

import java.util.Scanner;

public class DrawHalfArrow {

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        int arrowBaseHeight, arrowBaseWidth, arrowHeadWidth;

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

        arrowBaseHeight = scnr.nextInt();

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

        arrowBaseWidth = scnr.nextInt();

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

        arrowHeadWidth = scnr.nextInt();

        while (arrowHeadWidth <= arrowBaseWidth) {

            // Prompt user for a valid arrow head value

            System.out.print("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 = arrowHeadWidth; i > 0; i--) {

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

                System.out.print("*");

            }

            System.out.println();

        }

    }

}


Related Solutions

4.24 LAB*: Program: Drawing a half arrow This program outputs a downwards facing arrow composed of...
4.24 LAB*: Program: Drawing a half arrow 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...
Rectangle Information. This program displays information about a rectangle drawn by the user. Input: Two mouse...
Rectangle Information. This program displays information about a rectangle drawn by the user. Input: Two mouse clicks for the opposite comers of a rectangle. Output: Draw the rectangle. Print the perimeter and area of the rectangle. Formulas: area = (length)(width) perimeter = 2(length + width)
Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
17.18 LAB 8A: Input and formatted output: Left-facing arrow You will be working on generating a...
17.18 LAB 8A: Input and formatted output: Left-facing arrow You will be working on generating a formatted output using characters such as *, #, -, +. You need to prompt the user for a character for the arrowhead, and a character for the arrow body, and then print a left-facing arrow. Your prompts should be exactly "Enter a character for the arrowhead:" and "Enter a character for the arrow body:", as shown below. Ex: If the user inputs a *...
PYTHON Program Problem Statement: Write a Python program that processes information related to a rectangle and...
PYTHON Program Problem Statement: Write a Python program that processes information related to a rectangle and prints/displays the computed values. The program will behave as in the following example. Note that in the two lines, Enter length and Enter width, the program does not display 10.0 or 8.0. They are values typed in by the user and read in by the program. The first two lines are text displayed by the program informing the user what the program does. This...
Trace through the program and what the outputs will be. If there is an error explain...
Trace through the program and what the outputs will be. If there is an error explain what must be fixed and continue to trace through. #include <iostream> using namespace std; void beans(int y, int& n, int size); void spam(int& n, int& y); int main(){ int m = 7; int n = 4; cout<<"m is "<<m<<" n is "<<n<<endl; beans(n, m, 3); cout<<"m is "<<m<<" n is "<<n<<endl; spam(m, n); cout<<"m is "<<m<<" n is "<<n<<endl; beans(m, 2, n); cout<<"m is...
a program that takes an integer and outputs the resulting factorial number.
assembly x86 language program a program that takes an integer and outputs the resulting factorial number. 
This is a straightforward program that will "draw" a rectangle using any character selected by the...
This is a straightforward program that will "draw" a rectangle using any character selected by the user. The user will also provide the width and height of the final rectangle. Use a nested for loop structure to create the output. Input: This program will draw a rectangle using your character of choice. Enter any character: [user types: *] Enter the width of your rectangle: [user types: 20] Enter the height of your rectangle: [user types: 5] Output: ******************** ******************** ********************...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
Create a program to input the length and width of a rectangle and calculate and print...
Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT