Example #1
0
	public static String XMLContent(List<Book> books, Writer writer)
	{
		XmlSerializer serializer = Xml.newSerializer();
		try {
			serializer.setOutput(writer);
			serializer.startDocument("UTF-8", true);
			serializer.startTag("", "books");
			for (Book book : books) {
				serializer.startTag("", "book");
				serializer.attribute("", "id", String.valueOf(book.getId()));
				serializer.startTag("", "name");
				serializer.text(book.getName());
				serializer.endTag("", "name");
				serializer.startTag("", "price");
				serializer.text(String.valueOf(book.getPrice()));
				serializer.endTag("", "price");
				serializer.endTag("", "book");
			}
			serializer.endTag("", "books");
			serializer.endDocument();
			return writer.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
 @Override
 public int visit(Book book) {
   int prix = 0;
   prix = book.getPrice();
   System.out.println("Le livre " + book.getTitre() + " coûte " + prix);
   return prix;
 }
Example #3
0
 public void remove() {
   System.out.println("elo");
   bookList.remove(1);
   for (Book book : bookList) {
     System.out.println(book.getId() + " " + book.getTitle() + " " + book.getPrice());
   }
 }
Example #4
0
 public boolean equals(Object obj) {
   if (!(obj instanceof Book)) return false;
   Book book = (Book) obj;
   return (this.ISBN == book.getISBN()
       && this.getTitle().equals(book.getTitle())
       && this.getAuthor().equals(book.getAuthor())
       && this.getPrice() == book.getPrice());
 }
Example #5
0
  public static void main(String args[]) {
    Author schildt = new Author("Herbert Schildt", "*****@*****.**");
    System.out.println(schildt.getName() + " at " + schildt.getEmail());

    Author bjarne = new Author("Bjarne Stroustrup");
    bjarne.setEmail("*****@*****.**");
    bjarne.print();

    Book b1 = new Book("Teach Yourself C++", schildt);
    b1.setPrice(150.5);
    b1.setStock(50);
    System.out.println(
        "Author: "
            + b1.getAuthorName()
            + " Name: "
            + b1.getName()
            + " Price: "
            + b1.getPrice()
            + " Stock: "
            + b1.getStock());
    b1.borrowBook(20);
    b1.returnBook(10);
    System.out.println(
        "Author: "
            + b1.getAuthorName()
            + " Name: "
            + b1.getName()
            + " Price: "
            + b1.getPrice()
            + " Stock: "
            + b1.getStock());

    Book b2 = new Book("The C++ Programming Language", bjarne, 200, 20);
    b2.print();
    b2.returnBook(10);
    b2.borrowBook(50);
    b2.print();

    b1.getAuthor().print();
    b2.getAuthor().print();
  }
  @Override
  public BusinessResult buy(String userId, String bookId) throws DataAccessException {
    UserBook userBook = new UserBook();
    User user = mutableDataAccess.findById(User.class, userId);
    Book book = mutableDataAccess.findById(Book.class, bookId);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("userId", userId);
    map.put("bookId", bookId);
    List<UserBook> userBooks = mutableDataAccess.paging(UserBook.class, 1, 1, map);
    if (userBooks.size() > 0) {
      if (userBooks.get(0).isHasBuyed() && book.getPrice() > 0) {
        return new BusinessResult(BusinessResult.ResultStatus.FAIL, "该书已经购买,不需要重复购买");
      }
      userBook = userBooks.get(0);
    }

    userBook.setBookId(bookId);
    userBook.setUserId(userId);

    if (book.getPrice() <= 0) {
      userBook.setHasBuyed(userBook.isHasBuyed());
      mutableDataAccess.save(userBook);
      return new BusinessResult(BusinessResult.ResultStatus.OK, "免费书籍,已经保存到书架上");
    } else {
      if (user.getCredits() < book.getPrice()) {
        return new BusinessResult(BusinessResult.ResultStatus.FAIL, "购买失败,您的信用值余额不足,请充值");
      } else {
        user.setCredits(user.getCredits() - book.getPrice());
        userBook.setHasBuyed(true);
        userBook.setUser(user);
        userBook.setBook(book);
        mutableDataAccess.save(user);
        book.setSellAmount(book.getSellAmount() + 1);
        mutableDataAccess.save(book);
        mutableDataAccess.save(userBook);
        return new BusinessResult(BusinessResult.ResultStatus.OK, "购买成功,已经保存到书架上");
      }
    }
  }
Example #7
0
  // Example of sorting by TWO keys
  @Override
  public int compareTo(Book other) {
    int result = 0;

    if (author.equals(other.getAuthor())) {
      // Authors are the same. We need to look at the price
      // to determine which book should come first
      if (price < other.getPrice()) {
        // This price is cheaper. Put it at the top
        // of the list
        result = -1;
      } else if (price == other.getPrice()) {
        result = 0;
      } else {
        result = 1;
      }
    } else {
      // Authors are NOT the same
      result = author.compareTo(other.getAuthor());
    }

    return result;
  }
 @Override
 public void onBindViewHolder(ViewHolder holder, int position) {
   runEnterAnimation(holder.itemView, position);
   Book book = mBooks.get(position);
   holder.tvTitle.setText(book.getTitle());
   String desc =
       "作者: "
           + book.getAuthor()[0]
           + "\n副标题: "
           + book.getSubtitle()
           + "\n出版年: "
           + book.getPubdate()
           + "\n页数: "
           + book.getPages()
           + "\n定价:"
           + book.getPrice();
   holder.tvDesc.setText(desc);
   Glide.with(holder.ivBook.getContext()).load(book.getImage()).fitCenter().into(holder.ivBook);
 }
Example #9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_book);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    int position = getIntent().getIntExtra("position", 0);
    currentBook = SimpleBookManager.getInstance().getBook(position);

    title = (EditText) findViewById(R.id.textViewNameTitle);
    title.setText(currentBook.getTitle());
    author = (EditText) findViewById(R.id.textViewNameAuthor);
    author.setText(currentBook.getAuthor());
    course = (EditText) findViewById(R.id.textViewNameCourse);
    course.setText(currentBook.getCourse());
    price = (EditText) findViewById(R.id.textViewNamePrice);
    price.setText(String.valueOf(currentBook.getPrice()));
    isbn = (EditText) findViewById(R.id.textViewNameISBN);
    isbn.setText(currentBook.getIsbn());
  }
Example #10
0
 @Override
 public void mouseClicked(MouseEvent e) {
   // TODO Auto-generated method stub
   if (e.getSource() == table) {
     if (e.getClickCount() == 2) // 더블클릭
     {
       int row = table.getSelectedRow();
       String no = model.getValueAt(row, 0).toString();
       bp.setPoster(Integer.parseInt(no));
       bp.repaint();
       Book book = bm.bookDetail(Integer.parseInt(no));
       la1.setText("번호:" + no);
       la2.setText("제목:" + book.getTitle());
       la3.setText("저자:" + book.getAuthor());
       la4.setText("출판사:" + book.getPublisher());
       la5.setText("가격:" + book.getPrice());
     }
   } else if (e.getSource() == b) {
     getData();
   }
 }
 @Action(
     value = "grouponBook",
     interceptorRefs = {@InterceptorRef(value = "userActionStack")},
     results = {@Result(name = SUCCESS, type = "json")})
 public String grouponBook() {
   PrintWriter writer = CommonUtil.getJsonPrintWriter(ServletActionContext.getResponse());
   Book book = bookService.getBookByIsbn(isbn);
   BookBase base = null;
   if (book != null) {
     base = new BookBase();
     base.setIsbn(book.getIsbn());
     base.setAuthor(book.getAuthor());
     base.setPrice(book.getPrice());
     base.setTitle(book.getTitle());
     base.setPublisher(book.getPublisher());
   }
   String json = JSONObject.fromObject(base).toString();
   writer.write(json);
   writer.flush();
   writer.close();
   return SUCCESS;
 }
Example #12
0
 public void show() {
   System.out.println("nnnnnnnnnnn==" + name);
   System.out.println(
       "calling the show method==bookname=" + bk.getBookname() + "book price==" + bk.getPrice());
 }
Example #13
0
 public static void main(String[] args) {
   Book book = new Book("Discrete Math", "Qu", 20);
   System.out.println("Title : " + book.getTitle());
   System.out.println("Author : " + book.getAuthor());
   System.out.println("Price : " + book.getPrice());
 }
  // 1 进入团购的页面
  @Action(
      value = "nextGrouponitemPage",
      interceptorRefs = {@InterceptorRef(value = "userActionStack")},
      results = {
        @Result(name = SUCCESS, location = "/userPages/grouponitem.jsp"),
        @Result(name = "over", location = "/userPages/cart.jsp")
      })
  public String nextGrouponitemPage() {
    User findUser = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
    // if()
    Groupon find = grouponService.getGroupon(groupon.getId());
    Grouponitem grouponitem = new Grouponitem();
    grouponitem.setId(page);
    grouponitem.setGroupon(find);
    Grouponitem findItem = grouponService.next(grouponitem);
    // 如果没有找到,那么意味着查询已经结束
    if (findItem == null) {
      double fee = 0.0;
      int num = 0;
      List<Cart> result = new ArrayList<Cart>();
      List<Cartitem> items = cartService.getGrouponitemsByUser(findUser.getId(), find.getId());
      for (int i = 0; i < items.size(); i++) {
        Cartitem cartitem = items.get(i);
        num += cartitem.getNum();
        if (cartitem.getSalesBook() == null) {
          if (cartitem.getBook().getDiscount() == 0.0) {
            cartitem.getBook().setDiscount(ConstantUtil.NEWBOOKDISCOUNT);
          }
          SalesBook newbookSalesBook =
              salesBookService.getSalesBookByIsbnSeller(
                  cartitem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT);
          float discount = ConstantUtil.NEWBOOKDISCOUNT;
          if (newbookSalesBook != null && newbookSalesBook.getDiscount() != null) {
            discount = newbookSalesBook.getDiscount();
          }
          fee +=
              cartitem.getNum() * Math.round(cartitem.getBook().getPrice() * discount * 10) / 10d;
        } else {
          fee += cartitem.getNum() * cartitem.getSalesBook().getPrice();
        }
        Cart cart = cartitem.getCart();
        Cart findCart = getCartByList(cart.getId(), result);
        if (findCart == null) {
          Cart cartResult = new Cart();
          cartResult.setId(cart.getId());
          cartResult.setSeller(cart.getSeller());
          cartResult.setCartitems(new HashSet());
          cartResult.setTotalFee(cart.getTotalFee());
          cartResult.setUser(cart.getUser());
          cartResult.getCartitems().add(cartitem);
          cartitem.setCart(cartResult);
          result.add(cartResult);
        } else {
          findCart.getCartitems().add(cartitem);
          cartitem.setCart(findCart);
        }
      }
      System.out.println(result.size());
      ActionContext.getContext().getValueStack().set("carts", result);
      ActionContext.getContext().getValueStack().set("num", num);
      ActionContext.getContext().getValueStack().set("fee", Math.round(fee * 10) / 10d);
      return "over";
    }

    Book book = bookService.getBookByIsbn(findItem.getBook().getIsbn());
    // 如果没有拿到数据,则返回空
    ServiceArea serviceArea = findUser.getSchool().getServiceArea();
    // 如果找到了,查看新书供应商有没有此数据,如果没有,那么就给新书供应商加进去
    SalesBook newbookSalesBook =
        salesBookService.getSalesBookByIsbnSeller(
            findItem.getBook().getIsbn(), ConstantUtil.NEWBOOKPRODUCT);
    Seller seller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT);
    SalesBook model =
        salesBookService.getSalesBookByIsbnSeller(findItem.getBook().getIsbn(), seller.getId());
    float bookDiscount;
    if (newbookSalesBook == null) {
      newbookSalesBook = new SalesBook();
      newbookSalesBook.setSeller(seller);
      newbookSalesBook.setBook(book);
      newbookSalesBook.setTitle(book.getTitle());
      newbookSalesBook.setAuthor(book.getAuthor());
      newbookSalesBook.setStandardPrice(book.getPrice());
      newbookSalesBook.setPublisher(book.getPublisher());
      newbookSalesBook.setImage(book.getImage());
      newbookSalesBook.setBigImage(book.getBigImage());
      salesBookService.save(newbookSalesBook);
    }
    if (model == null) {
      model = newbookSalesBook;
    }
    if (newbookSalesBook.getDiscount() == null) {
      bookDiscount = ConstantUtil.NEWBOOKDISCOUNT;
    } else {
      bookDiscount = newbookSalesBook.getDiscount();
    }
    ActionContext.getContext().getValueStack().set("bookDiscount", bookDiscount);
    newbookSalesBook.setDiscount(bookDiscount);
    newbookSalesBook.setPrice(
        Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d);
    newbookSalesBook.setNum(999);
    SalesBook salesBook = newbookSalesBook;
    School findSchool = findUser.getSchool();
    List<SellerBean> sellerBeans =
        salesBookService.getSellerBeans(
            newbookSalesBook.getBook().getIsbn(), findSchool.getServiceArea().getId());
    int totalNum = cartService.getGrouponitemsByUser(findUser.getId(), find.getId()).size();
    ActionContext.getContext().getValueStack().set("sellerBeans", sellerBeans);
    ActionContext.getContext().getValueStack().set("item", findItem);
    Seller newBookSeller = sellerService.getSellerById(ConstantUtil.NEWBOOKPRODUCT);
    ActionContext.getContext().getValueStack().set("totalNum", totalNum);
    ActionContext.getContext().getValueStack().set("model", model);
    ActionContext.getContext().getValueStack().set("newBookSeller", newBookSeller);
    ActionContext.getContext()
        .getValueStack()
        .set("price", Math.round(newbookSalesBook.getBook().getPrice() * bookDiscount * 10) / 10d);
    // 获得这个学校所有的团购项目
    return SUCCESS;
  }
 public Float getItemPrice() {
   return book.getPrice() * quantity;
 }