public void fillList() {
    bookList = new ArrayList<Book>();
    Book book = new Book();
    book.setId(1);
    book.setPrice(2.3);
    book.setTitle("elo");
    bookList.add(book);

    book = new Book();
    book.setId(2);
    book.setPrice(2.3333);
    book.setTitle("el2222o");
    bookList.add(book);
    System.out.println("filling");

    book = new Book();
    book.setId(3);
    book.setPrice(2.111111111);
    book.setTitle("sssaaaaaaaaaaeeeeeee");
    bookList.add(book);
    System.out.println("filling");

    book = new Book();
    book.setId(4);
    book.setPrice(2.22222222);
    book.setTitle("sssssso");
    bookList.add(book);
    System.out.println("filling");
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_save) {

      if (title.getText().toString().isEmpty()) title.setError("This field can't be empty.");
      else if (!price.getText().toString().matches("^\\d+$"))
        price.setError("It must be an integer.");
      else {
        currentBook.setTitle(title.getText().toString());
        currentBook.setAuthor(author.getText().toString());
        currentBook.setCourse(course.getText().toString());
        currentBook.setPrice(Integer.valueOf(price.getText().toString()));
        currentBook.setIsbn(isbn.getText().toString());
        SimpleBookManager.getInstance().saveChanges(this);
        setResult(RESULT_OK);
        finish();
        return true;
      }
    } else if (id == android.R.id.home) {
      onBackPressed();
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
  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();
  }
  private void setupBooks() {
    Book firstBook, secondBook, thirdBook;
    firstBook = new Book();
    firstBook.setAuthor("Harlan Ellison");
    firstBook.setTitle("I Have No Mouth, and I Must Scream");
    firstBook.setSubject("Science Fiction");
    firstBook.setPageCount(13);
    firstBook.setPrice(6.12);

    secondBook = new Book();
    secondBook.setAuthor("Rick Riordan");
    secondBook.setTitle("The Titan's Curse");
    secondBook.setSubject("Fantasy literature");
    secondBook.setPageCount(280);
    secondBook.setPrice(15.50);

    thirdBook = new Book(1, "Hp lovecraft", "Horror", "Nyarlathotep", 1);

    hipsterBooks[0] = firstBook;
    hipsterBooks[1] = secondBook;
    hipsterBooks[2] = thirdBook;
  }
Exemple #5
0
  public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("/db02.xml");
    BookDao bookDao = ctx.getBean(BookDao.class);

    System.out.println("# insert前");
    for (Book book : bookDao.selectBookList()) {
      System.out.println(book);
    }

    Book insBook = new Book();
    insBook.setBookId(3);
    insBook.setBookName("Spring上級");
    insBook.setPrice(3980);
    bookDao.insert(insBook);
    System.out.println("# insert後");
    for (Book book : bookDao.selectBookList()) {
      System.out.println(book);
    }

    Book updBook = new Book();
    updBook.setBookId(1);
    updBook.setBookName("改訂版 Spring入門");
    updBook.setPrice(3990);
    bookDao.update(updBook);
    System.out.println("# update後");
    for (Book book : bookDao.selectBookList()) {
      System.out.println(book);
    }

    bookDao.delete(updBook);
    System.out.println("# delete後");
    for (Book book : bookDao.selectBookList()) {
      System.out.println(book);
    }
    ((ClassPathXmlApplicationContext) ctx).close();
  }
  public static void main(String[] args) {
    Book book = new Book();
    book.setPrice(100.0);
    double memberPrice = book.getMemberPrice(new IntermediateMemberStrategy());
    System.out.println("会员价:" + memberPrice);

    // 匿名内部类
    double memberPrice2 =
        book.getMemberPrice(
            new MemberStrategy() {
              @Override
              public double memberPrice(double price) {
                return price * 0.2;
              }
            });
    System.out.println("高级会员:" + memberPrice2);
  }
Exemple #7
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();
  }