answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
xz_007
29 days ago
12

3.24 Program: Drawing a half arrow (Java) This program outputs a downwards facing arrow composed of a rectangle and a right tria

ngle. 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)

Engineering
1 answer:
alex41 [274]29 days ago
3 0

Answer:

This is the JAVA code:

import java.util.Scanner; // to capture user input

public class DrawHalfArrow{ // class declaration

public static void main(String[] args) { // main function starts here

    Scanner scnr = new Scanner(System.in); //input reading

int arrowBaseHeight = 0; // variable for arrow base height

int arrowBaseWidth  = 0; // variable for arrow base width

int arrowHeadWidth = 0; // variable for arrow head width

// prompts user for height, base width, and head width

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

arrowBaseHeight = scnr.nextInt(); // reads integer input

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

arrowBaseWidth = scnr.nextInt();

/* loop for asking user for arrow head width until it exceeds base width */

while (arrowHeadWidth <= arrowBaseWidth) {

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

    arrowHeadWidth = scnr.nextInt(); }

//begin nested loop for base

//outer loop for outputting based on arrow base height

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

//inner loop produces the stars

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

          System.out.print("*");        } //prints stars

          System.out.println();          }

//used for the width of the arrowhead

int k = arrowHeadWidth;

//outer loop for the head height

for (int i = 1; i <= arrowHeadWidth; i++)

{     for(int j = k; j > 0; j--)     {//inner loop for stars

       System.out.print("*");    } //print stars

   k = k - 1;

   System.out.println(); } } } //marks end of asterisks for a new line

Explanation:

The code prompts for arrow dimensions, including height, base width, and head width. The program verifies that the head width must be larger than the base width through a condition. This loop instigates until the user provides a valid head width.

The loop manages the output of the arrow base corresponding to the specified height. Thus point (1) is fulfilled.

A nested loop is utilized to present an arrow base matching the defined width. The inner loop creates stars, establishing the width for the base, while the outer loop iterates according to the specified height. This satisfies point (2).

A temporary variable, k, saves the initial arrow head width for necessary adjustments.

The final nested loop outputs an arrow head corresponding to the specified width with stars. Therefore, point (3) is achieved.

The value of k decreases by 1 for each execution of the nested loop, ensuring each subsequent line contains fewer stars.

The output screenshot is attached.

You might be interested in
The 10-kg block slides down 2 m on the rough surface with kinetic friction coefficient μk = 0.2. What is the work done by the fr
iogann1982 [279]

Answer:

153.2 J

Explanation:

Let’s first identify our known variables:

mass (m) of the block = 10 kg

distance slid down (i.e., displacement) = 2 m

coefficient of kinetic friction (μk) = 0.2

In the following diagram, if we analyze the force component directed along the displacement, we find

F_x= Fcos 40°

F_x= 100 (cos 40°)

F_x= 76.60 N

The work done by the frictional force is then calculated as:

W = F_x × displacement

W = 76.60 × 2

W = 153.2 J

Therefore, the work done by the frictional force equals 153.2 J

7 0
25 days ago
PDAs with two stacks are strictly more powerful than PDAs with one stack. Prove that 2-stack PDAs are not a valid model for CFLs
iogann1982 [279]

Answer:

?pooooooooooooooooooooooop

Explanation:

?pooooooooooooooooooooooop

6 0
2 days ago
Write multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has
alex41 [274]

Answer:

The following includes the explanation, code, and resulting outputs.

C++ Code:

#include <iostream>

using namespace std;

int main()

{

int year;

cout<<"Enter the car model year."<<endl;

cin>>year;

if (year<=1969)

{

cout<<"Few safety features."<<endl;

}

else if (year>=1970 && year<1989)

{

cout<<"Probably has seat belts."<<endl;

}

else if (year>=1990 && year<1999)

{

cout<<"Probably has antilock brakes."<<endl;

}

else if (year>=2000)

{

cout<<"Probably has airbags."<<endl;

}

return 0;

}

Explanation:

