Ejemplo n.º 1
0
  @Override
  public void keyReleased(KeyEvent e) {
    switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:
        robot.stopUp();
        break;

      case KeyEvent.VK_DOWN:
        robot.stopDown();
        break;

      case KeyEvent.VK_LEFT:
        myBasket.stopMoving();
        break;

      case KeyEvent.VK_RIGHT:
        myBasket.stopMoving();
        break;

        /*case KeyEvent.VK_SPACE:
        break;*/

      case KeyEvent.VK_CONTROL:
        robot.setReadyToFire(true);
        break;
    }
  }
Ejemplo n.º 2
0
  @Override
  public void paint(Graphics g) {
    if (state == GameState.Running) {
      // g.drawImage(background, bg1.getBgX(), bg1.getBgY(), this);
      // g.drawImage(background, bg2.getBgX(), bg2.getBgY(), this);
      // paintTiles(g);

      ArrayList projectiles = robot.getProjectiles();
      for (int i = 0; i < projectiles.size(); i++) {
        Projectile p = (Projectile) projectiles.get(i);
        g.setColor(Color.BLACK);
        g.fillRect(p.getX(), p.getY(), 35, 2);
      }
      for (int i = 0; i < Ballon_Objects.size(); i++) {
        Ballon bb = Ballon_Objects.get(i);
        if (bb.isVisible == true)
          g.drawImage(ballonImage, bb.getCenterX() - 28, bb.getCenterY() - 35, this);
        else {
          Ballon_Objects.remove(i);
        }

        System.out.println("" + Ballon_Objects.size());
      }

      for (int i = 0; i < Ballon_Bottom_Objects.size(); i++) {
        BallonBottom bottom = Ballon_Bottom_Objects.get(i);
        if (bottom.isVisible == true)
          g.drawImage(ballonBottomImage, bottom.getCenterX() - 10, bottom.getCenterY() + 13, this);
        else {
          Ballon_Bottom_Objects.remove(i);
        }

        System.out.println("BallonBottom:" + Ballon_Bottom_Objects.size());
      }

      /*g.drawImage(character, robot.getCenterX() - 61,
              robot.getCenterY() - 63, this);
      */
      g.drawImage(arrowRobot, robot.getCenterX() - 51, robot.getCenterY() - 50, this);
      g.drawImage(basket, myBasket.getCenterX() - 54, myBasket.getCenterY() - 20, this);

      /*g.drawImage(hanim.getImage(), hb.getCenterX() - 48,
              hb.getCenterY() - 48, this);
      g.drawImage(hanim.getImage(), hb2.getCenterX() - 48,
              hb2.getCenterY() - 48, this);*/

      g.setFont(font);
      g.setColor(Color.BLACK);
      g.clearRect(10, 440, 90, 50);
      g.drawString("Basket : " + Integer.toString(basketScore / 24), 10, 440);
      g.drawString("Ballons: " + Integer.toString(ballonScore), 10, 470);
    } else if (state == GameState.Dead) {
      g.setColor(Color.BLACK);
      g.fillRect(0, 0, 800, 480);
      g.setColor(Color.WHITE);
      g.drawString("Dead", 360, 240);
    }
  }
Ejemplo n.º 3
0
 public int getTotalPrice() {
   int totalPrice = 0;
   Collection<Basket> collection = items.values();
   Iterator<Basket> iterator = collection.iterator();
   Basket basket;
   while (iterator.hasNext()) {
     basket = iterator.next();
     totalPrice = totalPrice + basket.getTotalPrice();
   }
   return totalPrice;
 }
  /* Input 2:
  1 imported box of chocolates at 10.00
  1 imported bottle of perfume at 47.50
  * Output 2:
  1 imported box of chocolates: 10.50
  1 imported bottle of perfume: 54.65
  Sales Taxes: 7.65
  Total: 65.15
  */
  @Test
  public void testBasketPrintReceipt2() {
    System.out.println("\nOutput 2:");

    Product impChocolateBox = new ChocolateBox(true, new BigDecimal("10.00"));
    Product impPerfumeBottle = new PerfumeBottle(true, new BigDecimal("47.50"));

    Basket basket = new Basket();
    basket.addProduct(impChocolateBox);
    basket.addProduct(impPerfumeBottle);

    System.out.println(basket.getReceiptForBasketContents());
  }
