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
1 month 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 [800]1 month 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
The Online Shopping system facilitates the customer to view the products, inquire about the product details, and product availab
amid [800]
Refer to the explanation provided. In the online shopping software system, five actors can be identified: A Customer can perform actions such as exploring products and seeking product information. The interface allows for the creation of customer accounts facilitating purchases. Additionally, customers can browse items by using search categories or keywords, and they are able to order and make payments for their selected products. The payment system accepts two primary methods: credit card and PayPal. A Seller can list products in appropriate categories and create accounts to gain membership. An Administrator manages product listings and can modify existing categories or introduce new ones. Finally, the Site Manager has the capability to view different reports regarding customer orders, seller-added products, and user-created accounts.
3 0
14 days ago
Your computer science teacher asks you to sample a black and white image that is 4" x 6". How would you sample the image to prov
8_murik_8 [892]

Answer:

The maximum dimensions possible for an image using the pixelation widget are 255 by 255 pixels.

When an image undergoes resizing, its pixel count may either increase or decrease, resulting in resampling. This process alters the overall file size.

Explanation: This is all the information I could gather. I hope it's useful. Sorry.

3 0
1 month ago
Explain working principle of computer?​
maria [879]

Answer:

The principle behind how computer systems operate involves a primary machine-based function that remains invisible to us, serving as a control center that changes the input data into output. This central element known as the central processing unit (CPU) illustrates that the operation of computers is quite intricate.

Explanation:

5 0
1 month ago
Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
8_murik_8 [892]

Answer:

Below is the JAVA program:

import java.util.Scanner;   //to take input from user

public class Main {  //name of the class

  public static void main(String[] args) {  //beginning of main method

      Scanner input = new Scanner(System.in);  //creates Scanner instance

      int integer = input.nextInt();  //defines and collects an integer for the number of words

      String stringArray[] = new String[integer]; //initializes an array to hold strings

      for (int i = 0; i < integer; i++) {  //iterates through the array

          stringArray[i] = input.next();         }  //collects strings

      int frequency[] = new int[integer];  //creates an array for holding frequencies

      int count;         //initializes variable to calculate frequency of each word

      for (int i = 0; i < frequency.length; i++) {  //iterates through frequency array

          count = 0;  //sets count to zero

          for (int j = 0; j < frequency.length; j++) {  //iterates through array

              if (stringArray[i].equals(stringArray[j])) {  //checks if element at ith index matches jth index

                  count++;                 }            }  //increments count

          frequency[i] = count;      }  //stores count in the frequency array

      for (int i = 0; i < stringArray.length; i++) {  //iterates through the string array

          System.out.println(stringArray[i] + " " + frequency[i]);         }    }    } //displays each word and its frequency

Explanation:

To illustrate the program, consider:

let integer = 3

for (int i = 0; i < integer; i++) is used to input strings into stringArray.

On the first pass:

i = 0

0<3

stringArray[i] = input.next(); takes a word and saves it to the ith index of stringArray. For example, if the user types "hey", it will be in stringArray[0].

Then, i increments to i = 1

On the second pass:

i = 1

1<3

stringArray[i] = input.next(); takes another word and assigns it to stringArray[1]. If the user enters "hi", then hi will be in stringArray[1]

Next, i becomes i = 2

On the third pass:

i = 2

2<3

stringArray[i] = input.next(); captures a word and places it in stringArray[2]. If the user types "hi", it goes to stringArray[2]

Then, i increments to i = 3

The loop terminates since i<integers is false.

The next outer loop for (int i = 0; i < frequency.length; i++) and inner loop for (int j = 0; j < frequency.length; will check each word and if (stringArray[i].equals(stringArray[j])) identifies any duplicates. Words that repeat will have their count incremented and the frequency array will record these values. For example, hey appears once while hi shows up twice, thus resulting in the final outputs:

hey 1

hi 2

hi 2

The visual representation of the program and its outcome based on the example provided is attached.

4 0
1 month ago
(Java) Which of the following code segments correctly declare a Strings and gives it a value of "fortran".
maria [879]

Response:

IT F

Clarification:

8 0
1 month ago
Other questions:
  • When you add a zero to the right of a decimal number, it multiplies its value by 10 (For example, "15" becomes "150"). What simi
    10·1 answer
  • PLEASE HELP!!~~
    7·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    7·1 answer
  • U.S. industries like steel, computers, and energy need to be protected from foreign competition to ensure which of the following
    6·2 answers
  • The table is an excerpt from an interviewer’s notes about three applicants applying to the IT department.                
    15·1 answer
  • 3. What is the error in the following pseudocode? // The searchName function accepts a string containing the name // to search f
    6·1 answer
  • If a cell reference is c6, this cell is in the sixth column and the third row. true or false
    11·2 answers
  • In a survey of 7200 T.V. viewers, 40% said they watch network news programs. Find the margin of error for this survey if we want
    6·1 answer
  • A wireless network does not benefit like a wired network does, when it comes to collision reduction. Which device reduces collis
    6·1 answer
  • What problem does the DNS solve? How does the DNS help the world wide web scale so that billions of users can access billions of
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!