# Party Bits problem

• October 10th, 2013, 06:11 PM
frodooftheshire
Party Bits problem
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
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; }     }```
• October 10th, 2013, 06:15 PM
Junky
Re: Party Bits problem
Nowhere in your code do I see a print statement.
• October 10th, 2013, 07:03 PM
frodooftheshire
Re: Party Bits problem
It has a driver class that out puts the info
Code :

```public class parityFun { public static void main(String[]args) { message parity = new message("1111111"); message parity2 = new message("1111110");   System.out.println("Original Message: "+ parity);   parity.sendWithEvenParity(); parity.getParity(); System.out.println("\tWith even Parity: " + parity);     parity.sendWithOddParity(); parity.getParity(); System.out.println("\tWith odd Parity: " + parity);   System.out.println("Original Message: "+ parity2);   parity2.sendWithEvenParity(); parity2.getParity(); System.out.println("\tWith even Parity: " + parity2);   parity2.sendWithOddParity(); parity2.getParity(); System.out.println("\tWith odd Parity: " + parity2);   } }```
• October 10th, 2013, 07:23 PM
Junky
Re: Party Bits problem
So the error occurs in the code you didn't originally post! Do you think posting relevant information would make it easier for us to help you?

When you want to do one thing or another what kind of statement would you use?
• October 10th, 2013, 08:26 PM
frodooftheshire
Re: Party Bits problem
Well I assumed my error occurred in the other class not the driver class. I would use an if-else statement if I wanted to do one thing or another
• October 10th, 2013, 08:50 PM
Junky
Re: Party Bits problem
What happened when you tried?
• October 11th, 2013, 11:49 AM
frodooftheshire
Re: Party Bits problem
Original Message: 1111111
With even Parity: 11111111
With odd Parity: 111111110
Original Message: 1111110
With even Parity: 11111101
With odd Parity: 111111010

that is what happened the first output is correct but all others thereafter are incorrect I'm not sure why this is.