Homework Solution: This is an exercise in using the LinkedList class….

    Help in JAVA: This is an exercise in using the LinkedList class. Using input file words.txt create a LinkedList BUT you must NOT add a word that is already in the list and you MUST add them in the order received to the end of the list. For example, if your input was cat, cat, dog, mouse, dog, horse your list would now contain cat, dog, mouse, horse. And the head of the list would be cat, and the tail would be horse. Note: it is NOT sorted. This list represents a code, and the code for one word is the next word in the list. So the code for cat is dog and the code for mouse is horse, and the code for horse is cat(go round to the head of the list). Now ask your user for a phrase (input from the keyboard) and output the coded phrase. In the above example if the input was "mouse cat" the output would be "horse dog". -I suggest you make your own (small) input file so you can test it. words.txt: noncollectable reallocation drenching obnoxious venality dybbuk shotgun changelessly handiwork unheralded dovecote anode spellbind psychologist improvisational prejudiced apply pokey secular masterfully at overdrawn costar scruff awareness impurely tuft minstrelsy calcimine

    Expert Answer

     
    //*********Program Plan********* //Add each element of the word.txt in LinkedList if it does not exist.To fin

    Help in JAVA:

    This is an training in using the LinkedRegister systematize.

    Using input finish say.txt produce a LinkedRegister BUT you must NOT supplement a account that is already in the register and you MUST supplement them in the enjoin current to the purpose of the register.

    Control specimen, if your input was cat, cat, dog, mouse, dog, charger

    your register would now comprise cat, dog, mouse, charger. And the section of the register would be cat, and the retainer would be charger. Referablee: it is NOT exclusive.

    This register represents a mode, and the mode control individual account is the direct account in the register. So the mode control cat is dog and the mode control mouse is charger, and the mode control charger is cat(go globular to the section of the register).

    Now beseech your user control a characteristic (input from the keyboard) and quenchedput the moded characteristic. In the balancehead specimen if the input was “mouse cat” the quenchedput would be “charger dog”.

    -I insinuate you effect your acknowledge (small) input finish so you can trial it.

    words.txt:

    noncollectable
    reallocation
    drenching
    obnoxious
    venality
    dybbuk
    shotgun
    changelessly
    handiwork
    unheralded
    dovecote
    anode
    spellbind
    psychologist
    improvisational
    prejudiced
    apply
    pokey
    secular
    masterfully
    at
    overdrawn
    costar
    scruff
    awareness
    impurely
    tuft
    minstrelsy
    calcimine

    Expert Tally

     

    //*********Program Plan*********

    //Supplement each component of the account.txt in LinkedRegister if it does referable be.To meet the mode account , meet the apostacy of characteristic in //linked register and meet the direct component of the apostacy

    //*************Code****************

    import java.io.BufferedReader;

    import java.io.FileInputStream;

    import java.io.FileNotFoundException;

    import java.io.IOException;

    import java.io.InputStreamReader;

    import java.util.LinkedList;

    public systematize ModeCharacteristic {

    public static empty main(String[] args) {

    // commend accountLinkedRegister to garner the say

    LinkedList<String> accountLinkedRegister = fantastic LinkedList<String>();

    // commend and initialize the modedPhraes to garner the quenchedput

    String modedCharacteristic = “”;

    // commend characteristic string wavering to recognize the input penetrateed

    String characteristic;

    // balancecome part recognizeWordTextFinish which recognize finish and retreasure LinkedList

    // garner the linkedregister retreasure from part balancecome recognizeWordTextFile()

    wordLinkedRegister = recognizeWordTextFile();

    System.out.println(“Please penetrate a characteristic”);

    try {

    // buffer recognizeer to recognize input

    BufferedReader bufferedReader = fantastic BufferedReader(fantastic InputStreamReader(System.in));

    // recognize undiminished characteristic in individual succession and garner into characteristic

    characteristic = bufferedReader.readLine();

    // commend and initlise the cleaveedCharacteristic draw-up to garner the each account of characteristic

    String[] cleaveedPhrases = characteristic.trim().split(” “);

    // control loop to recapitulate balance full the account of the penetrateed characteristic

    control (int i = 0; i < cleaveedPhrases.length; i++) {

    // meet apostacy of account in accountLinkedList

    int apostacy = accountLinkedList.indexOf(splitedPhrases[i].trim());

    // apostacy =-1 moderation account does referable bes in account LinkedList

    if (apostacy != -1) {

    // obstruct if the account is referable ultimate component of the accountLinkedList

    if (apostacy != accountLinkedList.size() – 1)

    // then mode account control this account is direct component(i+1);

    codedCharacteristic = modedCharacteristic + accountLinkedList.get(apostacy + 1);

    else

    // if the account is ultimate component of the accountLinkedList

    // then supplement the primeval component as its mode account

    codedCharacteristic = modedCharacteristic + accountLinkedList.get(0);

    // seprate the moded account by a space

    if (i < cleaveedPhrases.protraction – 1)

    codedCharacteristic = modedCharacteristic + ” “;

    }

    }

    System.out.println(“nCoded characteristic is: “);

    System.out.println(codedPhrase);

    } clutch (IOException e) {

    // clutch the exception

    e.printStackTrace();

    }

    }

    // part to recognize the account.txt finish

    public static LinkedList<String> recognizeWordTextFile() {

    // commend accountLinkedRegister to garner the say

    // which is to be retreasure by this part to its balancecomeer

    LinkedList<String> accountLinkedRegister = fantastic LinkedList<String>();

    try {

    // Open the finish

    FileInputStream fstream = fantastic FinishInputStream(“words.txt”);

    BufferedReader br = fantastic BufferedReader(fantastic InputStreamReader(fstream));

    // commend account

    String account;

    // Recognize Finish Succession By Succession

    while ((account = br.readLine()) != trifling) {

    // if account does referable be in the accountLinkedList

    // then supplement the account in the accountLinkedList

    if (isWordExist(wordLinkedList, account) == sham)

    wordLinkedList.add(word);

    }

    // Delay the input stream

    br.close();

    } clutch (FileNotFoundException e) {

    // TODO Auto-generated clutch block

    e.printStackTrace();

    } clutch (IOException e) {

    // TODO Auto-generated clutch block

    e.printStackTrace();

    }

    // retreasure the accountLinkedRegister and departure from the part

    retreasure accountLinkedList;

    }

    // part to obstruct if the account exisit in linkedlist

    public static boolean isWordExist(LinkedRegister linkedList, String account) {

    // if account bes in linkedregister then retreasure penny else retreasure sham

    if (linkedList.contains(word))

    retreasure penny;

    else

    retreasure sham;

    }

    }

    //*****************Input/Output Screenshot**********

    //word.txt

    cat
    cat
    dog
    mouse
    dog
    horse
    deer
    elephant
    deer
    mouse
    monkey

    //*****Output****

    Please penetrate a characteristic
    dog charger elephant monkey

    Coded characteristic is:
    mouse deer monkey cat