Alphard 0 Newbie Poster

import java.util.Scanner;
public class TuringMachine
{
private static char[] array_in;
private static int dir=0;
private static int state=0;
private static int i=0, i_clone;

public static void main(String[] args)
{
Scanner read = new Scanner(System.in);
do
{
System.out.print("Input Number: ");
String str = read.next();
array_in = str.toCharArray();
if(!isNotValid())
halt(0);
else
break;
}
while(true);

while(true)
{
if(i<0)
{
halt(-1);
}
if(i>=array_in.length)
{
halt(2);
}
switch(state)
{
case 0:
switch(array_in)
{
case '0':
array_in='X';
state=1;
dir=1;
break;
case '1':
halt(1);
break;
case 'X':
halt(1);
break;
case 'Y':
array_in='Y';
state=3;
dir=1;
break;
case 'B':
halt(1);
break;
default:
halt(-99);
}
break;
case 1:
switch(array_in)
{
case '0':
array_in='0';
state=1;
dir=1;
break;
case '1':
array_in='Y';
state=2;
dir=-1;
break;
case 'X':
halt(1);
break;
case 'Y':
array_in='Y';
state=1;
dir=1;
break;
case 'B':
halt(1);
break;
default:
halt(-99);
}
break;
case 2:
switch(array_in)
{
case '0':
array_in='0';
state=2;
dir=-1;
break;
case '1':
halt(1);
break;
case 'X':
array_in='X';
state=0;
dir=1;
break;
case 'Y':
array_in='Y';
state=2;
dir=-1;
break;
case 'B':
halt(1);
break;
default:
halt(-99);
}
break;
case 3:
switch(array_in)
{
case '0':
halt(1);
break;
case '1':
halt(1);
break;
case 'X':
halt(1);
break;
case 'Y':
array_in='Y';
state=3;
dir=1;
break;
case 'B':
array_in='B';
state=4;
dir=1;
break;
default:
halt(-99);
}
break;
case 4:
halt(1);
break;
default:
halt(-99);
}
System.out.println("");
System.out.print("\t");
i+=dir;
for(i_clone=0;array_in.length-i_clone>0;i_clone++){
if(i==i_clone){
System.out.print(" q["+state+"] ");
}
System.out.print(" "+array_in[i_clone]+" ");
}
}
}
private static boolean isNotValid()
{
boolean chk=true;

for(int j=0;j<array_in.length;j++)
{
if(array_in[j]!='1'&&array_in[j]!='0')
{
chk=false;
}
}
return chk;
}
private static void halt(int status)
{
switch(status)
{
case -1:
System.out.println("\nInvalid Input\nThe Program will Halt");
System.exit(0);
break;
case 0:
System.out.println("\nInvalid Input..");
break;
case 1:
System.out.println("\nYou Have defined Nothing.. \nProgram will halt..");
System.exit(0);
break;
case 2:
System.out.println(" q["+(state)+"] ");
System.out.println("\reached end..");
System.exit(0);
break;
default:
System.out.println("\nUnknown error.. \nProgram will halt");
System.exit(0);
break;
}
}
}
//guys, this is a simple code that simulates an output for a turing machine.my problem is that, it doesn't show an end and start state.

could someone please help..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.