Ejemplo n.º 5
0
  /**
   * BasketCart의 HashMap에 basket객체를 삭제해준다. ProductID를 키로 하여 존재 유무를 확인하고 존재할때 quantity의 수를 감소 시킨다.
   *
   * @param String productID
   */
  public void remove(String productID) {
    if (items.containsKey(productID)) {
      Basket basket = items.get(productID);
      // System.out.println("삭제전 :" + basket.getQuantity() + " " + basket.getTotalPrice());
      basket.decrementQuantity();
      // System.out.println("삭제후 :" + basket.getQuantity() + " " + basket.getTotalPrice());

      if (basket.getQuantity() <= 0) {
        items.remove(productID);
        numberOfItems--;
      }
    }
  }
  /*  Input 1:
  	1 book at 12.49
         1 music CD at 16.49
  	1 chocolate bar at 0.85

  	1 book : 12.49
  	1 music CD: 16.49
  	1 chocolate bar: 0.85
  	Sales Taxes: 1.50
  	Total: 29.83
  */
  @Test
  public void testBasketPrintReceipt1() {
    System.out.println("\nOutput 1:");
    Product book = new Book(false, new BigDecimal("12.49"));
    Product musicCd = new MusicCD(false, new BigDecimal("14.99"));
    Product chocolateBar = new ChocolateBar(false, new BigDecimal("0.85"));

    Basket basket = new Basket();
    basket.addProduct(book);
    basket.addProduct(musicCd);
    basket.addProduct(chocolateBar);

    System.out.println(basket.getReceiptForBasketContents());
  }
Ejemplo n.º 7
0
  public static void main(String args[]) {

    Basket basket = new Basket();

    char y = 'n';
    Scanner scanner = new Scanner(System.in);
    do {
      System.out.println("Enter \'y\' to new or any key to stop");
      y = scanner.nextLine().charAt(0);
      if (y == 'y') {
        basket.addFruit();
      }
    } while (y == 'y');

    BananaPacket packet = new BananaPacket(basket.getAllBananas());
    packet.showInfo();
  }
Ejemplo n.º 8
0
 /**
  * BasketCart의 HashMap에 basket객체를 더해 준다. ProductID를 키로 하여 존재를 유무를 확인하고 존재할 때 quantity의 수를
  * parameter로 받아 증가 시킨다.
  *
  * @param String productID,Basket basket,int quantity
  */
 public void add(String productID, Basket basket, int quantity) {
   if (items.containsKey(productID)) {
     basket = items.get(productID);
     basket.incrementQuantity(quantity);
   } else {
     items.put(productID, basket);
     numberOfItems++;
   }
 }
Ejemplo n.º 9
0
 /**
  * BasketCart의 HashMap에 basket객체를 더해 준다. ProductId를 키로 하여 존재 유무를 확인하고 존재하면 quantity의 수를 증가 시킨다.
  * 존재하지 않으면 basket객체를 저장한다.
  *
  * @param String productID,Basket basket
  */
 public void add(String productID, Basket basket) {
   if (items.containsKey(productID)) {
     // 존재하면 수량을 증가시킨다
     basket = items.get(productID);
     basket.incrementQuantity();
   } else {
     // 존재하지 않으면 basket객체를 저장한다.
     items.put(productID, basket);
     numberOfItems++;
   }
 }
Ejemplo n.º 10
0
  /** Show appropriate order page. */
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    ServletContext sc = getServletContext();
    Connection conn = (Connection) sc.getAttribute("dbConnection");
    HttpSession session = request.getSession();
    synchronized (session) {
      LoginSession ls = (LoginSession) session.getAttribute("loginSession");
      if (ls == null) {
        return;
      }
      Basket basket = ls.getUser().getBasket();
      // If there is no basket, do nothing
      if (basket == null) {
        return;
      }
      if (request.getParameter("dialog").equals("yes")) {
        String msg = null;
        Order order = null;
        try {
          order = new Order();
          msg = order.form(basket, conn);
        } catch (SQLException exc) {
          request.setAttribute("sqlExc", exc);
          request.getRequestDispatcher("/error").forward(request, response);
          return;
        }
        // If there is a message (that means can't form an order)
        if (msg != null) {
          request.setAttribute("errMsg", msg);
        }
      }
      if (request.getParameter("dialog").equals("show")) {
        request.setAttribute("itemList", basket.getItemList());
      }
      request.setAttribute("url", request.getRequestURI());
      request.getRequestDispatcher("/WEB-INF/OrderVerified.jsp").forward(request, response);
    }
  }
