Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
import java.io.*; import java.util.*; /********************************************************************* * Assignment 3 - COMP2011 Session 1, 2005. * * Don't change this file. * (For Stage 1, the only file you need to edit is State.java) */ public class TestState { /***************************************************************** * Read map of environment from standard input. */ public static char[][] get_initial_map( BufferedReader in ) { ArrayList lineList = new ArrayList(); char initial_map[][]; int r,c; try { String oneLine = in.readLine(); while (( oneLine != null )&&( oneLine.length() > 0 )) { lineList.add( oneLine ); oneLine = in.readLine(); } } catch( IOException e ) { System.out.println( "IO Error" ); } initial_map = new char[lineList.size()][]; for( r=0; r < initial_map.length; r++ ) { initial_map[r] = new char[((String)lineList.get(r)).length()]; for( c=0; c < initial_map[r].length; c++ ) { initial_map[r][c] = ((String) lineList.get(r)).charAt(c); } } return( initial_map ); } /***************************************************************** * Get next instruction from standard input. */ public static int get_instruction( BufferedReader in ) { int ch; try { while( true ) { switch( ch = in.read() ) { case 'L': case 'R': case 'F': case 'C': case 'O': case 'B': case -1: return( ch ); } } } catch( IOException e ) { return( -1 ); } } /***************************************************************** * Apply instructions to environment and print final state. * * Read the initial state of the environment from standard input. * Then call the apply() method for each instruction * 'L','R','F','C','O' or 'B' as it is read from standard input * (note: 'P' and 'I' instructions are ignored). * After all instructions have been read, * print the final state of the environment. */ public static void main( String[] args ) { BufferedReader in; State state; int ch; in = new BufferedReader( new InputStreamReader( System.in )); char[][] initial_map = get_initial_map( in ); state = new State( initial_map ); ch = get_instruction( in ); while( ch != -1 ) { state.apply( ch, initial_map ); ch = get_instruction( in ); } System.out.println( state ); } }