Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how do i do this? i am to write a class that has 2 instant variables: Word = an

ID: 3533423 • Letter: H

Question

how do i do this?

i am to write a class that has 2 instant variables: Word = an array of 26 chars that is final of letters a-z jumble = array of 26 also but it has to be randomly arranged.... jumble has to have a method of "doJumble" that has to be called by my constructor.

By jumbling the word, a new String is created where the letters of the array "Word" will be changed to the corresponding letter from the "jumble" array. and converts converts all letters to small letters. To switch the array "Word"  a new String will be then created where NOW the letters in the array "jumble" will be changed to the original array "Word" are replaced by the corresponding letter in the original alphabet.

Since there are 26 characters in array Word, the array jumble will also have 26 but in random order. To do this "doJumble" method we can do:

do a substitute array that has the same size of array Word, then copy all the elements from array Word to the array substitute, then use a "for loop" for each of the index in the array substitute(such as i) then generate a position that is random within the "substitute" array(such as place) and swap the element at index i with the element at index place, then return the "substitute" array.


public class Jumble

{

public final char [] Word = 26;

  public char [] jumble = 26;

  

public Jumble()

{

this.jumbleword = new ?????????


From here I am stuck as I do not know what to do ...........

I believe I can do the for loop such as:


  for(int i = 0; i < this.jumbleword.length; i++)

{

for (int j = 0; j < this.jumbleword.length; j++)

{

this.letterGrid[i][j] = new???????? [i] [j];

}

on my client i have this.............

public class JumbleClient

{

public static void main( String [] args )

{

char [][] allLetters =

{ {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 };

Jumble newword = new Jumble(allLetters)

then I'm going to call toString................

Explanation / Answer

Here you go, please rate my previous answer if I answered late :


import java.util.ArrayList;

import java.util.Collections;


public class Test

{

private char[] word={'a','b','c','d','e','f','g','h','i','j','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

private char[] jumble=new char[26];

public Test()

{

doJumble(word);

System.out.println("Jumbled :");

for(char e:jumble)

{

System.out.print(e+" ");

}

}

public void doJumble(char[] a)

{

ArrayList<Character> ar=new ArrayList<Character>();

for(char e:word)

{

ar.add(e);

}

Collections.shuffle(ar);

for(int i=0;i<jumble.length;i++)

{

jumble[i]=ar.get(i);

}

}

public static void main(String[] a)

{

new Test();

}

}