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

Building on H11a ; 1. Delete the loop that prints out 10 words from the ArrayLis

ID: 3715010 • Letter: B

Question

Building on H11a ;

1. Delete the loop that prints out 10 words from the ArrayList..

2. Get one random word from the ArrayList.

3. Make a guess word consisting of underscores. It should be the same length as the word.

3. Ask your user to guess a character in the word. If it is there put the character in the correct spot in the guess word.

4. If it is not there, that is a strike against the user. (10 strikes and he loses).

5. If the user guesses the word, he wins.

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Random;

public class Tttt {

private final String FILENAME =getClass().getResource("words.txt").getPath(); //file path detection

public static void main(String[] args) {

ArrayList<String> myList=new ArrayList<String>();//initializing array list

Random r=new Random();

Tttt f=new Tttt();

myList=f.getInput();//getting list from getInput() method

int size=myList.size();//getting size of list

System.out.println("First Word is "+myList.get(0));//printing FirstWord of File

System.out.println("Last Word is "+myList.get(size-1));//printing LastWord of File

for(int i=0;i<10;i++){

int rand=r.nextInt(4580);

System.out.println("The position is "+rand+" of "+myList.get(rand));//printing position of random word along with the word

}

}

public ArrayList<String> getInput(){

BufferedReader br = null;

FileReader fr = null;

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

try {

fr = new FileReader(FILENAME);//reading filepath

br = new BufferedReader(fr);//reading object of file

String sCurrentLine;

while ((sCurrentLine = br.readLine()) != null) {

ar.add(sCurrentLine);//reading currentline in file

}

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if (br != null)

br.close();

if (fr != null)

fr.close();

} catch (IOException ex) {

ex.printStackTrace();

}

}

return ar;

}

}

Explanation / Answer

DO you want to the perform the geven tasks on the below program? Be clear. Any how If it is about mitochandria DNA, this file "words.txt" is missing. Difficult to understant the text in the file without actually seeing it.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote