1answer.
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
Wittaler [7]
3 years ago
14

Write a public static method named insert. The insert method should have the signature insert(String[] words, String newWord, in

t place), should return a boolean, and should function as described below.
When called, if place does not represent a valid index for words, then the method will return false to indicate the insertion could not be performed and do nothing else. Otherwise the method will insert the String newWord into the array words at the index place, moving each subsequent entry one place further and losing the final String in the array. The method will then return true to indicate the insertion has taken place.
Use the runner class to test this method: do not add a main method to your code in the U6_L4_Activity_One.java file or it will not be scored correctly.
Here is the runner code:
import java.util.Scanner;
public class runner_U6_L4_Activity_One{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter array length:");
int len = scan.nextInt();
scan.nextLine();
String[] wordList = new String[len];
System.out.println("Enter values:");
for(int i = 0; i < len; i++){
wordList[i] = scan.nextLine();
}
System.out.println("Enter new String:");
String insWord = scan.nextLine();
System.out.println("Enter place:");
int pos = scan.nextInt();
System.out.println("Method return: " + U6_L4_Activity_One.insert(wordList, insWord, pos));
System.out.print("Array contents: {");
for(int i = 0; i < len-1; i++){
System.out.print(wordList[i] + ", ");
}
System.out.println(wordList[len-1]+"}");
}
}
Computers and Technology
1 answer:
Mumz [18]3 years ago
5 0

Answer:

Explanation:

The following code was written in Java and performs the exact requirements listed in the question. It has also been tested by the runner code and works perfectly.

public static boolean insert(String[] words, String newWord, int place) {

               if (place > words.length) {

                   return false;

       } else {

                   for (int x = words.length - 1; x >= 0; x--) {

                       if (place == x) {

                           words[x] = newWord;

                           break;

                       } else {

                           words[x] = words[x-1];

                       }

                   }

                   return true;

               }

   }

You might be interested in
The background image does not affect any cell’s format or content. _______
Korvikt [17]
Hmmm...that is true 
Here a quizlet about if you need it!
https://quizlet.com/15207805/csci-241-flash-cards/
3 0
3 years ago
What is a computer OPERATING SYSTEM?
Alex17521 [72]

Answer:

A computer OPERATING SYSTEM is a system software that manages computer hardware, software resources, and provides common services for computer programs.

Explanation:

5 0
3 years ago
Which structural semantic will this HTML code snippet form?
Yakvenalex [24]

Answer:

D. Block

Explanation:

Semantic HTML or semantic markup is HTML that introduces meaning to the web page rather than just presentation. For example, a <p> tag indicates that the enclosed text is a paragraph. This is both semantic and presentational because people know what paragraphs are, and browsers know how to display them.

3 0
2 years ago
What command should you use to rearrange parts of files on the drive so they are contiguous?
Sunny_sXe [5.5K]
<span>What command should you use to rearrange parts of files on the drive so they are contiguous? Answer = Defrag</span>
3 0
4 years ago
Write a program that lets the Michigan Popcorn Company keep track of their sales for seven different types of popcorn they produ
valentina_108 [34]

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.    // declare and initialize popcorn name array
  6.    string popcorn_name[7] = {"plain", "butter", "caramel", "cheese", "chocolate", "turtle", "zebra"};
  7.    // declare and initialize sales array with 7 elements
  8.    int sales[7];
  9.    
  10.    // A loop to prompt user to enter sales for each popcorn
  11.    for(int i=0; i < 7; i++){
  12.        cout<<"Enter number of sales for " + popcorn_name[i] + " :";
  13.        cin>>sales[i];
  14.    }
  15.    
  16.    // Find maximum sales
  17.    int max = sales[0];
  18.    int maxIndex = 0;
  19.    for(int j=1; j < 7; j++){
  20.        if(max < sales[j]){
  21.            max = sales[j];
  22.            maxIndex = j;
  23.        }
  24.    }
  25.    
  26.    // Find minimum sales
  27.    int min = sales[0];
  28.    int minIndex = 0;
  29.    for(int k=1; k < 7; k++){
  30.        if(min > sales[k]){
  31.            min = sales[k];
  32.            minIndex = k;
  33.        }
  34.    }
  35.    
  36.    // Print popcorn name and sales
  37.    for(int l=0; l < 7 ; l++){
  38.        cout<<popcorn_name[l]<<"\n";
  39.        cout<<"Sales: "<< sales[l]<<"\n\n";
  40.    }
  41.    
  42.    // Print popcorn name with maximum and minimum sales
  43.    cout<<"Highest selling: "<< popcorn_name[maxIndex]<<"\n";
  44.    cout<<"Lowest selling: "<<popcorn_name[minIndex]<<"\n";
  45.    return 0;
  46. }

Explanation:

Create two arrays to hold the list of popcorn name and their sales (Line 5-8). Next prompt user to input the sales for each popcorn (Line 10-14). Get the maximum sales of the popcorn (Line 17-24) and minimum sales (Line 27-34). Print the popcorn name and sales (Line 37-40) and the popcorn name with highest and lowest selling (Line 43-44).

5 0
3 years ago
Other questions:
  • The rules that establish an orderly transfer of data between sender and receiver are called ____.
    5·2 answers
  • Two users, UserA and UserB, are engaging in secure communication using only asymmetrical encryption. UserA needs to send a secur
    11·1 answer
  • Which element of the word program window contains buttons for saving a document and for undoing, redoing, and repeating a change
    5·1 answer
  • Which of the following is the definition of Internet Protocol Security ( IPSec)? A remote access client/server protocol. It is a
    13·2 answers
  • With ______________, the cloud provider manages the hardware including servers, storage, and networking components. The organiza
    6·1 answer
  • Why is an ISA unlikely to change between successive generations of microarchitectures
    11·1 answer
  • You are creating a business report for your organization. Where will you find the options to edit the margins of your document?
    11·2 answers
  • What is the output?
    6·2 answers
  • The Windows Net use command is a quick way to discover any shared resources on a computer or server. True or False
    8·1 answer
  • Intro Programming - Problem(s)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!