Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 491f149

Browse files
committed
meaning names clean code
1 parent 9a5ce83 commit 491f149

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/binod/FunctionDemo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ public static void binToDec(int binNum) {
7373
System.out.println(dnum);
7474
}
7575

76+
public static void decToBinary(int decimalNum) {
77+
int binNum = 0;
78+
while (decimalNum > 0) {
79+
int rem = decimalNum % 2;
80+
binNum = (binNum * 10) + rem;
81+
decimalNum = decimalNum / 2;
82+
}
83+
System.out.println(binNum);
84+
}
85+
7686
public static void main(String[] args) {
7787
// Scanner scanner = new Scanner(System.in);
7888
// System.out.println("Enter side of a square");
@@ -87,5 +97,6 @@ public static void main(String[] args) {
8797
// System.out.println(isPrime(12));
8898
// printPrime(10);
8999
binToDec(101);
100+
decToBinary(5);
90101
}
91102
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package binod.meaningful_names;
2+
import java.util.ArrayList;
3+
import java.util.List;
4+
5+
public class GameBoard {
6+
7+
static List<Cell> gameBoard = new ArrayList<Cell>();
8+
9+
public static void main(String[] args) {
10+
List<Cell> list = getFlaggedCells();
11+
System.out.println(list);
12+
}
13+
14+
public static List<Cell> getFlaggedCells() {
15+
List<Cell> flaggedCells = new ArrayList<Cell>();
16+
for (Cell cell : gameBoard)
17+
if (cell.isFlagged())
18+
flaggedCells.add(cell);
19+
return flaggedCells;
20+
}
21+
}
22+
23+
class Cell {
24+
25+
int STATUS_VALUE = 0;
26+
27+
int FLAGGED = 4;
28+
29+
public boolean isFlagged() {
30+
return STATUS_VALUE == FLAGGED;
31+
}
32+
}

0 commit comments

Comments
 (0)