Skip to content

Commit 471dad0

Browse files
committed
Table created
1 parent 05e2967 commit 471dad0

File tree

12 files changed

+75
-16
lines changed

12 files changed

+75
-16
lines changed

bin/Dev.class

-160 Bytes
Binary file not shown.

bin/command/commander.class

3 Bytes
Binary file not shown.

bin/model/Subnetting.class

-68 Bytes
Binary file not shown.

bin/model/VLSM.class

1.58 KB
Binary file not shown.

bin/test/testFake.class

0 Bytes
Binary file not shown.

bin/test/tester.class

-1.22 KB
Binary file not shown.

src/Dev.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ public static void main(String[] args) {
1313
Scanner scn = new Scanner (System.in);
1414
VLSM vlsm = new VLSM();
1515
int k = 1;
16-
System.out.println("##### WELCOME #####");
16+
System.out.println("##### WELCOME TO JDNETTING#####");
1717
String line = scn.nextLine();
1818
String[] parts = line.split("\\s+");
1919

2020
if (!parts[0].equals(null)) {
2121
vlsm.listRedIP.add(parts[0]);
22-
System.out.println("Added IP address");
22+
System.out.println("Red IP added");
2323
}
2424
System.out.println("#### Write the quantity host by subnet ####");
25+
2526
/*
2627
* Quantity host
2728
*/
@@ -31,15 +32,13 @@ public static void main(String[] args) {
3132
vlsm.listQuantityHost.add(qh);
3233
k++;
3334
}
35+
3436
/*
3537
* Sort List
3638
*/
3739
Comparator<Integer> descendingComparator = (a, b) -> b.compareTo(a);
3840
Collections.sort(vlsm.listQuantityHost, descendingComparator);
39-
40-
for (int f=0; f < vlsm.listQuantityHost.size(); f++) {
41-
System.out.println(vlsm.listQuantityHost.get(f));
42-
}
41+
4342
/*
4443
* Prefix and Host Required
4544
*/
@@ -59,6 +58,10 @@ public static void main(String[] args) {
5958
* RED IP
6059
*/
6160
vlsm.FindRedIP();
61+
/*
62+
* Overview O.O
63+
*/
64+
vlsm.Overview();
6265

6366
scn.close();
6467
}

src/command/commander.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
public interface commander {
44
public String CANCEL = "-c";
5-
public String QUANTITY_HOST = "-qh";
5+
public String COMMANDER_VLSM = "-vlsm";
66
public String HELP = "-h";
77
}

src/model/Subnetting.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,4 @@ public abstract class Subnetting {
66
public List<String> listRedIP;
77
public List<String> listSubredMask;
88

9-
public void Overview () {
10-
11-
}
12-
139
}

src/model/VLSM.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void FindSubredMask () {
8686
strBuilder.insert(8, '.');
8787
strBuilder.insert(17, '.');
8888
strBuilder.insert(26, '.');
89-
System.out.println(strBuilder);
9089
String[] splitSubredZeroAndOne = strBuilder.toString().split("\\.");
9190
int firstOctetValue = Integer
9291
.parseInt(splitSubredZeroAndOne[0],2);
@@ -125,4 +124,59 @@ public void FindRedIP () {
125124
}
126125
}
127126

127+
/*
128+
* Table
129+
*/
130+
public void Overview () {
131+
String[][] data = new String[listRedIP.size()+1][6];
132+
data[0] = new String[]{"Subnet","Host","Host Required","Red IP","Prefix","Subred Mask"};
133+
int num=1;
134+
for (int k = 0; k < listRedIP.size(); k++) {
135+
data[k+1][0] = "Subnet "+num++;
136+
data[k+1][1] = listQuantityHost.get(k).toString();
137+
data[k+1][2] = listHostRequired.get(k).toString();
138+
data[k+1][3] = listRedIP.get(k).toString();
139+
data[k+1][4] = listPrefix.get(k).toString();
140+
data[k+1][5] = listSubredMask.get(k).toString();
141+
}
142+
143+
int[] columnWidths = {10,5,13,15,6,15};
144+
printTable(data, columnWidths);
145+
}
146+
147+
private String paddingRight (String cell, int width) {
148+
return String.format("%-"+width+"s",cell);
149+
}
150+
151+
private void printLine (int width) {
152+
for (int i = 0; i < width; i++) {
153+
System.out.print("-");
154+
}
155+
System.out.println();
156+
}
157+
158+
private void printTable (String[][] data, int[] columnWidths) {
159+
int totalWidth = 1;
160+
for (int w : columnWidths) {
161+
totalWidth += w + 3;
162+
}
163+
164+
printLine(totalWidth);
165+
166+
for (int i = 0; i < data.length; i++) {
167+
System.out.print("| ");
168+
for (int j = 0; j < data[i].length; j++) {
169+
String cell = data[i][j];
170+
int width = columnWidths[j];
171+
System.out.print(paddingRight(cell, width)+" | ");
172+
}
173+
System.out.println();
174+
175+
if (i == 0) {
176+
printLine(totalWidth);
177+
}
178+
}
179+
printLine(totalWidth);
180+
}
181+
128182
}

0 commit comments

Comments
 (0)