Conway’s Game of Life Object oriented implementation in Java

I have designed Conway’s Game of Life in Java, the solution follows Object Oriented design and paradigm, please review and let me know the feedback Class Cell Cell has one property alive and behavior to update alive status public class Cell { private boolean alive; public Cell( boolean alive) { this.alive = alive; } public … Read more

Maths test program

I have written this simple program that is a basically a maths test. I would like to know is there any areas I can improve on and if I have any bad habits that would be useful to break now. I realise I could have written this in the main class, but I was trying … Read more

Version comparison function

I have this version comparison function in java. Any cleaner way to write this without all the nested ‘if’ statements? Note that the suggestions must be in Java code only. @Override public int compareTo(Version o) { int result = this.major.compareTo(o.major); if (result == 0) { result = this.minor.compareTo(o.minor); if (result == 0) { result = … Read more

Similar methods using loops

Is it recommended to combine two similar methods into one? public void initialize_board(){ for(int y = 0; y < board.length; y++){ for(int x = 0; x < board.length; x++){ if(x == 0) board[x][y] = (char)y; else board[x][y] = ‘~’; } } } public void display_board(){ for(int y = 0; y < board.length; y++){ for(int x … Read more

Customised Java UTF-16

I have implemented customized encoding mechanism for javaUTF16. Does this implementation support all the characters? public class Encoding { public static void main(String[] args) { byte [] arr = new byte[1000]; String str = “abcde” ; //even this encoding works supplementary characters Encode(arr,0,str); System.out.println(Decode(arr,str.length())); } public static byte[] Encode(byte[] ByteArray , int offset ,String str) … Read more

Cutting it to Pages

I was working on representing a large List of information on a number of different pages, and a colleague of mine suggested that I try to make a generic method for the task I was trying to perform: private <T> List<List<T>> listSplitter(List<T> originalList, int splitCount) { List<List<T>> listOfLists= new ArrayList<>(); listOfLists.add(new ArrayList<>()); int originalListSize = … Read more