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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started