/**
  * Transaction menu.
  *
  * @param service authenticated client connection to a Finance GData service
  * @param sc Scanner to read user input from the command line.
  * @throws IOException If there is a problem communicating with the server.
  * @throws ServiceException If the service is unable to handle the request.
  */
 private static void transactionMenu(FinanceService service, Scanner sc)
     throws IOException, ServiceException {
   printTransactionMenuHelp();
   while (true) {
     String requestUrl = baseUrl + PORTFOLIO_FEED_URL_SUFFIX + "/";
     switch (processTransactionMenuCommand(sc.nextLine().toLowerCase())) {
       case QUERY_FEED:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         System.out.println("Enter ticker (<exchange>:<symbol>)");
         tickerProperty = sc.nextLine();
         requestUrl +=
             portfolioIdProperty
                 + POSITION_FEED_URL_SUFFIX
                 + "/"
                 + tickerProperty
                 + TRANSACTION_FEED_URL_SUFFIX;
         queryTransactionFeed(service, requestUrl);
         break;
       case QUERY_ENTRY:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         System.out.println("Enter ticker (<exchange>:<ticker>)");
         tickerProperty = sc.nextLine();
         System.out.println("Enter transaction ID");
         transactionIdProperty = sc.nextLine();
         requestUrl +=
             portfolioIdProperty
                 + POSITION_FEED_URL_SUFFIX
                 + "/"
                 + tickerProperty
                 + TRANSACTION_FEED_URL_SUFFIX
                 + "/"
                 + transactionIdProperty;
         queryTransactionEntry(service, requestUrl);
         break;
       case CREATE:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         System.out.println("Enter ticker (<exchange>:<ticker>) ");
         tickerProperty = sc.nextLine();
         requestUrl +=
             portfolioIdProperty
                 + POSITION_FEED_URL_SUFFIX
                 + "/"
                 + tickerProperty
                 + TRANSACTION_FEED_URL_SUFFIX;
         System.out.print("Enter transaction type (Buy, Sell, Sell Short, Buy to Cover): ");
         String type = sc.nextLine();
         System.out.print("Enter transaction date (yyyy-mm-dd or blank): ");
         String date = sc.nextLine();
         System.out.print("Enter number of shares (optional, e.g. 100.0): ");
         String shares = sc.nextLine();
         System.out.print("Enter price (optional, e.g. 141.14): ");
         String price = sc.nextLine();
         System.out.print("Enter commission (optional, e.g. 20.0): ");
         String commission = sc.nextLine();
         System.out.print("Enter currency (optional, e.g. USD, EUR, JPY): ");
         String currency = sc.nextLine();
         System.out.print("Enter any notes: ");
         String notes = sc.nextLine();
         TransactionEntry entry =
             FinanceUtilities.makeTransactionEntry(
                 type, date, shares, price, commission, currency, notes);
         insertTransactionEntry(service, requestUrl, entry);
         break;
       case UPDATE:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         System.out.println("Enter ticker (<exchange>:<ticker>) ");
         tickerProperty = sc.nextLine();
         System.out.println("Enter transaction ID");
         transactionIdProperty = sc.nextLine();
         requestUrl +=
             portfolioIdProperty
                 + POSITION_FEED_URL_SUFFIX
                 + "/"
                 + tickerProperty
                 + TRANSACTION_FEED_URL_SUFFIX
                 + "/"
                 + transactionIdProperty;
         System.out.print("Enter transaction type (Buy, Sell, Sell Short, Buy to Cover): ");
         type = sc.nextLine();
         System.out.print("Enter transaction date (yyyy-mm-dd or blank): ");
         date = sc.nextLine();
         System.out.print("Enter number of shares (optional, e.g. 100.0): ");
         shares = sc.nextLine();
         System.out.print("Enter price (optional, e.g. 141.14): ");
         price = sc.nextLine();
         System.out.print("Enter commission (optional, e.g. 20.0): ");
         commission = sc.nextLine();
         System.out.print("Enter currency (optional, e.g. USD, EUR, JPY): ");
         currency = sc.nextLine();
         System.out.print("Enter any notes: ");
         notes = sc.nextLine();
         entry =
             FinanceUtilities.makeTransactionEntry(
                 type, date, shares, price, commission, currency, notes);
         updateTransactionEntry(service, requestUrl, entry);
         break;
       case DELETE:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         System.out.println("Enter ticker (<exchange>:<ticker>)");
         tickerProperty = sc.nextLine();
         System.out.println("Enter transaction ID");
         transactionIdProperty = sc.nextLine();
         requestUrl +=
             portfolioIdProperty
                 + POSITION_FEED_URL_SUFFIX
                 + "/"
                 + tickerProperty
                 + TRANSACTION_FEED_URL_SUFFIX
                 + "/"
                 + transactionIdProperty;
         deleteTransactionEntry(service, requestUrl);
         break;
       case BACK:
         return;
       case QUIT:
         System.exit(0);
       case HELP:
         printTransactionMenuHelp();
         break;
       default:
         printTransactionMenuHelp();
     }
   }
 }
 /**
  * Portfolio menu.
  *
  * @param sc Scanner to read user input from the command line.
  * @throws IOException If there is a problem communicating with the server.
  * @throws ServiceException If the service is unable to handle the request.
  */
 private static void portfolioMenu(FinanceService service, Scanner sc)
     throws IOException, ServiceException {
   printPortfolioMenuHelp();
   while (true) {
     String requestUrl = baseUrl + PORTFOLIO_FEED_URL_SUFFIX;
     switch (processPortfolioMenuCommand(sc.nextLine().toLowerCase())) {
       case QUERY_FEED:
         System.out.print("Include returns in query response? (y/n) ");
         String includeReturns = sc.nextLine();
         if (includeReturns.toLowerCase().equals("y")
             || includeReturns.toLowerCase().equals("yes")) {
           requestUrl += "?returns=true";
         } else if (includeReturns.toLowerCase().equals("n")
             || includeReturns.toLowerCase().equals("no")) {
           requestUrl += "?returns=false";
         }
         System.out.print("Inline positions in feed? (y/n) ");
         String inlinePositions = sc.nextLine();
         if (inlinePositions.toLowerCase().equals("y")
             || inlinePositions.toLowerCase().equals("yes")) {
           requestUrl += "&positions=true";
         } else if (inlinePositions.toLowerCase().equals("n")
             || inlinePositions.toLowerCase().equals("no")) {
           requestUrl += "&positions=false";
         }
         queryPortfolioFeed(service, requestUrl);
         break;
       case QUERY_ENTRY:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         requestUrl += "/" + portfolioIdProperty;
         queryPortfolioEntry(service, requestUrl);
         break;
       case CREATE:
         System.out.println("Enter portfolio name");
         String portfolioName = sc.nextLine();
         System.out.println("Enter currency code");
         String currencyCode = sc.nextLine();
         PortfolioEntry entry = FinanceUtilities.makePortfolioEntry(portfolioName, currencyCode);
         insertPortfolioEntry(service, requestUrl, entry);
         break;
       case UPDATE:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         requestUrl += "/" + portfolioIdProperty;
         System.out.println("Enter new portfolio name");
         portfolioName = sc.nextLine();
         System.out.println("Enter new currency code");
         currencyCode = sc.nextLine();
         entry = FinanceUtilities.makePortfolioEntry(portfolioName, currencyCode);
         updatePortfolioEntry(service, requestUrl, entry);
         break;
       case DELETE:
         System.out.println("Enter portfolio ID");
         portfolioIdProperty = sc.nextLine();
         requestUrl += "/" + portfolioIdProperty;
         deletePortfolioEntry(service, requestUrl);
         break;
       case BACK:
         return;
       case POSITIONS:
         positionMenu(service, sc);
         break;
       case QUIT:
         System.exit(0);
       case HELP:
         printPortfolioMenuHelp();
         break;
       default:
         printPortfolioMenuHelp();
     }
   }
 }