The challenge involved displaying feature messages for a car based on its model year.

Logical conditions were integrated into the coding. The implementation has been verified with multiple inputs producing the expected results.

Output:

Enter the car model year.

1961

Few safety features.

Enter the car model year.

1975

Probably has seat belts.

Enter the car model year.

1994

Probably has antilock brakes.

Enter the car model year.

2005

Probably has airbags.

5 0
25 days ago
Given num_rows and num_cols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
Viktor [230]

Answer:

This is the solution code in Python:

  1. alphabets = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
  2. user_input = input("Enter number of rows and columns: ")
  3. myArr = user_input.split(" ")
  4. num_rows = int(myArr[0])
  5. num_cols = int(myArr[1])
  6. seats = []
  7. for i in range(num_rows):
  8. row = []
  9. for j in range(num_cols):
  10. row.append(alphabets[j])
  11. seats.append(row)
  12. output = ""
  13. for i in range(len(seats)):
  14. for j in range(len(seats[i])):
  15. output += str(i + 1) + seats[i][j] + " "
  16. print(output)

Explanation:

Initially, we create a small list of alphabets from A to J (Line 1).

We then request the user to enter the number of rows and columns (Line 3). Given that the input comes as a string (e.g., "2 3"), we utilize the split() method to separate the numbers into individual items in a list (Line 4). The first item (row number) is assigned to variable num_rows, while the second item (column number) goes to num_cols.

Subsequently, we construct the seats list with a nested for-loop (Lines 10-15). Once the seats list is formed, another nested for-loop generates the required output string as per the question (Lines 19-21).

Finally, the output is printed (Line 23). For example, an input of 2 3 results in the output:

1A 1B 1C 2A 2B 2C

8 0
1 month ago
6. You are evaluating flow through an airway. The current flow rate is 10 liters per minute with a fixed driving pressure (P1) o
iogann1982 [279]

Answer:

B) P1 would have to increase to sustain the flow rate (correct)

C) Resistance would rise (correct)

Explanation:

Flow rate is measured at 10 liters per minute

Driving pressure (P1) stands at 20 cm H2O

Fixed downstream pressure (P2) is 5 cm H2O

The accurate statements when the lumen is pinched in the center of the tube are: P1 will increase to maintain the flow rate, and resistance will rise. This occurs because pinching the lumen decreases its diameter, leading to higher resistance, which is linearly related to pressure, thus P1 will also increase.

The incorrect statement is: the flow would decrease.

6 0
16 days ago
Other questions:
  • Given two input integers for an arrowhead and arrow body, print a right-facing arrow. Ex: If the input is 0 1, the output is
    8·1 answer
  • The in situ moist unit weight of a soil is 17.3 kN/m3 and the moisture content is 16%. The specific gravity of soil solids is 2.
    12·1 answer
  • Identify the four engineering economy symbols and their values from the following problem statement. Use a question mark with th
    10·1 answer
  • Current density is given in cylindrical coordinates as J = −106z1.5az A/m2 in the region 0 ≤ rho ≤ 20 µm; for rho ≥ 20 µm, J = 0
    13·1 answer
  • The basic barometer can be used to measure the height of a building. If the barometric readings at the top and the bottom of a b
    15·1 answer
  • A tank contains initially 2500 liters of 50% solution. Water enters the tank at the rate of 25 iters per minute and the solution
    13·1 answer
  • NEEDS TO BE IN PYTHON:ISBN-13 is a new standard for indentifying books. It uses 13 digits d1d2d3d4d5d6d7d8d910d11d12d13 . The la
    15·1 answer
  • Small droplets of carbon tetrachloride at 68 °F are formed with a spray nozzle. If the average diameter of the droplets is 200 u
    10·1 answer
  • A cylinder with a 6.0 in. diameter and 12.0 in. length is put under a compres-sive load of 150 kips. The modulus of elasticity f
    5·1 answer
  • A center-point bending test was performed on a 2 in. x d in. wood lumber according to ASTM D198 procedure with a span of 4 ft an
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!