Question
Use this format below to write the new program in java, please. The program needs to be changed to and input settle, asset, least, stale,
Use this format below to write the new program in java, please. The program needs to be changed to and input settle, asset, least, stale, and late. Below is an example of how this program should be written.
// Finite State Machine // Counts the number of occurrences of 4 words: // pancake, peek, cake, keep
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException;
public class NewFSM {
private static final int cakeACCEPT = 14; private static final int pancakeACCEPT = 7; private static final int keepACCEPT = 18; private static final int peekACCEPT = 10;
// P A N C K E ? private static final int[][] STATE_TABLE = { {1, 0, 0, 11, 15, 0, 0}, // state 0 {1, 2, 0, 11, 15, 8, 0}, // state 1: p {1, 0, 3, 11, 15, 0, 0}, // state 2: pa {1, 0, 0, 4, 15, 0, 0}, // state 3: pan {1, 5, 0, 11, 15, 0, 0}, // state 4: panc {1, 0, 0, 11, 6, 0, 0}, // state 5: panca {1, 0, 0, 11, 15, 7, 0}, // state 6: pancak {1, 0, 0, 11, 15, 17, 0}, // state 7: pancake {1, 0, 0, 11, 15, 9, 0},// state 8: pe {1, 0, 0, 11, 10, 0, 0}, // state 9: pee {1, 0, 0, 11, 15, 16, 0}, // state 10: peek {1, 12, 0, 11, 15,0, 0}, // state 11: c {1, 0, 0, 11, 13, 0, 0}, // state 12: ca {1, 0, 0, 11, 15, 14, 0}, // state 13: cak {1, 0, 0, 11, 15, 17, 0}, // state 14: cake {1, 0, 0, 11, 15, 16, 0}, // state 15:k {1, 0, 0, 11, 15, 17, 0}, // state 16: ke {18, 0, 0, 11, 15, 0, 0}, // state 17: kee {1, 2, 0, 11, 15, 8, 0} // state 18: keep };
private BufferedReader in; private int pancakeCount; private int cakeCount; private int peekCount; private int keepCount;
public NewFSM(String filename) throws IOException { in = new BufferedReader( new FileReader(filename)); cakeCount = 0; pancakeCount = 0; peekCount = 0; keepCount = 0; }
public void run() throws IOException { char ch; int unicode; int state = 0;
unicode = in.read(); while (unicode != -1) { ch = (char) unicode; state = STATE_TABLE[state][charToColumn(ch)]; if (state == cakeACCEPT) { cakeCount++; } if (state == pancakeACCEPT) { pancakeCount++; cakeCount++; } if (state == peekACCEPT) peekCount++; if (state == keepACCEPT) keepCount++; unicode = in.read(); } System.out.println( "Occurrence counts: "); System.out.println( "pancake count is " + pancakeCount); System.out.println( "cake count is " + cakeCount); System.out.println( "keep count is " + keepCount); System.out.println( "peek count is " + peekCount); }
public int charToColumn(char ch) { if (ch == 'P' || ch == 'p') return 0; if (ch == 'A' || ch == 'a') return 1; if (ch == 'N' || ch == 'n') return 2; if (ch == 'C' || ch == 'c') return 3; if (ch == 'K' || ch == 'k') return 4; if (ch == 'E' || ch == 'e') return 5; return 6; }
public static void main(String[] args) { if (args.length Program 2 - Counting Occurrences of Words settle 2. asset 3. least 4. stale 5. late Sample with program shown from class (your program should follow this model): PancakeepeekeEPancakpepepeek kepepeekepeekancakee panpcakeepeekeepke Fourscoreandsevenpanpanpancakepanwwkww keepeekpancakeepancakeePcakeep keepancakecakEEPPEREPePE keerpan_cake_panncakekekeepeekeepeekeepeeek parka
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started