
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
![34
using prompt
"Enter an integer as the random generator seed:
35
36
37
// Step 7: Create a Random object using the input seed
38
39
40
// Step 8: Use a for loop to create the specified number
of frogs and add them to the array list.
The weights of the frogs must be in the range
[MIN_WEIGHT, MAX_WEIGHT] and be generated by
the Random object created in Step 7
41
//
42
43
//
44
45
//
46
47
System.out.println("All frogs before swapping:");
48
49
// Step 9: Use the enhanced for loop to print
out all frogs in the list, one per line
50
51
52
53
// Step 10: Calculate the index of the last frog
in the list and store it in a variable
54
55
56
57
// Step 11: Swap the first and the last frogs in the list
58
59
60
System.out.println("All frogs after swapping: ");
61
62
//Step 12: Use the enhanced for loop to print
out all frogs in the list, one per line
63
64
65
66
67
68
69](https://content.bartleby.com/qna-images/question/41fc4194-ca6a-4c74-975f-c41e6cb486ed/04217b16-a081-4f90-8501-034c5a479cd1/ppqvd8_thumbnail.jpeg)
Transcribed Image Text:34
using prompt
"Enter an integer as the random generator seed:
35
36
37
// Step 7: Create a Random object using the input seed
38
39
40
// Step 8: Use a for loop to create the specified number
of frogs and add them to the array list.
The weights of the frogs must be in the range
[MIN_WEIGHT, MAX_WEIGHT] and be generated by
the Random object created in Step 7
41
//
42
43
//
44
45
//
46
47
System.out.println("All frogs before swapping:");
48
49
// Step 9: Use the enhanced for loop to print
out all frogs in the list, one per line
50
51
52
53
// Step 10: Calculate the index of the last frog
in the list and store it in a variable
54
55
56
57
// Step 11: Swap the first and the last frogs in the list
58
59
60
System.out.println("All frogs after swapping: ");
61
62
//Step 12: Use the enhanced for loop to print
out all frogs in the list, one per line
63
64
65
66
67
68
69
![16 public class FrogListApp
17
public static void main(String[] args)
18
19
final int MIN_WEIGHT = 1;
13B
final int MAX_WEIGHT = 25;
20
21
22
// Step 3: Create an array list to store Frog objects
23
24
25
// Step 4: Create a Scanner object
26
27
28
// Step 5: Read an integer as the number of frogs
using prompt "Enter the number of frogs:
29
30
31
32
// Step 6: Read an integer as the random generator seed
33
using prompt
"Enter an integer as the random generator seed: "
34
%3D
35
//
36
37
// Step 7: Create a Random object using the input seed
38
39
40
// Step 8: Use a for loop to create the specified number
of frogs and add them to the array list.
The weights of the frogs must be in the range
[MIN WEIGHT, MAX WEIGHT] and be generated by
the Random object created in Step 7
41
42
//
//
43
44
45
//
46
47
System.out.println("Al1 frogs before swapping:");
48
49
// Step 9: Use the enhanced for loop to print
50](https://content.bartleby.com/qna-images/question/41fc4194-ca6a-4c74-975f-c41e6cb486ed/04217b16-a081-4f90-8501-034c5a479cd1/l36b4s_thumbnail.jpeg)
Transcribed Image Text:16 public class FrogListApp
17
public static void main(String[] args)
18
19
final int MIN_WEIGHT = 1;
13B
final int MAX_WEIGHT = 25;
20
21
22
// Step 3: Create an array list to store Frog objects
23
24
25
// Step 4: Create a Scanner object
26
27
28
// Step 5: Read an integer as the number of frogs
using prompt "Enter the number of frogs:
29
30
31
32
// Step 6: Read an integer as the random generator seed
33
using prompt
"Enter an integer as the random generator seed: "
34
%3D
35
//
36
37
// Step 7: Create a Random object using the input seed
38
39
40
// Step 8: Use a for loop to create the specified number
of frogs and add them to the array list.
The weights of the frogs must be in the range
[MIN WEIGHT, MAX WEIGHT] and be generated by
the Random object created in Step 7
41
42
//
//
43
44
45
//
46
47
System.out.println("Al1 frogs before swapping:");
48
49
// Step 9: Use the enhanced for loop to print
50
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 3 steps with 1 images

Knowledge Booster
Similar questions
- Write a hangman game that randomly generates a word andprompts the user to guess one letter at a time, as presented in the sample run.Each letter in the word is displayed as an asterisk. When the user makes a correctguess, the actual letter is then displayed. When the user finishes a word, displaythe number of misses and ask the user whether to continue to play with anotherword. Declare an array to store words, as follows:// Add any words you wish in this arrayString[] words = {"write", "that",...}; (Guess) Enter a letter in word ******* > p↵Enter(Guess) Enter a letter in word p****** > r↵Enter(Guess) Enter a letter in word pr**r** > p↵Enterp is already in the word(Guess) Enter a letter in word pr**r** > o↵Enter(Guess) Enter a letter in word pro*r** > g↵Enter(Guess) Enter a letter in word progr** > n↵Entern is not in the word(Guess) Enter a letter in word progr** > m↵Enter(Guess) Enter a letter in word progr*m > a↵EnterThe word is program. You missed 1 timeDo…arrow_forward2arrow_forwardThe Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, ... where each number (after the first two values) is the sum of the previous two numbers. Write a program that declares an integer array called fib_numbers with a length of 25 elements. The program then fills the array with the first 25 Fibonacci numbers using a loop. The program then prints the values to the screen using a separate loop.arrow_forward
- int [] arrayInt={3,54,90,22,32}; To print the last element in the arrayInt you will write: a. System.out.println(arrayInt[5]); b. System.out.println(arrayInt[0]); c. System.out.println(arrayInt[length]); d. System.out.println(arrayInt[4]);arrow_forwardWrite a loop that counts how many elements in an array are equal to zero. arrays.cpp 1 #include // sizet 2 int countZeros (const int values[], size_t size) { int count = 0; 3 4 for (int i; i using namespace std; 3 2 4 int countZeros(const int values[], size_t size); 5 int main() { int a[] = {1, 2, 0, 3}; cout <« countZeros (a, 4) <« endl; cout « "Expected: 1" « endl; 6 7 8 9 10 11 int b[] = {0, 2, 0, 3}; cout <« countZeros (b, 4) <« endl; cout « "Expected: 2" « endl; 12 13 14 15 int cl] -{1, 0, θ, 0, 0 ; cout <« countZeros (c, 5) <« endl; cout « "Expected: 4" « endl; 16 17 18 19 } CodeCheck Reset Testers Running Tester.cpp pass fail fail 1 Expected: 1 Expected: 2 Expected: 4 Score 1/3arrow_forwardStep 1: Read your files! You should now have 3 files. Read each of these files, in the order listed below. staticarray.h -- contains the class definition for StaticArray, which makes arrays behave a little more like Python lists O In particular, pay attention to the private variables. Note that the array has been defined with a MAX capacity but that is not the same as having MAX elements. Which variable indicates the actual number of elements in the array? staticarray.cpp -- contains function definitions for StaticArray. Right now, that's just the print() member function. 0 Pay attention to the print() function. How many elements is it printing? main.cpp -- client code to test your staticarray class. Note that the multi-line comment format (/* ... */) has been used to comment out everything in main below the first print statement. As you proceed through the lab, you will need to move the starting comment (/*) to a different location. Other than that, no changes ever need to be made to…arrow_forward
- 1)Examine the above code that creates the array: a)How is the base type of the array specified? b)How is the length of the array specified? c)How many Strings are actually stored in the array after the array has been created? d)How is the base type of the ArrayList specified? e)How is the capacity of the ArrayList specified? f)What is the capacity of the ArrayList? g)What is the size of the ArrayList?arrow_forwardGiven the code: float grades[10] = {4.4, 3.3, 2.2, 1.1, 0.0}; 1. Write a loop to print the entire array to the console. 2. Write the output of this code (what you see in the console when the loop runs).arrow_forwardThe contents of the array below represent a maxHeap. What would be the contents of the array after a deletion. Briefly explain how the deletion is done. 60 20 30 5 10 15 25arrow_forward
- Main difference between an array and an ArrayList is that an ArrayList can store more data types an ArrayList can store more elements an ArrayList executes faster for retrieval and insertion an ArrayList takes care of the memory management automatically an ArrayList uses positions and an array uses indicesarrow_forwardBonus Question: For the same array as in the last question, explain what this statement does: x = &x[2]; Hint: draw a memory diagram to help yourself find the correct answer.arrow_forwardIn javacode: Use ArrayList to create an array called myAL of type integer. --Fill the array with the values 5, 10, 15, 22, 33. --Print the array (use enhanced for loop). --Insert the value 25 between 10 and 15 and print the array.--Remove 2 elements on index 1 and 3 and then print the array.--Print if the array contains the value 123 or not.--Print the index of the element 22.--Print the size of the array.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