Alright So I am working on the first problem of this assignment and I have hit a road block. When my answer prints out it puts both a 1 and a 0 on and I only want it to do wone or the other depending on whether or not the number of ones is even or odd.
This is my code
public class message { private String parity1; private int countOfOnes; public message(String Parity1) { parity1 = Parity1; int countOfOnes; } public String getParity() { return parity1; } public void setParity(String Parity1) { parity1 = Parity1; } public int countOnes() { String abc = parity1; int countOfOnes = abc.length()-abc.replaceAll("1","").length(); return countOfOnes; } public String sendWithEvenParity() { if(countOfOnes %2 == 0) { parity1 = parity1 + "1"; } else { parity1 = parity1 + "0"; } return parity1; } public String sendWithOddParity() { if(countOfOnes%2 == 0 ) { parity1 = parity1 + "0"; } else { if(countOfOnes%2 == 1 ) parity1 = parity1 + "1"; } return parity1; } public String toString() { return parity1; } }