-1

So I have a code that is suppose to make labels and it seems to be almost working the only problem is that when it ask for user input the 7 questions (arrays) that is ask repeat. And they only repeat on the first round. Sorry its hard to explain. If you have any suggestions appreciate it.

import javax.swing.JOptionPane;
public class Mail
{
public static void main(String[] args)
{

                String nameAddressArray[] = getLabelData();
                String numBoxesInput;
                int numBoxes;
                String enterAnother = "Y";
                int counter;


                getLabelData();

                numBoxesInput = JOptionPane.showInputDialog("Enter number of boxes in the order:");
                numBoxes = Integer.parseInt(numBoxesInput);


                while(enterAnother.equalsIgnoreCase("Y"))
                {
                    counter = 1;
                    // begin the inner loop to display a label and increment the counter
                    while(counter <= numBoxes)
                    {
                        System.out.println(nameAddressArray[0] + " " + nameAddressArray[1] + " " + nameAddressArray[2]);
                        System.out.println(nameAddressArray[3]);
                        System.out.println(nameAddressArray[4] + ", " + nameAddressArray[5] + " " + nameAddressArray[6]);
                        System.out.println("Box " + counter + " of " + numBoxes);
                        System.out.println();
                        counter = counter + 1;
                    } // end while

                    enterAnother = JOptionPane.showInputDialog("Do you want to produce more labels? Y or N");

                    while (!enterAnother.equalsIgnoreCase("Y") && !enterAnother.equalsIgnoreCase("N"))
                    {
                        enterAnother = JOptionPane.showInputDialog(null, "Invalid Response. Please enter Y or N.",
                                                                    "DATA ENTRY ERROR", JOptionPane.ERROR_MESSAGE);
                    }

                    if(enterAnother.equalsIgnoreCase("Y"))
                    {

                        getLabelData();

                        numBoxesInput = JOptionPane.showInputDialog("Enter number of boxes in the order:");
                        numBoxes = Integer.parseInt(numBoxesInput);
                    } // end if
                } // end while

            System.exit(0);
}

public static String[] getLabelData() {
    String[] nameAddressArray = new String[7];
    nameAddressArray[0] = JOptionPane.showInputDialog("Enter title (Mr., Ms., Dr., "
            + "etc.): ");
    nameAddressArray[1] = JOptionPane.showInputDialog("Enter first name: ");
    nameAddressArray[2] = JOptionPane.showInputDialog("Enter lastname: ");
    nameAddressArray[3] = JOptionPane.showInputDialog("Enter street address: ");
    nameAddressArray[4] = JOptionPane.showInputDialog("Enter city: ");
    nameAddressArray[5] = JOptionPane.showInputDialog("Enter state (IL, MO, etc.): ");
    nameAddressArray[6] = JOptionPane.showInputDialog("Enter zip (e.g., 62025): ");
    return nameAddressArray;
    }
}
Raf
  • 7,505
  • 1
  • 42
  • 59
Grace
  • 67
  • 5

2 Answers2

1

You're calling getLabelData() twice, once as:

String nameAddressArray[] = getLabelData();

and then later as:

getLabelData();

Remove the second call.

Apart from that, as has been pointed out in Gi0rgi0s answer, having the array brackets following the variable type instead of the name is considered better style and less confusing, meaning your line should preferably be

String[] nameAddressArray = getLabelData();
Community
  • 1
  • 1
Matthias Fischer
  • 553
  • 4
  • 18
0

Change

String nameAddressArray[] = getLabelData(); 

to just

String[] nameAddressArray;

You are calling it twice.

Gi0rgi0s
  • 1,757
  • 2
  • 22
  • 31