Each time main is run a new driver is created. The if-then-else is then used, but it is with a new driver each time. after each use driver.close();
closes the tab
Try creating a program structure that creates the driver once and then has methods that reuse that driver without closing it between tests.
See also http://sqa.stackexchange.com/a/1993/8992https://sqa.stackexchange.com/a/1993/8992