Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static java.lang.System.*;
- import java.util.*;
- public class App15
- {
- public static void main(String[] args)
- {
- Envelope toMe = new Envelope("C671RTS2", "JOHN DOE", "1009 FRANKLIN BLVD", "SUNNYVALE", "CA", 95014);
- out.println(toMe);
- }
- }
- class Envelope
- {
- private String code;
- private String name;
- private String address;
- private String city;
- private String state;
- private int zip;
- private String zipBarCode;
- Envelope(String code, String name, String address, String city, String state, int zip)
- {
- this.code = code.toUpperCase();
- this.name = name.toUpperCase();
- this.address = address.toUpperCase();
- this.city = city.toUpperCase();
- this.state = state.toUpperCase();
- this.zip = zip;
- zipBarCode = "";
- barCode();
- }
- private void barCode()
- {
- String rawZip = "" + zip;
- zipBarCode += "|";
- for(int x = 0; x < 4; x++)
- {
- int pieceOfZip = Integer.parseInt("" + rawZip.charAt(x));
- switch(pieceOfZip)
- {
- case 1: zipBarCode += " ||"; break;
- case 2: zipBarCode += " | |"; break;
- case 3: zipBarCode += " || "; break;
- case 4: zipBarCode += " | |"; break;
- case 5: zipBarCode += " | | "; break;
- case 6: zipBarCode += " || "; break;
- case 7: zipBarCode += "| |"; break;
- case 8: zipBarCode += "| | "; break;
- case 9: zipBarCode += "| | "; break;
- case 0: zipBarCode += "|| "; break;
- default: exit(0);
- }
- }
- zipBarCode += "|";
- }
- public String toString()
- {
- String label;
- label = "CODE " + code + "\n";
- label += name + "\n";
- label += address + "\n";
- label += city + " " + state + " " + zip + "\n";
- label += zipBarCode + "\n";
- for(int x = 0; x < zipBarCode.length(); x++)
- label += "|";
- label += "\n";
- return label;
- }
- }
Add Comment
Please, Sign In to add comment