
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Add a new method to ArrayTools called copy. Make this method accept two String arrays. Copy the content from the first array into the second array. If the second array isn't big enough, show an error message.
Write in Java and use test case 1 as result.
![Test Case 1
How many strings? \n
3 ENTER
Enter a value: \n
a ENTER
Enter a value: \n
b ENTER
Enter a value: \n
C ENTER
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: c\n
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: cn
[3]: null \n
copy/print test 1 \n
Error: Second array isn't big enough. \n
First array size: 3\n
Second array size: 2 \n
[0]: null \n
[1]: null \n
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: c\n
[3]: null \n
[4]: null \n
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: c\n
[3]: null \n
[4]: null \n
[5]: null \n
[6]: null \n
[7]: null \n
[8]: null \n](https://content.bartleby.com/qna-images/question/3064d3b4-17c7-48fb-b797-1fcca0646f95/1b8197ee-7ec6-476f-9f24-0bb59f64e135/3dpr0fh_thumbnail.png)
Transcribed Image Text:Test Case 1
How many strings? \n
3 ENTER
Enter a value: \n
a ENTER
Enter a value: \n
b ENTER
Enter a value: \n
C ENTER
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: c\n
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: cn
[3]: null \n
copy/print test 1 \n
Error: Second array isn't big enough. \n
First array size: 3\n
Second array size: 2 \n
[0]: null \n
[1]: null \n
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: c\n
[3]: null \n
[4]: null \n
copy/print test 1 \n
[0]: a \n
[1]: b\n
[2]: c\n
[3]: null \n
[4]: null \n
[5]: null \n
[6]: null \n
[7]: null \n
[8]: null \n
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 6 images

Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Did I miss something because in the output it doesn't mention anything about the
First array size: 3\n
Second array size: 2\n
in the code? It just skips over it.
Solution
by Bartleby Expert
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Did I miss something because in the output it doesn't mention anything about the
First array size: 3\n
Second array size: 2\n
in the code? It just skips over it.
Solution
by Bartleby Expert
Knowledge Booster
Similar questions
- write a code in java that has a row of 3 and a column of 3 and prints out the even numbers but if there is an odd number it instead prints it the space blankarrow_forwardWrite a method to replace all spaces in a string with '%20'. You may assume that the stringhas sufficient space at the end to hold the additional characters, and that you are given the "true"length of the string. (Note: If implementing in Java, please use a character array so that you canperform this operation in place.)EXAMPLEInput: "Mr John Smith ", 13Output: "Mr%20John%20Smith"arrow_forward4. Say we wanted to get an iterator for an ArrayList and use it to loop over all items and print them to the console. What would the code look like for this? 5. Write a method signature for a method called foo that takes an array as an argument. The return type is void. 6. What is the difference between remove and clear in ArrayLists.arrow_forward
- Provide a different implementation of ChoiceQuestion. Instead of storing the choices in an array list, the addChoice method should add the choice to the question text. For this purpose, an addLine method has been added to the Question class. Use the following files: Question.java /** A question with a text and an answer.*/public class Question{ private String text; private String answer; /** Constructs a question with empty text and empty answer. */ public Question() { text = ""; answer = ""; } /** Sets the answer for this question. @param correctResponse the answer */ public void setAnswer(String correctResponse) { answer = correctResponse; } /** Checks a given response for correctness. @param response the response to check @return true if the response was correct, false otherwise */ public boolean checkAnswer(String response) { return response.equals(answer); } /** Add a line of text to…arrow_forwardWrite the Java method averageOfDoubles that is passed an array of double values, and returns the average of the array values.You can assume the array length is a positive integer.arrow_forwardHello! I need some help with my Java homework. Please use Eclipse Please add comments to the to program so I can understand what the code is doing and learn Create a new Eclipse project named so as to include your name (eg smith15 or jones15). In this project, create a new package with the same name as the project. In this package, write a solution to the exercise noted below. Implement the following method that returns the maximum element in an array: public static <E extends Comparable<E>> E max(E[] list) Write a test program that generates 10 random integers, invokes this method to find the max, and then displays the random integers sorted smallest to largest and then prints the value returned from the method. Max sure the the last sorted and returned value as the same!arrow_forward
- Show your code and console with the exact sample run. Thankyouarrow_forwardYou are given an array of n integers. Write a java method that splitsthe numbers of the array into two equal groups so that the GCD of all numbers in the second group is equal to one and the GCD of all numbers in the first group is not one. After splitting the numbers display the resulting groups as shown in the sample run below. Note: 1. The array has even size. 2. All elements of the array are less than 100. You are not allowed to define new arrays. 3. 4. You are not allowed to definenew methods or use methods from java libraries. Sample run of the method: Inputarray: (6,7,9,4,3,2} Output Group two: (7,9,3} Group one: (2,4,6} I Ignore Order of numbers. Order is not important //Ignore Order of numbers. Order is not importantarrow_forwardCan you help me fix my code in Java, please? I am stuck to keep going. Thank youarrow_forward
- Write a java method called switchThem that accepts two integer arrays as parameters and switches the contents of the arrays. Take into account that the arrays may be of different sizes.arrow_forwardNeeds to be written in java: Write a program with a main() method that asks the user to input an integer array of 10 elements.Next, create three methods described below. From inside your main() method, call each of thethree methods described below and print out the results of the methods 2, 3, which return values.1. printReverse() - a method that receives an array of integers, then reverses the elements ofthe array and prints out all the elements from inside the method. Print all in one lineseparated by commas (see sample output below).2. getLargest() – a method that receives an array of integers, then returns the largest integervalue in the array. (print result from main())3. computeTwice()- a method that receives the previously reversed array of integers, thenreturns an array of integers which doubles the value of each number in the array (see thesample output below). (print result from main())Sample output:Enter a number:22Enter a number:34Enter a number:21Enter a number:35Enter a…arrow_forwardThis question is in java The Sorts.java file is the sorting program we looked at . You can use either method listed in the example when coding. You want to add to the grades.java and calculations.java files so you put the list in numerical order. Write methods to find the median and the range. Have a toString method that prints the ordered list, the number of items in the list, the mean, median and range. Ex List: 20 , 30 , 40 , 75 , 93Number of elements: 5Mean: 51.60Median: 40Range: 73 Grades.java is the main file import java.util.Scanner;public class grades { public static void main(String[] args) { int n; calculation c = new calculation(); int array[] = new int[20]; System.out.print("Enter number of grades that are to be entered: "); Scanner scan = new Scanner(System.in); n = scan.nextInt(); System.out.println("Enter the grades: "); for(int i=0; i<n; i++) { array[i] = scan.nextInt(); if(array[i] < 0) {…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY