The issue here is the conditionals inside the for loop are not being entered for some reason. Namely if (samp==1){Since all characters should be 0 or 1 one of these two should be entered at all times instead neither of them is being entered and I am not sure what is going on. It should be a simple character comparison. Also I have tested it to see that the ‘samp’variable is correctly sampling the bit sequence one character at a time.
Could really use some help here. I am sure its mind numbingly simple.
//This method will take in a binary bit sequence which should be set up correctly from above
//Then it should print the Unipolar encoding of the waveform
public static void Unipolar(String s){
String code ="";
char samp='9';
char[] charArray = s.toCharArray(); //turn the input bit sequence into a char array for simplicity
String topline=""; //the method I chose was to keep a consistent 3 strings to draw the output
String midline="";
String botline="";
for (int i = 0; i < s.length(); i++) {
samp = charArray[i];
System.out.println(samp);
//depending on if the current character is a 1 or a 0 a differnt pattern will be added to the
//string to be outputted
if (samp==1){
topline+="*****";
midline+="* ";
botline+="* ";
}
if (samp==0){
topline+=" ";
midline+=" ";
botline+="*****";
}
}
System.out.println(topline);
System.out.println(midline);
System.out.println(botline);
}
You should use the character values when comparing
chars: