Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ZipCode
  4. {
  5. public static int checkDigit(int zip)
  6. {
  7. int remaining = zip;
  8. int sum = 0;
  9. while (remaining > 0) {
  10. sum += remaining % 10;
  11. remaining /= 10;
  12. }
  13. return 10 - (sum % 10);
  14. }
  15.  
  16. public static String digitToBarCode(int digit) {
  17. if (digit == 1)
  18. {
  19. return ":::||";
  20. }
  21. if (digit == 2)
  22. {
  23. return "::|:|";
  24. }
  25. if (digit == 3)
  26. {
  27. return "::||:";
  28. }
  29. if (digit == 4)
  30. {
  31. return ":|::|";
  32. }
  33. if (digit == 5)
  34. {
  35. return ":|:|:";
  36. }
  37. if (digit == 6)
  38. {
  39. return ":||::";
  40. }
  41. if (digit == 7)
  42. {
  43. return "|:::|";
  44. }
  45. if (digit == 8)
  46. {
  47. return "|::|:";
  48. }
  49. if (digit == 9)
  50. {
  51. return "|:|::";
  52. }
  53. if (digit == 0)
  54. {
  55. return "||:::";
  56. }
  57. return "";
  58.  
  59. }
  60.  
  61. }
  62.  
  63. import java.util.Scanner;
  64.  
  65. public class ZipCodeConverter
  66. {
  67. public static void main(String[] args)
  68. {
  69. Scanner input = new Scanner(System.in);
  70. System.out.print("Enter a zip code: ");
  71. int zip = input.nextInt();
  72. int checkDigit = checkDigit(zip);
  73. String digitPrint=digitToBarCode(checkDigit);
  74.  
  75. int specificNum1=(int)((zip / Math.pow(10, 5-1)) % 10);
  76. String swag1=digitToBarCode(specificNum1);
  77.  
  78.  
  79. int specificNum2=(int)((zip / Math.pow(10, 4-1)) % 10);
  80. String swag2=digitToBarCode(specificNum2);
  81.  
  82.  
  83. int specificNum3=(int)((zip / Math.pow(10, 3-1)) % 10);
  84. String swag3=digitToBarCode(specificNum3);
  85.  
  86.  
  87. int specificNum4=(int)((zip / Math.pow(10, 2-1)) % 10);
  88. String swag4=digitToBarCode(specificNum4);
  89.  
  90.  
  91. int specificNum5=(int)((zip / Math.pow(10, 1-1)) % 10);
  92. String swag5=digitToBarCode(specificNum5);
  93.  
  94. String y=swag1+swag2+swag3+swag4+swag5;
  95.  
  96.  
  97. System.out.println("|"+y+digitPrint+"|");
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement