hey there, I trying to do a automata program which is about an online shop. the basic usage of the online shop is for the customer to search, add items to shopping basket,view basket and then order and pay.

ab : add to basket
vb : view basket
op : order and pay
se: search

I want to make this program:

1) possible to search without then adding an item from the search to the basket
2)possible to search partway through run, for example after adding an item to the shopping basket.
3) possible to add multiple items from a search to the basket(only one at a time)

However it is not possible to order and pay without first placing at least one item

regular expression = (ab+s)* (vb)(op)
Java Code:
	v|      vb              op
	0 ---------->  0 ------->1   

I was given a code to modify according to the properties above

most modification was done in the switch statement
Java Code:
import java.io.*;
/* import java.util.*; */

class shop

This is a Scanner for the basic online shop,
see DCS103 CW1 (2008) 

ab : add to basket
vb : view basket
op : order and pay
se: search

static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static int state=0;
static String s;
static String overall = "";

public static boolean eq(String a, String b)
int i=0;
if (a.length() != b.length()) {return false;};
while (i<a.length())
  { if (a.charAt(i) != b.charAt(i)) {return false;};
return true;

public static boolean acc() throws IOException

System.out.print("state =" + state);
System.out.println(", input a symbol or empty");
overall = overall +", "+ s;

switch (state) {

      case 0 : if (eq(s,"")) {return true;};  /* final state */
               if (eq(s,"ab")) {state=1;return(acc());};
               if (eq(s,"se")) {state=1;return(acc());};
               return false;  /* if we get here, it's bad */

      case 1 : if (eq(s,"")) {return false;};  /* not final state */
               if (eq(s,"ab")) {state=1;return(acc());};
               if (eq(s,"se")) {state=1;return(acc());};
               if (eq(s,"vb")) {state=1; return(acc());};
               if (eq(s,"op")) {state=0; return(acc());};
               return false;  /* if we get here, it's bad */
          }; /* end case */

return true; /* We never get here, but the Java compiler made me 
                put a return statement in nonetheless */ }

public static void main(String[] args) throws IOException
System.out.println("This is the scanner for the original online shop."); 
System.out.println("Input one symbol at a time, empty line to end input string"); 
System.out.println("Symbols: ab, vb, op, se"); 
if (acc()) {
System.out.println("Yes, accepted sequence is"); }
else {System.out.println("No, rejected sequence is");};


I need to know whether this is correct.

I tried all the strings like

ab s vb op
ab ab v op
s ab vb op

they are all accepted. but I'm not what I modified is correct. basically Im not sure about the code.