Step 3. Your starting code has a function readNames returns an array of student names. The temporary code you were given always returns the same five names shown above (Ava, Ben, .). Now you will change this function so that it reads from stdIn an integer N 2 0, followed by N names. You can assume that after N, the input will always be exactly N names, each on one line that could be read using the function stdIn.readString. There are several example data files in the directory that conform to this specification. For example names3. txt contains 3 names (Ava, Ben and Carol). Your function should return an array containing those N student names. For example, if you provide the file names3.txt on StdIn your version of readNames would return the three names in that text file, and the output would be: $ java-introcs ZoomRooms greedy 3 < names3.txt Room: e Ava Ben Carol Room: 1 Note that with the code we have so far we will always print out exactly two rooms, regardless of the number of students or the room capacity. We will fix that next. Step 4. Now you have a simple math problem. The second command line argument specifies the room size (the maximum capacity for each room). For example, in the command shown above it's 3 (right after the word "greedy"). Since the room size is 3, it means that Ava, Ben and Carol can all fit in Room 0. The function roomsNeeded should compute the number of rooms needed; but as provided it always just returns 2, no matter what. It takes two arguments: numStudents (the total number of students) and roomSize (the size of each room, as specified on the command line). Change this function to return numStudents divided by roomSize , rounding up to an integer in cases where it does not divide evenly. (Hint: there's a useful function the Math library.) Now you should get the following output, because only one room is needed: $ java-introcs ZoomRooms greedy 3 < names3.txt
Step 3. Your starting code has a function readNames returns an array of student names. The temporary code you were given always returns the same five names shown above (Ava, Ben, .). Now you will change this function so that it reads from stdIn an integer N 2 0, followed by N names. You can assume that after N, the input will always be exactly N names, each on one line that could be read using the function stdIn.readString. There are several example data files in the directory that conform to this specification. For example names3. txt contains 3 names (Ava, Ben and Carol). Your function should return an array containing those N student names. For example, if you provide the file names3.txt on StdIn your version of readNames would return the three names in that text file, and the output would be: $ java-introcs ZoomRooms greedy 3 < names3.txt Room: e Ava Ben Carol Room: 1 Note that with the code we have so far we will always print out exactly two rooms, regardless of the number of students or the room capacity. We will fix that next. Step 4. Now you have a simple math problem. The second command line argument specifies the room size (the maximum capacity for each room). For example, in the command shown above it's 3 (right after the word "greedy"). Since the room size is 3, it means that Ava, Ben and Carol can all fit in Room 0. The function roomsNeeded should compute the number of rooms needed; but as provided it always just returns 2, no matter what. It takes two arguments: numStudents (the total number of students) and roomSize (the size of each room, as specified on the command line). Change this function to return numStudents divided by roomSize , rounding up to an integer in cases where it does not divide evenly. (Hint: there's a useful function the Math library.) Now you should get the following output, because only one room is needed: $ java-introcs ZoomRooms greedy 3 < names3.txt
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images
Recommended textbooks for you
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
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