Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! ===========================================================================
public class StatsAnalyzer { public static int PlayerTotalPoints(int[][] scores, int p) { // assuming the 1st player data is at index 0 and // last player index is at p-1 index if (0 <= p && p < scores.length) { int totalPoints = 0; // player p data will be in row scores[p] for (int game = 0; game < scores[p].length; game++) { totalPoints += scores[p][game]; } return totalPoints; } return 0; } public static double playerAvgPoints(int[][] scores, int p) { // assuming the 1st player data is at index 0 and // last player index is at p-1 index if (0 <= p && p < scores.length) { double totalPoints = 0; // player p data will be in row scores[p] for (int game = 0; game < scores[p].length; game++) { totalPoints += scores[p][game]; } // divide totalpoints by game count to get average return totalPoints / scores[p].length; } return 0; } public static int teamPointsPerGame(int[][] scores, int g) { int points = 0; for (int i = 0; i < scores.length; i++) { points += scores[i][g]; } return points; } public static int teamBestGame(int[][] scores) { int bestGameIndex = 0; int bestGameTotalPoints = 0; for (int game = 0; game < scores[0].length; game++) { int gameTotalPoints = teamPointsPerGame(scores, game); if (gameTotalPoints > bestGameTotalPoints) { bestGameTotalPoints = gameTotalPoints; bestGameIndex = game; } } return bestGameIndex; } public static int lowestScoringPlayer(int[][] scores) { int lowestScoringPlayerIndex = 0; int lowestScore = Integer.MAX_VALUE; for (int player = 0; player < scores.length; player++) { for (int game = 0; game < scores[player].length; game++) { if (scores[player][game] < lowestScore) { lowestScore = scores[player][game]; lowestScoringPlayerIndex = player; } } } return lowestScoringPlayerIndex; } }
===========================================================================
Thanks, let me know for any questions or in case you encounter any issue.
Please do give a thumbs up from your end :
)
public class StatsAnalyzer { public static int PlayerTotalPoints(int[] [] scores, int p) { // assuming the...
Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....
You will implement the following method public static int[] linearSearchExtended(int[][] numbers, int key) { // Implement this method return new int[] {}; } There is a utility method provided for you with the following signature. You may use this method to convert a list of integers into an array. public static int[] convertIntegers(List<Integer> integers) Provided code import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; public class MatrixSearch { // This method converts a list of integers to an array...
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...
import java.util.Arrays; public class lab { public static void main(String args[]) { int arr[] = {10, 7, 8, 9, 1, 5,6,7}; int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; int arr3[] = {1, 3, 5, 3, 2, 6, 20}; quicksort(arr,0,arr.length-1); quicksort(arr2,0,arr2.length-1); quicksort(arr3,0,arr3.length-1); System.out.println(Arrays.toString(arr)); System.out.println(Arrays.toString(arr2)); System.out.println(Arrays.toString(arr3)); } private static int partition(int[] items,int low, int high) { int i=0; int j=0;...
Big-O notation for each public static double accumulate (double[] a) { double sum = 0.0; for (int i = 0; i < a.length; i++) sum += a[i]; return sum; } public static double innerProduct(double[] a, double[] b) { // assume a. length == b.length double sum = 0; for (int i = 0; i < a.length; i++) sum += a[i] * b[i]; return sum; } public static int twoSum(int[] a) { int count = 0; for (int i = 0;...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...
public class NumStack implements Comparable{ private Integer[] data; private int index; public NumStack(int cap){ data=new Integer[cap]; index =-1; } public boolean isEmpty(){ return index == -1; } public boolean isFull(){ return index==data.length -1; } public NumStack pop(){ if(!isEmpty()) data[index--]=null; return this; } public int size(){ return index+1; } public Integer top(){ if(isEmpty()) return null; return data[index]; } public NumStack push(int num){ if(index < data.length-1) data[++index]=num; return this; } public int compareTo(NumStack s){} } public int compareTo(NumStack s) compares two stack...
Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver { public static String solve(char[][] grid) { // TODO /* * 1. Construct a graph using grid * 2. Use BFS to find shortest path from start to finish * 3. Return the sequence of moves to get from start to finish */ // Hardcoded solution to toyTest return...
cant understand why my toString method wont work... public class Matrix { private int[][] matrix; /** * default constructor -- * Creates an matrix that has 2 rows and 2 columns */ public Matrix(int [][] m) { boolean valid = true; for(int r = 1; r < m.length && valid; r++) { if(m[r].length != m[0].length) valid = false; } if(valid) matrix = m; else matrix = null; } public String toString() { String output = "[ "; for (int i...
hey I need help finishing this simplex program. public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //FAIRE LES TODO dans Simplex test1();test2(); } private static void test1() { double[][] A = { { -1, 1, 0 }, { 1, 4, 0 }, { 2, 1, 0 }, { 3, -4, 0 }, ...