コード例 #1
0
 @Test
 public void testToString() {
   Book b5 = new Book("Learn SQL", "John Doe");
   String s = "Learn SQL by John Doe - Available";
   // System.out.println(b5.getPerson().getName());
   assertEquals(s, b5.toString());
   b5.setPerson(new Person("User"));
   s = "Learn SQL by John Doe - Unavailable";
   assertEquals(s, b5.toString());
 }
コード例 #2
0
 @Override
 public String toString() {
   String bookNames = String.format("%-25s %-25s %-25s \n", "Bookname", "Author Name", "Year");
   for (Book names : bookList) {
     bookNames += names.toString() + "\n";
   }
   return bookNames;
 }
コード例 #3
0
  public static void main(String[] args) {
    ArrayList<String> List = new ArrayList<String>();
    Scanner sc = new Scanner(System.in);

    // SETTING THE CONDITION FOR CONTINUATION
    String choice = "y";
    while (choice.equalsIgnoreCase("y")) {

      // SELECTION OF PRODUCT TYPE
      System.out.println("Product type:(Book/Software)?");
      String type = sc.nextLine();

      // FOR BOOK, ENTER THE REQUIRED INFORMATION AND STORE TO DESIGNATED LOCATION
      if (type.equalsIgnoreCase("Book")) {
        System.out.println("Enter the book description:");
        String descript = sc.nextLine();
        System.out.println("Enter the book price:");
        double price = sc.nextDouble();
        sc.nextLine();
        System.out.println("Enter the book author:");
        String author = sc.nextLine();
        Book a = new Book();
        a.setAuthor(author);
        a.setDescription(descript);
        a.setPrice(price);
        a.setCode(type);
        List.add(a.toString("detail"));
      } else {

        // FOR SOFTWARE, ENTER THE REQUIRED INFORMATION AND STORE TO DESIGNATED LOCATION
        if (type.equalsIgnoreCase("Software")) {
          System.out.println("Enter the software description:");
          String descript = sc.nextLine();
          System.out.println("Enter the software price:");
          double price = sc.nextDouble();
          sc.nextLine();
          System.out.println("Enter the software version:");
          String version = sc.nextLine();
          Software s = new Software();
          s.setVersion(version);
          s.setDescription(descript);
          s.setPrice(price);
          s.setCode(type);
          List.add(s.toString("detail"));
        }
      }
      System.out.println("Do you wish to continue?(y/n)");
      choice = sc.nextLine();
    }
    System.out.println("PRODUCT DETAILS DISPLAYED BELOW");
    System.out.println("\n");
    Iterator<String> itr = List.iterator();
    while (itr.hasNext()) {
      String in = itr.next();
      System.out.println(in);
    }
    sc.close();
  }
コード例 #4
0
 private void RodytiKnyguRinkinius() {
   neregKnyguZona.setText("");
   for (Book a : rg.neregKnygos) neregKnyguZona.append(a.toString() + "\n");
   regKnyguZona.setText("");
   for (Map.Entry<String, Book> me : rg.regKnygos.entrySet())
     regKnyguZona.append(String.format("%8s=%s\n", me.getKey(), me.getValue()));
   tfNeregSKaitytojųKiekis.setText(Integer.toString(rg.neregKnygos.size()));
   tfRegSKaitytojųKiekis.setText(Integer.toString(rg.regKnygos.size()));
 }
コード例 #5
0
ファイル: App.java プロジェクト: noelvillaman/java
 public static Integer create(Book b) {
   Session session = getSessionFactory().openSession();
   session.beginTransaction();
   session.save(b);
   session.getTransaction().commit();
   session.close();
   System.out.println("Successfully created " + b.toString());
   return b.getId();
 }
コード例 #6
0
 public String removeBook(Book book, Session session) {
   if (bookList.contains(book)) {
     Book currentBook = bookList.get(bookList.indexOf(book));
     bookList.remove(book);
     checkedOutBooks.add(currentBook);
     borrowerDetails.put(currentBook.toString(), session.currentUserDetails());
     return "Thank You!Enjoy the book.\n";
   }
   return "That book is not available.\n";
 }
