Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project Description POSTNET (Postal Numeric Encoding Technique) is a barcode sys

ID: 3670888 • Letter: P

Question

Project Description POSTNET (Postal Numeric Encoding Technique) is a barcode system that was used until 2013 by the United States Postal Service to assist in directing mail. The zip code and a check digit were encoded in half-height and full- height bars and printed on letters. Full-height frame bars were placed on either side of the six encoded digits. For this part of the project, your program will simply prompt the user for a name, street address, city, state, and zip code and output a mailing label. See Sample Output for all the required output and format. Note the row of asterisks followed by the word, “Postage". This is required By the time you finish Part 2 of the project, your program will output a true barcode using : for half bars and | for full bars. You will not do any encoding in this part of the project. Instead, for your "pseudo" barcode you will 1. 2. 3. 4. Break a 5 digit zip code into individual digits Calculate a check digit Display all 6 digits with a space between each digit Surround the group of digits with frame bars To calculate the check digit: 1. 2. 3. Add up the 5 zip code digits. For example, if a letter is sent to 37660 it would have the sum of 22 Find the remainder of this number when it is divided by 10, in this case 2. This is also known as the sum modulo 10. Subtract the sum modulo 10 from 10. Continuing with the example, 10 2 = 8. The check digit is therefore 8.

Explanation / Answer

import javax.swing.*;

import java.awt.*;

import java.util.StringTokenizer;

public class Address

{

    //Class Variables    

    String s1;

    String s2;

    String s3;

    boolean zipCheck = true;

            //Constructor

            public Address()

            {

            String prompt = "first and last name";

            s1 = JOptionPane.showInputDialog(prompt);

            String prompt2 = "Enter Street Address";

            s2 = JOptionPane.showInputDialog(prompt2);

            String prompt3 = "City, State Zip";

            s3 = JOptionPane.showInputDialog(prompt3);

            checkValid();

        //    noZip();

            }

        public void write(Graphics2D g2)

              {

                Font address1 = new Font ("Arial", 0, 20);

                g2.setFont(address1);

                g2.drawString(s1, 50, 130);

                g2.drawString(s2, 50, 150);

                g2.drawString(s3, 50, 170);

            }

        public int getZipCode()

            {

            if (zipCheck != false) {

                StringTokenizer st = new StringTokenizer(s3);

                String tristan;

                tristan = st.nextToken();

                tristan = st.nextToken();

                tristan = st.nextToken();

                return Integer.parseInt(tristan, 10);

            }

            else

                return 0;

            }

    public void checkValid()

    {

    if (s1.equals(""))

        {

        s1 = "Dead Letter Box";

        s2 = "c/o Local USPS";

        s3 = " ";

        zipCheck = false;

        }

    if (s2.equals(""))

        {

        s1 = "Dead Letter Box";

        s2 = "c/o Local USPS";

        s3 = " ";

        zipCheck = false;

        }

        if (s3.equals(""))

        {

        s1 = "Return to Sender";

        s2 = "Post not deliveable";

        s3 = " ";

        zipCheck = false;

        }

    }

    }

import javax.swing.*;

import java.awt.*;

public class mailComponent extends JComponent

{

int x1;

int x2;

int x3;

int x4;

int x5;

int ZipCode;

private Address label1;

int sum1;

bars one;

    public mailComponent()    

    {

    label1 = new Address();

    ZipCode = label1.getZipCode();

    calcDigits();

    CheckSum();

    one = new bars();

    }

        public void paintComponent(Graphics g)

        {

        Graphics2D g2 = (Graphics2D) g;

        label1.write(g2);

        if (ZipCode != 0) {

            one.drawLong(g2);

            drawBars(x1,g2);

            drawBars(x2,g2);

            drawBars(x3,g2);

            drawBars(x4,g2);

            drawBars(x5,g2);

            drawBars(sum1,g2);

            one.drawLong(g2);

        }

    }    

        public void calcDigits()

        {

            x5 = ZipCode%10;

            ZipCode = (ZipCode-x5)/10;

            x4 = ZipCode%10;

            ZipCode = (ZipCode-x4)/10;

            x3 = ZipCode%10;

            ZipCode = (ZipCode-x3)/10;

            x2 = ZipCode%10;

            ZipCode = (ZipCode-x2)/10;

            x1 = ZipCode%10;    

            System.out.println(x1);

            System.out.println(x2);

            System.out.println(x3);

            System.out.println(x4);

            System.out.println(x5);

            }

        public void CheckSum()

        {

            sum1 = x1+x2+x3+x4+x5;

            sum1= sum1%10;

            if (sum1 == 0)

                sum1 = 0;

            else

                sum1 = 10-sum1;

        }

        public void drawBars(int wall, Graphics2D g2)

        {

            switch (wall)

            {

            case 1:  one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawLong(g2);

                break;

            case 2:  one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                break;

            case 3:  one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                break;

            case 4:  one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                break;

            case 5:  one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                break;

            case 6:  one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                break;

            case 7:  one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                break;

            case 8:  one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                break;

            case 9:  one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                break;

            case 0:  one.drawLong(g2);

                        one.drawLong(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

                        one.drawShort(g2);

            }

        }

}