## V22.0002 - ASSIGNMENT 3

A stock brokerage company wants to know to which stock exchange its brokers are sending their customers' orders. Write a program that allows the company to track its orders.

For every order, the broker will enter the number of shares and the exchange (note that the user is not entering every detail of an order - just those two pieces of information).

After all the data is entered, the program should print to the screen for each exchange the number of orders, the number of shares, as well the average number of shares per order.

There are two possible exchanges for this exercise, as follows: the New York Stock Exchange ("NYSE"), and the American Stock Exchange ("ASE"). For data input, use 'N' or 'n' to represent the NYSE, and 'a' or 'A' to represent the ASE. You should reject order data for any other values for exchange.

You should use a sentinel of 0 or less for shares to signal the end of data input. That is if the user enters a 0 or a negative number that will signal the end of input.

Ex:

```Welcome to the Destination Summary program.
You will enter the number of shares and the destination
exchange for each order.  Possible exchanges are represented
by the letters N and A, for the New York, and
American Stock Exchanges, respectively.

To end the program, enter 0 or less for the number of shares.

Please enter the number of shares for the next order (enter 0 or less to end):
101
Please enter the destination exchange for this
order (N (NYSE) or A (ASE)):
N

Please enter the number of shares for the next order (enter 0 or less to end):
200
Please enter the destination exchange for this
order (N (NYSE) or A (ASE)):
a

Please enter the number of shares for the next order (enter 0 or less to end):
100
Please enter the destination exchange for this
order (N (NYSE) or A (ASE)):
N

Please enter the number of shares for the next order (enter 0 or less to end):
300
Please enter the destination exchange for this
order (N (NYSE) or A (ASE)):
7
ERROR: 7 is not a valid exchange.  Rejecting data.

Please enter the number of shares for the next order (enter 0 or less to end):
100
Please enter the destination exchange for this
order (N (NYSE) or A (ASE)):
A

Please enter the number of shares for the next order (enter 0 or less to end):
0

Summary Statistics:
-------------------
New York Stock Exchange:
2 order(s), 201 share(s), average 100.50 share(s) per order
American Stock Exchange:
2 order(s), 300 share(s), average 150.00 share(s) per order

```
Notes and Hints:
• Remember, style counts so remember your comments, spacing, and use of constants to avoid .magic numbers. in the body of the program.
• Pay attention to efficiency of the code- avoid statements that are unnecessary in the body of your while loop.
• Note the error message after an invalid exchange was entered; its shares were not used in any calculations.
• Notice you do not ask for the exchange in the event that you have reached the end of the data. That means you must pay attention to the order of the prompts in your loop.
• Oviously, each of the input lines will not be sent to System.out as it appears in my sample run. Instead, you will use JOptionPane to get the input. All output can go to System.out or to JOptionPane.
Updated October 10, 2004