/home/jfernan6/NetBeansProjects/CSX/src/npw/TextRectangles.java |
1
2
3
4
5
6 package npw;
7
8 import java.util.Scanner;
9 import java.util.logging.Level;
10 import java.util.logging.Logger;
11
12
13
14 @author
15
16 public class TextRectangles {
17 boolean running = true;
18
19 static TextRectangles text = new TextRectangles();
20
21
22
23 public void run(){
24
25 Scanner input = new Scanner(System.in);
26
27
28 while (running){
29 System.out.println(" Nuber Of Rows?");
30 int nrOfRows = input.nextInt();
31 System.out.println("Number Of Columns ?");
32 int nrOfColumns = input.nextInt();
33
34 drawRectangle(nrOfRows,nrOfColumns);
35 try {
36 Thread.sleep(5000);
37 } catch (InterruptedException ex) {
38 Logger.getLogger(TextRectangles.class.getName()).log(Level.SEVERE, null, ex);
39 }
40 text.retry(input);
41 }
42 }
43
44 public void retry(Scanner input){
45 System.out.println("if you would like to retry Type YES");
46 System.out.println("or NO if you Want to end the program");
47
48
49 String retryChoice = input.next();
50
51 if(retryChoice.equalsIgnoreCase("YES")){
52 text.run();
53 }
54
55 else if(retryChoice.equalsIgnoreCase("NO")){
56 running = false;
57 System.out.println("Thanks for playing ");
58 }
59
60 else {
61 System.out.println("Invalid Command");
62 text.retry(input);
63 }
64 }
65 public void drawRectangle(int nrOfRows, int nrOfColumns){
66 int i = 1 ;
67 while (i <= nrOfRows){
68 drawOneRow(nrOfColumns);
69 System.out.println("*");
70 i++;
71 }
72 }
73 public void drawOneRow(int nrOfColumns) {
74
75 int x = 2;
76 while(x <= nrOfColumns){
77 System.out.print("*");
78 x++;
79 }
80 }
81
82 @param args
83
84 public static void main(String[] args) {
85 text.run();
86
87 }
88
89 }