Stage A and B done in Java