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
Molodets
3 months ago
15

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 b

Computers and Technology
1 answer:
amid [951]3 months ago
3 0

Response:

Here is the JAVA program:

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

public class DrawHalfArrow{ // beginning of the half arrow class  

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

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

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 arrow base height, width, and head width  

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

arrowBaseHeight = scnr.nextInt(); // scans input as an integer  

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

arrowBaseWidth = scnr.nextInt();  

/* while loop to keep asking for arrow head width until it's greater than the arrow base width */  

while (arrowHeadWidth <= arrowBaseWidth) {  

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

   arrowHeadWidth = scnr.nextInt(); }  

// begins the nested loop  

// outer loop runs as many times as the arrow base height  

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

// inner loop prints the asterisks  

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

         System.out.print("*");        } // shows asterisks  

         System.out.println();          }  

// a temporary variable to store the width of the arrowhead  

int k = arrowHeadWidth;  

// outer loop to iterate the number of times equal to the arrowhead height  

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

{     for(int j = k; j > 0; j--)     {// inner loop to print asterisks  

      System.out.print("*");    } // shows asterisks  

  k = k - 1;  

  System.out.println(); } } } // continues adding more asterisks for a new line  

Clarification:

This program requests the user to input the arrow base height, base width, and head width. When the head width is asked, it checks that the width must exceed that of the base width. The while loop keeps prompting until a valid head width is entered.

The loop generates an arrow base matching the specified height. This satisfies the first condition.

A nested loop outputs the base with the specified width. The inner loop draws the asterisks to form the base, while the outer loop iterates according to the base height, thus meeting the second condition.

A temporary variable k stores the initial value of head width during modifications.

The final nested loop produces the arrow head with the specified width. The inner loop handles star printing for the arrow head, fulfilling the third condition.

The temporary variable k decreases by one for subsequent iterations to produce one less asterisk each time.

Attached is the output screenshot.

You might be interested in
Write a class named Taxicab that has three **private** data members: one that holds the current x-coordinate, one that holds the
amid [951]

Response:

Refer to the explanation

Details:

class Taxicab():

def __init__(self, x, y):

self.x_coordinate = x

self.y_coordinate = y

self.odometer = 0

def get_x_coord(self):

return self.x_coordinate

def get_y_coord(self):

return self.y_coordinate

def get_odometer(self):

return self.odometer

def move_x(self, distance):

self.x_coordinate += distance

# increase the odometer with the absolute distance

self.odometer += abs(distance)

def move_y(self, distance):

self.y_coordinate += distance

# increase odometer with the absolute distance

self.odometer += abs(distance)

cab = Taxicab(5,-8)

cab.move_x(3)

cab.move_y(-4)

cab.move_x(-1)

print(cab.odometer) # will output 8 3+4+1 = 8

7 0
2 months ago
Choose the person responsible for each innovation.
zubka84 [1067]

Response:

John Blankenbaker

Reasoning:

5 0
2 months ago
Assume that k corresponds to register $s0, n corresponds to register $s2 and the base of the array v is in $s1. What is the MIPS
Amiraneli [1052]
Your question is missing the section C, so here is the C segment while (k<n v="" k="k+1;" answer:="" while:="" bge="" end="" while="" n="" addi="" sll="" making="" indexable="" add="" lw="" sw="" j="" end:="" explanation:="" the="" mips="" assembly="" code="" reflecting="" c="" segment="" is="" />
4 0
1 month ago
You just read an msds for acetic acid. based on what you read, what type of information is included in an msds sheet? record you
maria [1035]
The MSDS sheet is packed with details such as the owning company of the acid, the ingredient's makeup, potential hazards and their management, first aid steps, and firefighting precautions, among other things. It provides comprehensive information necessary for laboratory safety when handling various chemicals. 
3 0
1 month ago
Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
amid [951]

Response:

a. Current disks do not reveal the actual locations of logical blocks.

Clarification:

Modern disks incorporate scheduling algorithms within the disk drive itself. This presents challenges for operating systems trying to optimize rotational latency. All scheduling methods end up having to perform similarly due to potential constraints faced by the operating system. Disks are typically accessed in physical blocks. Modern technology applies more electronic control to the disk.

4 0
2 months ago
Other questions:
  • Write a function solution that returns an arbitrary integer which is greater than n.
    13·1 answer
  • A company requires an Ethernet connection from the north end of its office building to the south end. The distance between conne
    8·1 answer
  • Sophie often makes grammatical errors in her document. Which feature of the Spelling and Grammar tool can she use to understand
    15·2 answers
  • This question refers to a standard deck of playing cards. If you are unfamiliar with playing cards, there is an explanation in P
    10·2 answers
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
  • Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
    8·1 answer
  • Dr. Collins has a personal website where he encourages his students to solve questions and discuss topics he taught in class. Wh
    14·2 answers
  • Within a word processing program, predesigned files that have layout and some page elements already completed are called text bo
    15·1 answer
  • An ISP is granted the block 16.12.64.0/20. The ISP needs to allocate addresses for 8 organizations, each with 256 addresses. a.
    12·1 answer
  • A feedback mechanism that can be used to measure the effectiveness of a CSIRT is the ____. a. after action review b. IR plan tes
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!