You are on page 1of 8

/*-----------------------------------------------------------------------*/ Source Code: /*------------------------------------------------------------------------*/

i m p ort Shape; imp ort ShapeExcept ion; p u blic class ShapeCol lect ion { private static f inal Shape CLEAR , GLIDER , S ALLE!"L, E!"L# DER ; private static f inal Shape CELL$% , &IS' , "( " , S' # #)ER , C #LLEC)I#* ; int i+%; int ,+i-$; for. i+%; i+$; i- -/ { for. ,+$; ,+0; ,- -/ { static { CLEAR + ne 1 Shape. 2Clear2,ne 1 int3 4 3 4 / ; GLIDER + ne 1 Shape. 2Gl i5er2,ne 1 int3 i 4 3 , 4 / ; S ALLE!"L + ne 1 Shape. 2S mal l Explo5er2,ne 1 int3 i 4 3 , 4 / ; E!"L# DER + ne 1 Shape. 2Explo5er2,ne 1 int3 i 4 3 , 4 / ; CELL$% + ne 1 Shape. 2$% Cel l Ro 12, ne 1 int3 i 4 3 i 4 / ; &IS' + ne 1 Shape. 2L i6ht1ei6ht spaceship2,ne 1 int3 i 4 3 , 4 / ; "( " + ne 1 Shape. 2)u m bler2,ne 1 int3 i 4 3 , 4 / ; S ' # #)ER + ne 1 Shape. 2Gosper Gli5er G un2,ne 1 int3 i 4 3 , 4 / ; C #LLEC)I#* + ne 1 Shape3 4 { CLEAR ,GLIDER , S ALLE!"L,E!"L# DER ,CELL$% ,&IS' , "( " ,S' # #)ER 7; 7 7 7 p u blic static Shape3 4 6etShapes./ { return C #LLEC)I#* ; 7 p u blic static Shape 6etShape89*a m e. Str in6 na m e / thro 1s ShapeExcept ion { Shape3 4 shapes + 6etShapes. / ; for . int i+ %; i: shapes; len6th; i-- / { i f . shapes3 i 4 ;6et*a m e./ ;e<uals. na m e / / return shapes3 i 4 ; 7 thro 1 . ne 1 ShapeException. 2(n=no 1n shape> 2- na m e/ / ; 7

?@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@?

Straight Code Output: class Sample { static int TX_RATE = 20; static int MN_RATE = 10; static int OK_RATE =5; public static !i" main#St$in% a$% &'( { St$in% $esi"ence=)TEXAS); *l!at am!unt=0; "!uble calc=0; int p!ints=0; int $ate=1+base=1+e,t$amnt=1+basisamt=1; i*#$esi"ence-e.uals#)TEXAS)(( { $ate = TX_RATE; am!unt = base/TX_RATE; calc = 2/basisamt0e,t$amnt/1-05; 1 else i*#$esi"ence-e.uals#)OK2A3OMA)( 44 $esi"ence-e.uals#)MA5NE)(( { $ate = $esi"ence-e.uals#)OK2A3OMA)(6OK_RATE7MN_RATE; am!unt = base/$ate; calc = 2/basisamt0e,t$amnt/1-05; i*#$esi"ence-e.uals#)OK2A3OMA)((

{ p!ints=2; 1 1 else { $ate=1; am!unt=base; calc=2/basisamt0e,t$amnt/1-05; 1 1 1

Re factored Code Output: class Sample { static int TX_RATE = 20; static int MN_RATE = 10; static int OK_RATE =5; public static !i" main#St$in% a$% &'( { St$in% $esi"ence=)OK2A3OMA); *l!at am!unt=0; "!uble calc=0;

int p!ints=0; int $ate=1+base=1+e,t$amnt=1+basisamt=1; i*#$esi"ence-e.uals#)TEXAS)(( { $ate = TX_RATE; am!unt = base/TX_RATE; calc = 2/basisamt0e,t$amnt/1-05; 1 else i*#$esi"ence-e.uals#)OK2A3OMA)( 44 $esi"ence-e.uals#)MA5NE)(( { $ate = $esi"ence-e.uals#)OK2A3OMA)(6OK_RATE7MN_RATE; am!unt = base/$ate; calc = 2/basisamt0e,t$amnt/1-05; i*#$esi"ence-e.uals#)OK2A3OMA)(( { p!ints=2; 1 else { p!ints=100; 1 1 else { $ate=1;

am!unt=base; calc=2/basisamt0e,t$amnt/1-05; 1 1 1

Game of Life:

/*-------------------------Re factored Source Code--------------------------------*/


i m p ort Shape; imp ort ShapeExcept ion; p u blic class ShapeCol lect ion { private static f inal Shape CLEAR , GLIDER , S ALLE!"L, E!"L# DER ; private static f inal Shape CELL$% , &IS' , "( " , S' # #)ER , C #LLEC)I#* ; int i+%; int ,+i-$; for. i+%; i+$; i- -/ { for. ,+$; ,+0; ,- -/ { static { CLEAR + ne 1 Shape. 2Clear2,ne 1 int3 4 3 4 / ; GLIDER + ne 1 Shape. 2Gl i5er2,ne 1 int3 i 4 3 , 4 / ; S ALLE!"L + ne 1 Shape. 2S mal l Explo5er2,ne 1 int3 i 4 3 , 4 / ; E!"L# DER + ne 1 Shape. 2Explo5er2,ne 1 int3 i 4 3 , 4 / ; CELL$% + ne 1 Shape. 2$% Cel l Ro 12, ne 1 int3 i 4 3 i 4 / ; &IS' + ne 1 Shape. 2L i6ht1ei6ht spaceship2,ne 1 int3 i 4 3 , 4 / ; "( " + ne 1 Shape. 2)u m bler2,ne 1 int3 i 4 3 , 4 / ; S ' # #)ER + ne 1 Shape. 2Gosper Gli5er G un2,ne 1 int3 i 4 3 , 4 / ; C #LLEC)I#* + ne 1 Shape3 4 { CLEAR ,GLIDER , S ALLE!"L,E!"L# DER ,CELL$% ,&IS' , "( " ,S' # #)ER 7; 7 7 7 p u blic static Shape3 4 6etShapes./ { return C #LLEC)I#* ; 7 p u blic static Shape 6etShape89*a m e. Str in6 na m e / thro 1s ShapeExcept ion { Shape3 4 shapes + 6etShapes. / ; for . int i+ %; i: shapes; len6th; i-- / { i f . shapes3 i 4 ;6et*a m e./ ;e<uals. na m e / / return shapes3 i 4 ; 7 thro 1 . ne 1 ShapeException. 2(n=no 1n shape> 2- na m e/ / ; 7

You might also like