Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: What should I snip off of this code?

  1. #1
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default What should I snip off of this code?

    Hey! I was wondering which part of this code should be snipped to JUST have the barcode maker?

    import java.util.Scanner;
     
    public class postal
    {
        /**
            Here is a constructor
        */
        public int num2;    // 10000 digit
        public int num3;    // 1000 digit
        public int num4;    // 100 digit
        public int num5;    // 10 digit
        public int num6;    // 1 digit
        public int checkDig; // check digit
        public static int num;
        public static String temp;
        public static int menu;
        public static int zip;
        public static String bar0;
        public static String bar1;
        public static String bar2;
        public static String bar3;
        public static String bar4;
        public static String bar5;
        public static String bar6;
        public static String bar7;
        public static String bar8;
        public static String bar9;
        public static String str;
        public static int numb;
     
        public postal()
        {
            zip = 0;
            /**
                bar code 
            */
            bar0 = "::..."; bar1 = "...::"; bar2 = "..:.:";
            bar3 = "..::."; bar4 = ".:..:"; bar5 = ".:.:.";
            bar6 = ".::.."; bar7 = ":...:"; bar8 = ":..:.";
            bar9 = ":.:..";
     
        }
     
        public static int getZIP()
        {
            System.out.println("Enter a ZIP code : ");
            Scanner sc = new Scanner(System.in);
            zip = sc.nextInt();
            while((zip<01001)||(zip>99950))
            {
                System.out.println("**** ERROR ****");
                System.out.println("The ZIP code must be between 01001 and 99950");
                System.out.println("Please,enter the correct zip : ");
                zip = sc.nextInt();
            }
            return zip;
        }
        public static int menu()
        {
            System.out.println("**** Barcode maker / reader ****");
            System.out.println("Choose one option from following : ");
            System.out.println("1) Create ZIP barcode ");
            System.out.println("2) Find ZIP code from barcode ");
            System.out.println("3) Exit ");
            Scanner sc = new Scanner(System.in);
            return sc.nextInt();
        }
     
        public void getDigit(int num)
        {
            num2 = num/10000;
            num3 = ((num/1000)-num2*10);
            num4 = (num/100 - (num2*100 + num3*10));
            num5 = (num/10 -(num2*1000 + num3*100 + num4*10));
            num6 = (num - (num2*10000 + num3*1000 + num4*100 + num5*10));
            // error here; need to use correct formula
            checkDig = 100- (num2+num3+num4+num5+num6);
            System.out.println(checkDig);
     
            while(checkDig>10)
            {   checkDig -= 10; }
            System.out.println("**** BARCODE ****");
            getBar(num2);
            getBar(num3);
            getBar(num4);
            getBar(num5);
            getBar(num6);
            getBar(checkDig);
     
        }
        public void getBar(int x)
        {
     
            switch(x)
            {
                case 0: System.out.print(bar0); break;
                case 1: System.out.print(bar1); break;
                case 2: System.out.print(bar2); break;
                case 3: System.out.print(bar3); break;
                case 4: System.out.print(bar4); break;
                case 5: System.out.print(bar5); break;
                case 6: System.out.print(bar6); break;
                case 7: System.out.print(bar7); break;
                case 8: System.out.print(bar8); break;
                case 9: System.out.print(bar9); break;
            }
        }
        public static String number()
        {
            System.out.println("Enter a barcode with using . or : ");
            Scanner scn = new Scanner(System.in);
            String bar = scn.nextLine();
            return bar;
        }
     
        public static void getNumber(String temp)
        {
            System.out.println("*** In a getNUmber ***");
            System.out.println(temp);
            if(temp.equals(bar0))
            {  numb = 0; }
            if(temp.equals(bar1))
            {  numb = 1; }
            if(temp.equals(bar2))
            {  numb = 2; }
            if(temp.equals(bar3))
            {  numb = 3; }
            if(temp.equals(bar4))
            {  numb = 4; }
            if(temp.equals(bar5))
            {  numb = 5; }
            if(temp.equals(bar6))
            {  numb = 6; }
            if(temp.equals(bar7))
            {  numb = 7; }
            if(temp.equals(bar8))
            {  numb = 8; }
            if(temp.equals(bar9))
            {  numb = 9; }
            System.out.print(numb);
        }
        public static void devide(String temp)
        {
            postal po = new postal();
            str = temp.substring(0,4);
            System.out.println(str);
            po.getNumber(str);
            str = temp.substring(5,9);
            System.out.println(str);
            po.getNumber(str);
            str = temp.substring(10,14);
            System.out.println(str);
            po.getNumber(str);
            str = temp.substring(15,19);
            System.out.println(str);
            po.getNumber(str);
            str = temp.substring(20,24);
            System.out.println(str);
            po.getNumber(str);
     
        }
     
        public static void main(String[] args)
        {
            postal pos = new postal();
            while(menu != 3)
            {
                System.out.println();
                menu = pos.menu();      
                switch (menu)
                {
                    case 1: 
                        num = pos.getZIP();
                        pos.getDigit(num);
                        System.out.println();
                        break;
                    case 2:
                        temp = pos.number();
                        System.out.println(temp);
                        pos.devide(temp);
                        break;
                    case 3:    
                        break;
                }
            }   
        }
    }


  2. #2
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: What should I snip off of this code?

    while( zip < 01001 && zip > 99950 ) //You should use ampersands instead of bars because your saying its less than and greater than. 
            {
                System.out.println("**** ERROR ****");
                System.out.println("The ZIP code must be between 01001 and 99950");
                System.out.println("Please,enter the correct zip : ");
                zip = sc.nextInt();
            }

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: What should I snip off of this code?

    He wants it to mean less than or greater than. (I would remove the leading 0 in 01001)

    --- Update ---

    Start with the main method and see where it's calling the method that does the other things. I believe the bar-code interpreter method is called 'devide'.

    You also have to remove the other options from the menu. You can either disable them or just remove that particular function. Comment things out one thing at a time, so it doesn't stop working altogether.

Similar Threads

  1. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  2. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  3. Trouble Porting my Java File Reading Code to Android Code
    By Gravity Games in forum Android Development
    Replies: 0
    Last Post: December 6th, 2012, 04:38 PM
  4. Replies: 5
    Last Post: November 14th, 2012, 10:47 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM

Tags for this Thread