Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Building on H11a ; 1. Delete the loop that prints out 10 words from the ArrayList.. 2. Get one random word from the ArrayList. 3.

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 myList=new ArrayList();//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 getInput(){

BufferedReader br = null;

FileReader fr = null;

ArrayList ar=new ArrayList();

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;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago