//---------------------------------------------------------- //Import of the Scanner class allows the user to enter input //---------------------------------------------------------- import java.util.Scanner; public class BCD { //----------------------------------------------------------- // converts the user inputed strings of decimal digits into // Binary Coded decimal (BCD) strings. //----------------------------------------------------------- public static void main(String args[]) { final Scanner SC = new Scanner(System.in);//scanner class is declared and instantiated String input;//declared for user inputs through the scanner class String output;//storage for calculated input which is displayed to the user int i;//int storage int last;//int storage for the last character entered in the BCD int total;//int storage for the total 0s and 1s for each run in the BCD //-------------------------------------------------------------------------------- //Print line explains the conversion process and gives the user prompts to follow //-------------------------------------------------------------------------------- System.out.println("Welcome to the conversion program!"); System.out.println("it performs coversions on integer decimal numbers \n" + "which are at least zero."); System.out.println("When asked what to do next, please enter: \n" + "'toBCD' to convert to Binary Coded Decimal (BCD). \n" + "'toRLE' to covert to BCD and also Run Length Encoded (RLE)BCD."); System.out.println("Anything else to stop the program."); while(true)//evaluates the boolean condition repititively until false { System.out.println("What do you want to do next?");//prompts user to interact input = SC.next();//Scanner class method read from the keyboard via user input. //---------------------------------------------------------------------------- //Evaluates the statement, which if true, prompts the user to enter an integer //---------------------------------------------------------------------------- if(input.equals("toBCD")) { System.out.println("Please enter the number to be converted."); input = SC.next(); //-------------------------------------------------------------------- //processes the users input, and if true format, produces the output, //otherwise it 'catches' the exception and displays the error. //-------------------------------------------------------------------- try { //-------------------------------------------------------- //returns the int corresponding to the value stored in the //specified string, in this case, the input string. //-------------------------------------------------------- Integer.parseInt(input); output = "";//assigns a value for the variable output to recognise for(i=0; i