Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

In this assignment, we’re going to create our own Mad Libs with the assistance of Java and Array Lists. Program requirements: •Create a new class called MadLib.java •Your program should print a Mad...

1 answer below »

In this assignment, we’re going to create our own Mad Libs with the assistance of Java and Array Lists.

Program requirements:

•Create a new class called MadLib.java

•Your program should print a Mad Lib of your choosing. (You can use an existing one or create your own). The Mad Lib should have a minimum of 15 empty spots to fill

•For each empty spot, your program should pull a random word from an Array List. Create an Array List for the following. (This is at a minimum. Feel free to add more categories as needed.):oNounsoVerbsoAdjectivesoNamesoPlaces

•Each Array List should have a minimum of 15 entries to pick from. These entries should be read from an external file and placed in the Array List at runtime. You will have one external file for each category (e.g.,nouns.txt, verbs.txt, etc.)

•Each spot should be filled with a randomly selected item from the appropriate list. For example, if the spot needs a “noun,” pull an item from the Nouns Array List. If the word chosen was used in a previous spot, discard this word and pick another (hint: use the Math. random() and Array List contains() functions for this)Include appropriate comments throughout your code. Remember to use standard Java naming conventions. Put your name and information about the program at the beginning of your program. Submit your MadLib.java, MadLib.class, and a screenshot of it in operation on your computer. Package all of these in a zip file and name the submission in the format:NAME_COURSE_ASSIGNMENT_DATE.zip Submission is due by 11:59 p.m. ET.

For all assignments and exercises, submissions should be done as a packaged zip file that contains the following: all .java and .class files from your project and a screenshot of the code operating on your computer. You can save this image as a .jpg or .png. Name the zip file submission in the format:
NAME_COURSE_ASSIGNMENT_DATE.zip

Answered 4 days After Sep 13, 2021

Solution

Arun Shankar answered on Sep 18 2021
149 Votes
import java.util.A
ayList;
import java.util.Scanner;
import java.io.*;
import java.util.Random;
public class MadLib {
    /* This function returns a random word
     * from an a
aylist.
     *
    public static String get_word(A
ayList a
li)
    {
        Random rand = new Random();
        int index = rand.nextInt(a
li.size());
        String word = a
li.get(index);
        
        
Now, pop the word from the a
ay list
        
so that this won't show up again
        
        a
li.remove(index);
        return word;
    }
    
    /* This function populates an a
ay list with
     * the words from the file whose name it receives as
     * the first argument. The second argument is the a
ay list.
     *
    public static void populate_list(String fileName, A
ayList a
li)
    {
        try
        {
            FileInputStream fis = new FileInputStream(fileName);
            Scanner sc = new Scanner(fis);
            while(sc.hasNextLine()) ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here