Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kodut3;
- public class FormatMachine {
- final int INI = 0;//algstage
- final int CH = 1;// eelmine oli täht
- final int KM = 2;// eelmine oli kirjavahemärk või sulgev sulg
- final int AS = 3;// eelmine oli avav sulg
- final int T = 4; //kui eelmine oli tühik
- char[] margid ={',', ':',';','.','!','?'};
- int state = INI;
- public void checker(char c){
- if (c == '\n') state= INI;
- if (c == ' ') state= T;
- if (c=='(') state = AS;
- if (Character.isLetter(c)) state=CH;
- boolean contains = false;
- for (char e : margid) {
- if (e == c) {
- contains = true;
- break;
- }
- }
- if (contains) {
- state=KM;
- }
- }
- public String process(char c) {
- switch (state) {
- case INI:
- checker(c);
- switch(state){
- case T:
- //ei tagasta midagi
- break;
- case AS:
- case KM:
- case CH:
- case INI:
- }
- break;
- case CH:
- checker(c);
- switch(state){
- case AS:
- //tagastame tühik+c
- break;
- case KM:
- case CH:
- case INI:
- case T:
- }
- break;
- case KM:
- checker(c);
- switch(state){
- case CH://tagastame tühik+c
- break;
- case KM:
- case AS:
- case INI:
- case T:
- }
- break;
- case AS:
- checker(c);
- switch(state){
- case T://ei tagasta midagi
- break;
- case KM:
- case AS:
- case INI:
- case CH:
- }
- break;
- case T:
- checker(c);
- switch(state){
- case T:
- break;
- case KM:
- case AS:
- case INI:
- case CH:
- }
- break;
- }
- return ""+c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement