Hemendra/lights/TextInterface

From ggc

Jump to: navigation, search

01 package Hemendra.lights;
02 
03 import java.util.*;
04 import wiki.Wiki;
05 /**
06  * All about my application here.
07  @author Hemendra Pullay  
08  */
09 public class TextInterface
10 {
11   public static void main(String[] args)
12   {
13     LightsOutModel model;
14     model=new LightsOutModel();
15     while(model.won()==false)
16     {
17       Wiki.out.println("Board:");
18       Wiki.out.println(model);
19       Wiki.out.println("What row would you like to play (0-4)?");
20       Scanner scanner=new Scanner(Wiki.in);
21       String number=scanner.next();
22       int row=-1;
23       try
24       {
25         row=Integer.parseInt(number);
26       }
27       catch(NumberFormatException nfe)
28       {
29         Wiki.out.println("Not a number: "+number);
30       }
31       Wiki.out.println("What column would you like to play (0-4)?");
32       number=scanner.next();
33       int column=Integer.parseInt(number);
34       if(row>=&& row <=&& column>=&& column<=4)
35       {
36         model.play(row, column);
37       }
38       else
39       {
40         if(row<0)
41         {
42           Wiki.out.println("Row must be 0 to 4 inclusive (not negative).");
43         }
44         if(column<0)
45         {
46           Wiki.out.println("Column must be 0 to 4 inclusive (not negative).");
47         }
48         if(row>4)
49         {
50           Wiki.out.println("Row must be 0 to 4 inclusive (no larger than 4).");
51         }
52         if(column>4)
53         {
54           Wiki.out.println("Column must be 0 to 4 inclusive (no larger than 4).");
55         }
56       }
57     }
58     Wiki.out.println("Congratulations, you won!");
59   }
60 }


Download/View Hemendra/lights/TextInterface.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter