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.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class H11A {

public static void main(String[] args) { ArrayList ArrayList = getInput(); System.out.println("First Word in the ArrayList: "+ ArrayList.get(0));//first word in the ArrayList System.out.println("Last Word in the ArrayList: "+ ArrayList.get( ArrayList.size()-1));//last word in the ArrayList System.out.println(); Random r = new Random(); int low = 0; int high = 4580; for (int i=0;i<10;i++) { int randomNum = r.nextInt(high - low) + low; System.out.println("The position " + randomNum + " is " + ArrayList.get(randomNum)); } } public static ArrayList getInput() { Scanner sacnnerRead = null; //Scanner that can Read try { File file = new File("words.txt"); //creat file object based on the file name "words.txt" if (file.exists()) { //check if file exist or not ArrayList wordList = new ArrayList(); //ArrayList of String sacnnerRead = new Scanner(file);//Scanner Read object based on file object while (sacnnerRead.hasNextLine()) { //Iterating each line in the File wordList.add(sacnnerRead.nextLine().trim()); } return wordList;//retirning arraylist } else { System.out.println("The input File is " + "" + "not found"); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (sacnnerRead != null) { try { sacnnerRead.close(); } catch (Exception e) { e.printStackTrace(); } } } return null; } }

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

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

LO3 Name the seven categories of HR functions.

Answered: 1 week ago