在二十多歲的最後一年,決定再讓自己任性一回,開始在 CMoney 參加工程師培訓營,給自己半年,花費全部的心力在"寫程式"這件我一直都很有興趣的事情上。理工背景出生的我對於程式並不陌生,但多半是硬刻出一個可以運作的工具,一直很想要利用上班之餘的時間多深入些什麼,零碎的時間和人性的懶惰也常常讓這事拖延。
從零開始學程式,但我們的戰鬥其實是從物件導向開始!第一週的複習週一點也不手軟,很驚喜的發現同學們也都卯足了全力,幾位程式小白們透過自學也都如火如荼的跟上進度。有一群抱有同樣熱情的夥伴們一起努力,實在很幸運,那就開始記錄這一週忙碌的複習工程吧!
圖書館中有數個書架,書架上有數本書,書本有許多出版資訊...
就這樣,我們在浩瀚的書海裡,由淺入深,迷途忘返...
public class Date{
private int year;
private int month;
private int date;
public Date(int year, int month, int date){
setYear(year);
setMonth(month);
setDate(date);
}
public int getYear(){
return year;
}
public void setYear(int year){
this.year = year;
}
public String toString(){
int i = getYear()*10000 + getMonth()*100+ getDate();
return ""+i;
}
public int getMonth(){...}
public void setMonth(int month){...}
public int getDate(){...}
public void setDate(int date){...}
}
public class Book{
private String bookName;
private Date publishDate;
private String writer;
public Book(String name, Date date, String writer){...}
public String getBookName(){...}
public void setBookName(String bookname){...}
...
public void bookString(){
String info = Stirng.format("%-15s\t%-10s\t%s",
getBookName(),getWriter(),getDate().toString);
return info;
}
}
public class BookShelf{
private int serial;
private Sting index;
private int bookMax;
private int bookCount;
private Book[] books;
public BookShelf(int serial, String index, int bookMax){
setSerial(serial);
...
bookCount = 0;
books = new Book[bookMax];
}
public int getSerial(){...}
public void setSerial(int serial){...}
...
public void addBook(Book book){
if(bookMax == bookCount){
return;
}
books[count++] = book;
}
public Book findByName(String bookName){
for(int i = 0; i < count; i++){
if(books[i].getBookName.equals(bookName)){
return books[i];
}
}
return null;
}
public void modifyByName(String bookName,
String newBookName, String newWriter, Date newDate){
Book book = findByName(name);
if(book != null){
book.setBookName(newBookName);
...
return;
}
return;
}
public String bookShelfString(){
...
}
}
public class Lirary{
private BookShelf[] bookShelfs;
private int bsCount;
public BookShelf[] getBookShelfs(){...}
...
public Library(){
bookShelfs = new BookShelf[2];
bsCount = 0;
}
private void doubleBookShelfs(BookShelf[] arr){
BookShelf[] newArr = new Bookshelf[arr.length *2];
for(int i = 0; i < arr.length; i++){
newArr[i] = arr[i];
}
arr = newArr;
}
public void addBookShelf(BookShelf bookshelf){
if(bsCount == bookshelfs.length){
doubleBookShelfs(bookshelfs);
}
bookshelfs[bsCount++] = bookshelf;
}
}
public class Lirary{
public Library findByIndex(String index){
Lirary found = new Lirary()
for(int i = 0; i < bsCount; i++)
if(bookShelfs[i].getIndex().equals(index)){
found.addBookShelf(bookShelfs[i]);
}
}
return found;
}
public void addBook(String index, Book book){
Lirary found = findByIndex(index);
if(found.getBsCount() != 0){
for(int i = 0; i <= found.getBsCount(); i++){
if(found.getBookShelfs()[i].bookCount <
found.getBookShelfs()[i].bookMax){
found.getBookShelfs()[i].addBook(book);
return;
}
}
System.out.println("書櫃已滿");
return;
}
System.out.println("輸入錯誤");
}
}