Question: textbook question:A method returning an array of letters with their highest point value in any country My question: I am trying to make a new

textbook question:A method returning an array of letters with their highest point value in any country My question: I am trying to make a new method return an array of letters with the highest point value in any country. i have already made one method that finds out if the country has a letter with a value of ten. But I cant figure out how to make one that will print out the letter that is the highest value in each country. Just for some extra help I have included another method I have already written.

Extra clarification for question that professor gave: the array to be returned by the first non-constructor method described is to be an array of `int`, laid out so that the slot indexed with 0 holds the requested value for `'a'`, the slot indexed with 1 holds the requested value for `'b'`, and so on.

Code: ========================================================================================

public class TenScrabble {

String[] countries = {"America", "Canada", "Chile", "Mexico", "Germany", "Norway", "Russia", "Japan", "Sweden", "Iraq"}; private char[] letters = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', 'p','q','r','s','t','u','v','w','x','y','z'}; private int[][] values= new int[10][26]; //Could also use new int[countries.length][letters.length] public TenScrabble() { /*Randomizes the letter values*/ for (int c = 0; c < countries.length; c++) { Random randGen = new Random(); for (int l = 0; l < letters.length; l++) {

values[c][l] = randGen.nextInt(10) + 1; } } }//end of constructor public char[] highestLetters() { char[] highestValueLetter = new char[countries.length];

for(int i =0; i< values.length; i++) { int max = Integer.MIN_VALUE;//placeholder which sets the max to the smallest possible number char highestLetter = 'a'; for(int j=0; j < values[i].length;j++) { if(values[i][j] > max) { max = values[i][j]; highestLetter = letters[j]; } } highestValueLetter[i] = highestLetter; }

return highestValueLetter; }//end of highestLetters

/*Prints out countries that have a letter with a value of 10*/ public void getLetterValue10() { int countriesWithValue = 0;//keeps track of the number of countries with value so it can print out none if none show up System.out.println("Countries that have a letter with a value of 10"); for(int i = 0; i < values.length;i++) { for(int j =0; j

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!