Using this snippet........ import java.nio.file.Files; import java.nio.file.Path
ID: 3755909 • Letter: U
Question
Using this snippet........
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class Main {
public static void main(String[] args) {
Path p = Paths.get(args[0]);
List allLines = null;
try {
allLines = Files.readAllLines(p);
}
catch (Exception e) {
System.out.print("File IO issue");
System.exit(1);
}
for (String line : allLines) {
String[] lineParts = line.split(" ");
int startState = Integer.parseInt(lineParts[0]);
char transitionCharacter = lineParts[1].charAt(0);
int endState = Integer.parseInt(lineParts[2]);
System.out.printf("I read a transition from state %d to %d based on a character of %c ",
startState,endState,transitionCharacter);
}
}
}
The program must be called "validator" and take 2 command line parameters a state machine filename, then a filename of inputs to validate. For example: validator myStateMachine.txt mylnputs.txt State Machine: The state machine will come from a text file in the following space delimited format: umber For example: 0 A1 0 a 1 1 B 2 1 b 2 2 C 999 There are three terminal situations: 999 success- when this state is reached, print "Success" and end. failure (no transitions match) print "Failure at position found character_." failure (input string ends early) - print "Input string ended before success transition." Note - each state can have ANY NUMBER (1 or more) of transitions to other states. The transitions do not have to happen in any specific order (for example-state 1 could transition forwards to state 4 and state 5 could transition backward to state 2). States will be sorted in the text file (0,1,2,3,4, etc.). Input File: The inputs to validate is some number (1 or more) of lines of text. Example: abcExplanation / Answer
#include #include using namespace std; int main() { int a; couta; while(1) { if(cin.fail()) { cin.clear(); cin.ignore(numeric_limits::max(),’ ’); coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.