Ejemplo n.º 11
0
  @Override
  public void run() {
    if (state == GameState.Running) {
      while (true) {
        robot.update();
        myBasket.update();
        if (maxBallons > 0) {
          addBallons(15);
        }
        /*if (robot.isJumped()) {
            currentSprite = characterJumped;
        } else if (robot.isJumped() == false && robot.isDucked() == false) {
            currentSprite = anim.getImage();
        }*/

        ArrayList projectiles = robot.getProjectiles();
        for (int i = 0; i < projectiles.size(); i++) {
          Projectile p = (Projectile) projectiles.get(i);
          if (p.isVisible() == true) {
            p.update();
          } else {
            projectiles.remove(i);
          }
        }
        for (int i = 0; i < Ballon_Bottom_Objects.size(); i++) {
          Ballon_Bottom_Objects.get(i).update();
        }
        for (int i = 0; i < Ballon_Objects.size(); i++) {
          Ballon_Objects.get(i).update();
        }

        // updateTiles();
        // hb.update();
        // hb2.update();
        // bg1.update();
        // bg2.update();
        // animate();
        repaint();
        try {
          Thread.sleep(17);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        /*if (robot.getCenterY()>500){
        	state= GameState.Dead;
        }*/
      }
    }
  }
  private BigDecimal printSavings() {
    final List<Saving> savings = basket.getSavings();
    BigDecimal totalSavings = BigDecimal.ZERO;
    if (savings.isEmpty()) {
      return totalSavings;
    }

    System.out.println("\nSavings :");
    for (final Saving saving : savings) {
      final BigDecimal savingAmount = saving.getSavingAmount();
      System.out.println(String.format("%s -%s", saving.getReason(), savingAmount));
      totalSavings = totalSavings.add(savingAmount);
    }
    return totalSavings;
  }
Ejemplo n.º 13
0
  @Override
  public void keyPressed(KeyEvent e) {

    switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:
        robot.moveUp();
        // robot.setMovingUp(true);
        break;

      case KeyEvent.VK_DOWN:
        robot.moveDown();
        // robot.setMovingDown(true);
        break;

      case KeyEvent.VK_LEFT:
        myBasket.moveLeft();

        break;

      case KeyEvent.VK_RIGHT:
        myBasket.moveRight();

        break;

        /* case KeyEvent.VK_SPACE:
        robot.jump();
        break;*/

      case KeyEvent.VK_CONTROL:
        if (robot.isReadyToFire()) {
          robot.shoot();
          robot.setReadyToFire(false);
        }
        break;
    }
  }
 private BigDecimal printProducts() {
   BigDecimal total = BigDecimal.ZERO;
   for (final Map.Entry<Product, Long> countByProduct : basket.getCountByProduct().entrySet()) {
     final long quantity = countByProduct.getValue();
     final Product product = countByProduct.getKey();
     if (quantity > 1) {
       final BigDecimal unitPrice = product.getUnitPrice();
       final BigDecimal totalForProduct = unitPrice.multiply(BigDecimal.valueOf(quantity));
       System.out.println(
           String.format(
               "%d %s @ £ %s --> %s",
               quantity, product.getDisplayName(), unitPrice, totalForProduct));
       total = total.add(totalForProduct);
     } else {
       System.out.println(
           String.format("%s £%s", product.getDisplayName(), product.getUnitPrice()));
       total = total.add(product.getUnitPrice());
     }
   }
   System.out.println("Sub total = £" + total);
   return total;
 }
Ejemplo n.º 15
0
  /* Input 2:
  1 imported bottle of perfume at 27.99
  1 bottle of perfume at 18.99
  1 packet of headache pills at 9.75
  1 box of imported chocolates at 11.25
  * Output 2:
  1 imported bottle of perfume: 32.19
  1 bottle of perfume: 20.89
  1 packet of headache pills: 9.75
  1 imported box of chocolates: 11.85
  Sales Taxes: 6.70
  Total: 74.68
  */
  @Test
  public void testBasketPrintReceipt3() {
    System.out.println("\nOutput 3:");

    Product impPerfumeBottle = new PerfumeBottle("27.99");
    impPerfumeBottle.setImported(true);

    Product perfumeBotle = new PerfumeBottle(false, new BigDecimal("18.99"));
    perfumeBotle.setImported(false);

    Product packetOfHeadachePills = new HeadachePill(false, new BigDecimal("9.75"));
    packetOfHeadachePills.setImported(false);

    Product impChocolateBox = new ChocolateBox(true, new BigDecimal("11.25"));
    impChocolateBox.setImported(true);

    Basket basket = new Basket();
    basket.addProduct(impPerfumeBottle);
    basket.addProduct(perfumeBotle);
    basket.addProduct(packetOfHeadachePills);
    basket.addProduct(impChocolateBox);

    System.out.println(basket.getReceiptForBasketContents());
  }
Ejemplo n.º 16
0
 public void VisitBaksket(Basket basket) {
   for (Item item : basket.getItems()) {
     visitItem(basket, item);
   }
 }