コード例 #7
0
ファイル: BookSearch.java プロジェクト: greggjs/ProgramTwoS
  /**
   * Searches titles for a keyword
   *
   * @param keyword Word to search titles for
   * @return String of books representing books containing keywords
   * @throws SQLException
   */
  public String searchByKeyWord(String keyword) throws SQLException {
    ArrayList<Book> books = new ArrayList<Book>();

    ResultSet rs = stat.executeQuery("SELECT * FROM BOOK WHERE title LIKE '%" + keyword + "%'");

    while (rs.next()) books.add(new Book(rs));

    String ans = "";
    for (Book b : books) ans += b.toString() + "\n";

    return ans;
  }
コード例 #8
0
 public String returnBook(Book book, Session session) {
   if (!compareDetails(session)) {
     return "That is not a valid book to be returned by you.\n";
   }
   if (bookList.contains(book) || !checkedOutBooks.contains(book)) {
     return "That is not a valid book to return.\n";
   }
   Book currentBook = checkedOutBooks.get(checkedOutBooks.indexOf(book));
   checkedOutBooks.remove(book);
   bookList.add(currentBook);
   borrowerDetails.remove(currentBook.toString());
   return "Thank you for returning the book.\n";
 }
コード例 #9
0
ファイル: CDI.java プロジェクト: yc18841/workspace1
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Book book = books.createBook("H2G2", 5.55F);

    List<Item> items = new ArrayList<>();
    Item item = new Item();
    items.add(item);
    PurchaseOrder po = purchase.compute(items);
    purchase.create(items);
    response.getWriter().println(book.toString() + " PurchaseOrder = " + po);

    //		response.getWriter().println("CDI!!!");
  }
コード例 #10
0
ファイル: BookDao.java プロジェクト: ClaudeJeong/comics
  // 도서 등록
  public int InsertData(Book bean) {
    System.out.println(bean.toString());
    String sql =
        "insert into books(bookcode, name, volume, writer, publisher, pubdate, genre, image, bookstat, bookstory) ";
    sql += " values(bookseq.nextval, ?, ?, ?, ?, to_date(?, 'yyyy/MM/dd'), ?, ?, default, ?) ";
    PreparedStatement pstmt = null;
    int cnt = -99999;
    try {
      if (conn == null) {
        super.conn = super.getConn();
      }
      conn.setAutoCommit(false);
      pstmt = super.conn.prepareStatement(sql);

      pstmt.setString(1, bean.getName());
      pstmt.setInt(2, bean.getVolume());
      pstmt.setString(3, bean.getWriter());
      pstmt.setString(4, bean.getPublisher());
      pstmt.setString(5, bean.getPubdate());
      pstmt.setString(6, bean.getGenre());
      // 책 이미지 이름은 책 제목과 책 볼륨의 문자열 조합이다.
      String image = bean.getName() + " " + bean.getVolume() + ".jpg";
      pstmt.setString(7, image);
      // pstmt.setString(8, bean.getBookstat());
      pstmt.setString(8, bean.getBookstory());

      cnt = pstmt.executeUpdate();
      conn.commit();
    } catch (Exception e) {
      SQLException err = (SQLException) e;
      cnt = -err.getErrorCode();
      e.printStackTrace();
      try {
        conn.rollback();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    } finally {
      try {
        if (pstmt != null) {
          pstmt.close();
        }
        super.closeConn();
      } catch (Exception e2) {
        e2.printStackTrace();
      }
    }
    return cnt;
  }
コード例 #11
0
ファイル: BookSearch.java プロジェクト: greggjs/ProgramTwoS
  /**
   * Convert an ArrayList<Book> to a formatted string
   *
   * @param books
   * @return
   * @throws SQLException
   */
  public String booksToString(ArrayList<Book> books) throws SQLException {
    String bookString = "";
    for (Book b : books) bookString += b.toString() + "\n";

    return bookString;
  }
コード例 #12
0
 @Test
 public void shouldGiveBookDetails() {
   assertEquals("Red Jhon        Martin          1994 ", book.toString());
 }
コード例 #13
0
ファイル: BookTest.java プロジェクト: MichaelKohler/P1
 public static void shouldReturnBookString() {
   String bookString = _testBook.toString();
   String correctOutput = "3, TestBook, TestAuthor, 31.01.2005";
   if (!bookString.equals(correctOutput)) _allTestsPassed = false;
 }