
Concept explainers
Objectives:
- Construct and use 1D and 2D arrays
- Send arrays to methods
- Iterate through an array to perform a calculation
Details:
This assignment will be completed using the Eclipse IDE. Attach your .java file to the Assignment page.
Which of the following five people is the most interesting famous computer scientist?
- Grace Hopper
- Ada Lovelace
- Katherine Johnson
- Frances Allen
- Shafi Goldwasser
Let’s say that we ask a group of 20 people to vote for which one of the computer scientists is most interesting. Each voter votes for one candidate and, of course, we are interested in who wins.
Our data is a matrix with each row representing one of the five computer scientists and each column representing one of the 20 voters. The data in the matrix consists of 1s and 0s. The number 1 in each column represents a vote for the candidate represented by that row.
Here is an example matrix (the data matrix is just the numbers). Next to each row is the name of the computer scientist represented by that row.
10001001000000000000 Grace Hopper
00010000100111000010 Ada Lovelace
00100100001000000000 Katherine Johnson
01000010000000111101 Francis Allen
00000000010000000000 Shafi Goldwasser
The way we read this is that the first voter (the first column) voted for Grace Hopper (the first row) because a 1 appears in that row x column combination. The rest of the numbers in that first column are zeros. The second voter voted for Francis Allen. The third voter voted for Katherine Johnson, and so on. Every column should have a single 1 and the rest 0s. By counting across the columns, we can see how many votes each candidate received from the 20 voters. For example, in this case Grace Hopper received three votes, Ada Lovelace received six votes, and so on.
In your assignment, you will examine data from three voter groups like the one above. The ultimate goal is to determine who wins in each group.
Here are the two sets of data you will use:
group1:
10001001000000000000
00010000100111000010
00100100001000000000
01000010000000111101
00000000010000000000
group2:
00100000000110000000
00010000010001110001
11001000100000000010
00000110000000000100
00000001001000001000
For each of the two groups, your code will:
- Count the number of votes for each candidate and print them out.
- Determine who the winner is and print out their name.
- Finally, just to show off, print the raw data in the row x column format as shown above, and then print the transpose of the matrix in column x row format.
Your code will be “verbose” about what it is doing – printing out progress as it is processing the data.
Here is the code that you should put in the main method in order to produce the output above:
System.out.println("Voting Group 1");
winner = winnerIndex(group1,name);
System.out.println("The winner is " + name[winner]);
System.out.println("Raw data row x column: ");
printAllData(group1);
System.out.println("Raw data column x row: ");
printTransposeData(group1);
System.out.println("\nVoting Group 2");
winner = winnerIndex(group2,name);
System.out.println("The winner is " + name[winner]);
System.out.println("Raw data row x column: ");
printAllData(group2);
System.out.println("Raw data column x row: ");
printTransposeData(group2);
In order to get this to work, you will need to do the following:
- In the main method, create an array to hold the names of the five computer scientists. Refer to it by a variable called name. Assign each computer scientist’s name to successive elements of the name array. (Hint: Remember that you can declare an array and populate it with values in a single statement.)
- In the main method, create arrays to hold the values of the two voting matrices. Refer to them by variable names group1 and group2. Assign the values from the two voting matrices to the appropriate elements in the group1 and group2 arrays. (Hint: Remember that you can declare an array and populate it with values in a single statement.)
- Write a method called winnerIndex that tallies the votes for each candidate, determines who has the most votes, and returns the index of the winner. As you can see from the main method code, winnerIndex should accept references to a vote array and to the name array as arguments. winnerIndex should:
- Count the votes for each candidate row. For each row, print “Votes for” followed by the name of the candidate being tallied (using the name array), followed by “=”, followed by the sum of votes for that candidate.
- Keep track of which candidate has the most votes and return the array index value for that candidate.
- Write a method called printAllData that simply prints the vote array in row x column format.
- Write a method called printTransposeData that prints the transpose of the matrix, column x row format.

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

- А class with 10 students will take 3 exams. Use 3 arrays to hold the score for each student and another array to hold the average of each student.arrow_forwardCreate grid and play_board Step 1: Assign two variables grid_n should be assigned the integer 15 iter_n should be assigned the integer 25 Step 2: Call play_board Call play_board() with the following inputs for the parameters in play_board: bots | input should be bots_list grid_size | input should be grid_n n_iter | input sould be iter_n Upon executing the cell, you should see a a 15x15 grid, with three bots (of different shapes), wandering around the grid for 25 iterations.arrow_forwardSkybox class (M Visual Studios): Modify the skybox class appropriately to handle cube mapping. This involves loading six images for the cube map, setting appropriate texture parameters, and ensuring the normals of the cube model that encoded and runs sucessfully Task: The upload_CubeMap_images() function in the Skybox.cpp file needs to be implemented sucessfully according to the instructions.Instructions: Enable cube mapping: Use glEnable(GL_TEXTURE_CUBE_MAP) to enable cube mapping. Generate a texture ID: Use glGenTextures() to generate a texture ID to hold the cube map. This ID is stored in the tex_buffer_ID member variable of the Skybox class. Bind the texture ID: Use glBindTexture() to bind the texture ID as the current buffer. Make sure to bind it as a cube map using GL_TEXTURE_CUBE_MAP. Load six images: Load all six images into the correct "place" in the cube map. You can use the provided file paths (BMP_NEG_X_FILE_PATH, BMP_NEG_Y_FILE_PATH, etc.) to load the images. (Make sure to…arrow_forward
- body { font-family: Georgia, serif; font-size: 100%; line-height: 175%; margin: 0 15% 0; background-color:rgb(210,220,157); background-image: url("/Users/332bo/Desktop/Week_9_Lab/images/bullseye.png"); /* Rounded Shape image */ /* background-repeat:round space; */opacity: 0.5; background-size: contain; } header { margin-top: 0; padding: 3em 1em 2em 1em; text-align: center; border-radius:4px; background-color:hsl(0, 14%, 95%); background-image: url("/Users/332bo/Desktop/Week_9_Lab/images/purpledot.png"); background-repeat: repeat-x; } a { text-decoration: none; color:rgb(153,51,153); } a:visited { color: hsl(300, 13%, 51%); } a:hover { background-color: #fff; } a:focus { background-color: #fff; } a:active{color:#ff00ff;} h1 { font: bold 1.5em Georgia, serif; text-shadow: 0.1em 0.1em 0.2em gray; color: rgb(153,51,153);} h2 { font-size: 1em; text-transform: uppercase; letter-spacing: 0.5em; text-align: center; color:rgb(204,102,0); }dt { font-weight: bold; } strong { font-style: italic; }…arrow_forwardWhat function is required after you have made changes to the pixels[] array. updatePixels() loadPixels() accessPixels() createPixels()arrow_forwardHello I need help with Some JavaScript.arrow_forward
- Using Eclipsearrow_forwardPlease provide a pseudocode solution that utilizes the commands as specified in the image.arrow_forwardIn this assignment, students will demonstrate their understanding of how to create and manipulate NumPy Arrays. Create a 3-by-5 Array Select and Display Row 2 Select and Display Column 5 Select and Display Columns 2-4 Select Element in Row 1 and Column 4 Select all elements from Rows 1 and 2 that are in Columns 0, 2, and 4. Exitarrow_forward
- Alert dont submit AI generated answer.arrow_forwardWrite a code to the following image using Console.WriteLine.arrow_forwardCreate three students with the following details: Snow White, student ID: A00234,credits: 24 Lisa Simpson, student ID: C22044,credits: 56 Charlie Brown, student ID: A12003,credits: 6 Then enter all three into a lab and print a list to the screen.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





