Guest User

Untitled

a guest
Feb 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1.  
  2. import static java.lang.System.*;
  3. import java.util.*;
  4.  
  5. public class App15
  6. {
  7. public static void main(String[] args)
  8. {
  9. Envelope toMe = new Envelope("C671RTS2", "JOHN DOE", "1009 FRANKLIN BLVD", "SUNNYVALE", "CA", 95014);
  10. out.println(toMe);
  11.  
  12.  
  13. }
  14. }
  15.  
  16.  
  17. class Envelope
  18. {
  19. private String code;
  20. private String name;
  21. private String address;
  22. private String city;
  23. private String state;
  24. private int zip;
  25. private String zipBarCode;
  26.  
  27. Envelope(String code, String name, String address, String city, String state, int zip)
  28. {
  29. this.code = code.toUpperCase();
  30. this.name = name.toUpperCase();
  31. this.address = address.toUpperCase();
  32. this.city = city.toUpperCase();
  33. this.state = state.toUpperCase();
  34. this.zip = zip;
  35. zipBarCode = "";
  36.  
  37. barCode();
  38. }
  39.  
  40. private void barCode()
  41. {
  42. String rawZip = "" + zip;
  43.  
  44. zipBarCode += "|";
  45.  
  46. for(int x = 0; x < 4; x++)
  47. {
  48. int pieceOfZip = Integer.parseInt("" + rawZip.charAt(x));
  49.  
  50. switch(pieceOfZip)
  51. {
  52. case 1: zipBarCode += " ||"; break;
  53. case 2: zipBarCode += " | |"; break;
  54. case 3: zipBarCode += " || "; break;
  55. case 4: zipBarCode += " | |"; break;
  56. case 5: zipBarCode += " | | "; break;
  57. case 6: zipBarCode += " || "; break;
  58. case 7: zipBarCode += "| |"; break;
  59. case 8: zipBarCode += "| | "; break;
  60. case 9: zipBarCode += "| | "; break;
  61. case 0: zipBarCode += "|| "; break;
  62.  
  63. default: exit(0);
  64. }
  65.  
  66. }
  67.  
  68. zipBarCode += "|";
  69. }
  70.  
  71. public String toString()
  72. {
  73. String label;
  74.  
  75. label = "CODE " + code + "\n";
  76. label += name + "\n";
  77. label += address + "\n";
  78. label += city + " " + state + " " + zip + "\n";
  79. label += zipBarCode + "\n";
  80.  
  81. for(int x = 0; x < zipBarCode.length(); x++)
  82. label += "|";
  83.  
  84. label += "\n";
  85.  
  86. return label;
  87. }
  88. }
Add Comment
Please, Sign In to add comment