zoukankan      html  css  js  c++  java
  • 【笔记】Eclipse and Java for Total Beginners—016

    Lesson 16 – Create main Method and JAR File

    • Introduce main method
    • Write a main method
    • Run MyLibrary as Java application
    • Export to JAR file and run from Windows

    在MyLibrary.java里添加main method。

    1 public static void main(String[] args) {
    2 // create a new MyLibrary
    3   MyLibrary testLibrary = new MyLibrary("Test Drive Library");
    4 Book b1 = new Book("War and Peace");
    5 Book b2 = new Book("Great Expectations");
    6 b1.setAuthor("Tolstoy");
    7 b2.setAuthor("Dickens");
    8 Person jim = new Person();
    9 Person sue = new Person();
    10 jim.setName("Jim");
    11 sue.setName("Sue");
    12
    13 testLibrary.addBook(b1);
    14 testLibrary.addBook(b2);
    15 testLibrary.addPerson(jim);
    16 testLibrary.addPerson(sue);
    17
    18 System.out.println("Just creat new library");
    19 testLibrary.printStatus();
    20
    21 System.out.println("Check out War and Peace to Sue");
    22 testLibrary.checkOut(b1, sue);
    23 testLibrary.printStatus();
    24
    25 System.out.println("Do some more stuff");
    26 testLibrary.checkIn(b1);
    27 testLibrary.checkOut(b2, jim);
    28 testLibrary.printStatus();
    29
    30 }
    31
    32 private void printStatus() {
    33
    34 System.out.println("Status Report of MyLibrary \n" +
    35 this.toString());
    36 for (Book thisBook : this.getBooks()) {
    37 System.out.println(thisBook);
    38
    39 }
    40
    41 for (Person p : this.getPeople()) {
    42 int count = this.getBooksForPerson(p).size();
    43 System.out
    44 .println(p + " (has " + count + " of my books)");
    45
    46 }
    47 System.out.println("Books Available: "
    48 + this.getAvailableBooks().size());
    49 System.out.println("--- End of Status Report ---");
    50
    51
    52 }

  • 相关阅读:
    静态联编和动态联编
    常用Oracle分析函数详解
    Web Service , 不详细的介绍
    Eclipse安装JSEclipse和Spket
    IE中页面不居中,火狐谷歌等正常
    ExtJS3 详解与实践 之 第二章
    IPV6正则
    很漂亮、兼容火狐的Js日期选择,自动填充到输入框
    使用googlecodeprettify高亮显示网页代码
    ExtJS3 详解与实践 之 第三章
  • 原文地址:https://www.cnblogs.com/halflife/p/2079756.html
Copyright © 2011-2022 走看看