Eclipse and Java for Total Beginners

Tutorial Companion Document

Eclipse And Java For Total Beginners
Companion Tutorial Document
By Mark Dexter

Table of Contents
Introduction.........................................................................................................................................2
Tutorial Target Audience.....................................................................................................................2
Tutorial Objectives..............................................................................................................................2
Why learn Java with Eclipse?.............................................................................................................3
Topics Covered...................................................................................................................................3
Tutorial Approach................................................................................................................................3
Getting The Most From This Tutorial..................................................................................................3
Sample Java Application – Personal Lending Library........................................................................4
Downloading and Installing Eclipse ...................................................................................................4
Playing the Lessons............................................................................................................................5
Re-Sizing the Video........................................................................................................................5
Closed Captions and Lesson Table of Contents............................................................................5
Lesson Outlines..................................................................................................................................6
Lesson 1 – Create Your First Java Class.......................................................................................6
Lesson 2 – Add Methods To Class.................................................................................................6
Lesson 3 – Use Eclipse Scrapbook................................................................................................6
Lesson 4 – JUnit Testing in Eclipse, Part 1....................................................................................6
Lesson 5 – JUnit Testing Continued...............................................................................................7
Lesson 6 – Using Test-First Development in Eclipse.....................................................................7
Lesson 7 – Create Book Class.......................................................................................................7
Lesson 8 – Add Person to Book Class...........................................................................................7
Lesson 9 – MyLibrary Class and ArrayList.....................................................................................7
Lesson 10 – Start on MyLibrary Class...........................................................................................7
Lesson 11 – Create first methods in MyLibrary class.....................................................................8
Lesson 12 – Create checkOut, checkIn Methods..........................................................................8
Lesson 13 – Continue checkOut Method.......................................................................................8
Lesson 14 – Finish checkOut Method............................................................................................8
Lesson 15 – Finish MyLibrary Methods..........................................................................................8
Lesson 16 – Create main Method and JAR File.............................................................................9
Alphabetical Index by Lesson.............................................................................................................9
Glossary of Terms.............................................................................................................................12
Copyright © 2007 Mark Dexter. Licensed under the Educational Community License version 1.0.

Page 1 of 45

Eclipse and Java for Total Beginners
Tutorial Companion Document
Additional Resources........................................................................................................................14
Eclipse Websites..........................................................................................................................15
Java Websites...............................................................................................................................15
Java Books...................................................................................................................................15
Code Snapshots...............................................................................................................................15
Lesson 1 – Person class (fields and constructor)........................................................................15
Lesson 2 – Person class (with get and set methods)...................................................................16
Lesson 3 (scrapbook snapshots)..................................................................................................17
Lesson 5 – PersonTest class........................................................................................................17
Lesson 6 – Added toString() Method to Person class..................................................................18
Lesson 7 – TestBook and Book Classes......................................................................................20
Lesson 8 – Add Person to Book Class.........................................................................................21
Lesson 9 – MyLibrary Class and ArrayList...................................................................................23
Lesson 10 – Start on MyLibrary Class.........................................................................................23
Lesson 11 – Create first methods in MyLibrary class...................................................................24
Lesson 12 – Create checkOut, checkIn Methods........................................................................27
Lesson 13 – Continue checkOut Method.....................................................................................31
Lesson 14 – Finish checkOut Method..........................................................................................33
Lesson 15 – Finish MyLibrary Methods........................................................................................35
Lesson 16 – Create main Method and JAR File..........................................................................41

Introduction
This document is designed to accompany the “Eclipse And Java For Total Beginners” video tutorial,
which is available at http://eclipsetutorial.sourceforge.net/.

Tutorial Target Audience
This tutorial is targeted for people who are new to Eclipse and to Java. It is designed to work either
for those with prior programming experience in other languages or for those without prior experience.

Tutorial Objectives
The objectives of this tutorial are as follows:

Demonstrate the basics of using Eclipse for writing Java programs

Demonstrate how to use Eclipse for agile software development

Demonstrate how to use existing Java learning resources (tutorials, examples, books) within
Eclipse

Create a foundation for continuing to learn Java and Eclipse

Note that Java and Eclipse are both large subject areas that cannot possibly be mastered in a short
period of time. This tutorial will help get you started and give you some of the skills needed to learn
on your own.
Copyright © 2007 Mark Dexter. Licensed under the Educational Community License version 1.0.

Page 2 of 45

Eclipse and Java for Total Beginners
Tutorial Companion Document

Why learn Java with Eclipse?
There are many ways to learn how to program in Java. The author believes that there are
advantages to learning Java using the Eclipse integrated development environment (IDE). Some of
these are listed below:

Eclipse provides a number of aids that make writing Java code much quicker and easier than
using a text editor. This means that you can spend more time learning Java, and less time
typing and looking up documentation.

The Eclipse debugger and scrapbook allow you to look inside the execution of the Java code.
This allows you to “see” objects and to understand how Java is working behind the scenes

Eclipse provides full support for agile software development practices such as test-driven
development and refactoring. This allows you to learn these practices as you learn Java.

If you plan to do software development in Java, you’ll need to learn Eclipse or some other IDE.
So learning Eclipse from the start will save you time and effort.

The chief concern with learning Java with an IDE is that learning the IDE itself will be difficult and will
distract you from learning Java. It is hoped that this tutorial will make learning the basics of Eclipse
relatively painless so you can focus on learning Java.

Topics Covered
This tutorial will cover the following topics:

Basics of Eclipse for Java development

Basics of Java and object-oriented programming (OOP)

Test-driven development (TDD) and unit testing in Eclipse

Tutorial Approach
The tutorial is organized around the following activities.

Write a small sample Java application to track your personal lending library.

Use the “test-first” approach to develop most methods.

Write a “test drive” program and create an executable JAR file, and run the JAR file from the
system console.

Concepts are introduced as needed during the development of the sample applications.

Getting The Most From This Tutorial
This tutorial can be used as an in-depth demonstration of Java development in Eclipse. However, if
you want to actually learn how to write Java programs in Eclipse, the following approach is
recommended:

Copyright © 2007 Mark Dexter. Licensed under the Educational Community License version 1.0.

Page 3 of 45

Eclipse and Java for Total Beginners
Tutorial Companion Document

Have Eclipse installed and ready to go.

Work side-by-side with the lessons, pausing and rewinding as needed.

Use this guide as needed.

Consult other resources as needed to understand the topics covered in greater depth.

Keep a positive attitude!

Sample Java Application – Personal Lending Library
We will develop a small sample application to track our personal library of books. It will also include a
list of people to whom we loan our books. The application will have three Java classes:
1. Person will have fields for the person's name and a number which will be the maximum
number of books this person can borrow at one time.
2. Book will have fields for title, author, and the person who is currently borrowing the book.
3. MyLibrary will contain a list of all of our books and a list of all of the people who might borrow
them.

Downloading and Installing Eclipse
Before Installing Eclipse, you need to have either the Java JDK (Java development kit) or Java JRE
(Java runtime engine) installed on your computer. These are available at
http://java.sun.com/javase/downloads/index.jsp.
Installing the JDK or JRE is reasonably simple. Detailed, step-by-step instructions, if needed, are
available in the PDF Eclipse Tutorial at the
https://www.arctechsoftware.com/tutorial/welcomePage.do. (Follow the link to “Beginning Eclipse”.)
For Java development, the JDK is recommended because it allows you to see documentation and
source code for the standard Java classes. However, either the JDK or JRE will work for this tutorial.
This tutorial is based on Eclipse 3.3, although you could use 3.2 and probably later versions as well.
Here are the steps to install Eclipse 3.3 from www.eclipse.org:

Navigate to www.eclipse.org/downloads

Select “Eclipse IDE for Java Developers”. If your platform is Linux or MacOSX, be sure to
select the link to the right. Note that you can use “Eclipse IDE for Java EE Developers”,
“Eclipse for RCP/Plug-in Developers”, or “Eclipse Classic” as well. All of these include the Java
development portions of Eclipse used in this tutorial.

On the www.eclipse.org/downloads page, follow the link “Find out more”. Scroll your browser
to display the far right-hand side of the screen to the column “Tutorials and Help”. The first
tutorial is a Screencam tutorial that steps you through downloading and installing Eclipse on
Windows.

The Eclipse installation is very straightforward. There is no installation program. Instead, you just
create the top-level folder and the unzip the file inside this folder. In Windows XP, for example, just
Copyright © 2007 Mark Dexter. Licensed under the Educational Community License version 1.0.

Page 4 of 45

Open this file with your browser (e. A slide control allows you to fast-forward or rewind the video to any point in time. The Eclipse programs will be created in several subfolders (configuration. Playing the Lessons To play the lessons. Closed Captions and Lesson Table of Contents The audio track of each lesson can be accompanied by closed captions (subtitles). plugins.html). Internet Explorer or Firefox) and press the large play button on the video thumbnail. Controls for the video are below the video. “C:\”) and then unzip the downloaded zip file.0. making it larger or smaller. The controls are shown above. 5. This will create a folder called “C:\eclipse”. which display in the lower portion of the video.com/products/flashplayer/.adobe. Page 5 of 45 . click on the Table of Contents icon in the lower right corner of the video. 2. you can open the file “lessonxx. The procedure for Linux is similar. Table of Contents. Copyright © 2007 Mark Dexter. except your unzip the . Download the 16 lesson zip files (totalbeginnerlessonxx.html”. Unzip each lesson's zip file into a directory on your system. To access the table of contents. Find the file called “lessonxx.tar.. Each lesson also contains a table of contents that allows you to jump to a specified point inside the video. follow these steps.g. Press the “CC” button in the lower right corner to toggle them on and off. 3. Note that you need to have the Adobe Flash player installed on your system. Re-Sizing the Video Alternatively. Note that playing the video from the lessonxx. This can be downloaded from Adobe at http://www. Licensed under the Educational Community License version 1. readme).Eclipse and Java for Total Beginners Tutorial Companion Document copy the zip file to your root directory (e. In Windows Internet Explorer you might get a security warning and need to click and select “Allow blocked content”.zip).swf” with your browser.html file will provide the clearest rendition of the video but does not allow resizing.. and Closed Captions are in the lower right corner. A Pause/Play button is in the lower left corner. you can resize the video to any desired size. 4.gz file. Next to the Table of Contents control is the Volume control. 1. where xx is the lesson number 01-16.swf file directly (as opposed to lessonxx. The lesson should play inside the browser. features.g. If you open the lessonxx. Controls for Volume.

and getMaximumBooks  Static methods Lesson 6 – Using Test-First Development in Eclipse  Use test-first approach to write the Person toString() method  Method overriding Copyright © 2007 Mark Dexter. getName. statements  Discuss Java packages  Create Person object in Scrapbook Lesson 4 – JUnit Testing in Eclipse. Licensed under the Educational Community License version 1.Eclipse and Java for Total Beginners Tutorial Companion Document Lesson Outlines Lesson 1 – Create Your First Java Class  Create Java project in Eclipse  Create Java package  Discuss the Lending Library Application  Introduce classes and objects. naming conventions  Write a simple Java class (Person) Lesson 2 – Add Methods To Class  Introduce Eclipse Views and Perspectives  Introduce Eclipse user interface – drag / drop. Page 6 of 45 . context menus.0. help  Add get and set methods to Person class Lesson 3 – Use Eclipse Scrapbook  Introduce Eclipse Scrapbook  Introduce Java expressions. Part 1  Create test source folder  Create PersonTest class  Run first JUnit test Lesson 5 – JUnit Testing Continued  Test Person class – part 2  Create test methods for constructor.

in a collection?  MyLibrary object to hold Person & Entry objects  Introduce ArrayList in scrapbook  Introduce Java Generics  Method chaining Lesson 10 – Start on MyLibrary Class  Create MyLibraryTest JUnit test  Create testMyLibrary to test MyLibrary constructor  Create MyLibrary constructor  Introduce instanceof operator  Introduce assertTrue method Lesson 11 – Create first methods in MyLibrary class  Create test method for addBook.Eclipse and Java for Total Beginners Tutorial Companion Document  Field Hiding Lesson 7 – Create Book Class  Create BookTest before creating Book class  Test Book constructor  Create get and set methods Lesson 8 – Add Person to Book Class  Create a relationship between the Book class and the Person Class  Test getPerson method  Create JUnit Test Suite Lesson 9 – MyLibrary Class and ArrayList  How can we hold books.0. removeBook methods and test  Create addPerson. etc. checkIn Methods  Create test for checkOut. removeBook methods  Create addBook. removePerson methods  Introduce Eclipse refactoring – move local variable to field Lesson 12 – Create checkOut. checkIn methods Copyright © 2007 Mark Dexter. Licensed under the Educational Community License version 1. Page 7 of 45 .

............ checkIn methods  Fix compiler error – misplaced {}  Add test for maximum books  Create test for getBooksForPerson() method  Refactoring – extract method Lesson 14 – Finish checkOut Method  Write getBooksForPerson method  Introduce “for each” loop  Introduce logical and operator “&&”  NullPointerException errors  Complete checkOut Method Lesson 15 – Finish MyLibrary Methods  Create test for getAvailableBooks  Create getAvailableBooks  Create getUnavailableBooks 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 Alphabetical Index by Lesson Topic Lesson addBook() method.................................Eclipse and Java for Total Beginners Tutorial Companion Document  Write checkout method  Introduce if / then / else syntax  Introduce boolean method  Write checkIn method Lesson 13 – Continue checkOut Method  Test checkOut............................11 Copyright © 2007 Mark Dexter.... Licensed under the Educational Community License version 1.0............... Page 8 of 45 .............................

....... Licensed under the Educational Community License version 1....................................................... ArrayList................................................................................2 getUnavailableBooks() method...... Java........................... Eclipse Wizard.......................................................................................................................................................................... Eclipse scrapbook......................................................................................................1 for each loop.......................................................................... toggle in-line comments.....................12 indexOf() method..................................... Page 9 of 45 ..............................................................................................................................4 ArrayList<> class................................................................... highlighting in Eclipse....................................................................................................1 constructor (Java)..................................................13 CTRL+Space – code assist........................................................................................................14 executable JAR file..................................................................................................................................................... Eclipse wizard.........................................................1 code assist (CTRL+Space)........................2 equals method for Strings (vs.....................16 execute button..........................................................................2 code assist template.....1 Convert Local Variable to Field........14 getter methods.......9 assertEquals() method .....................15 if then statement .............................9 inspect button.................................................................4 capitalization in Java...............................................................2 Generics feature................16 expressions.........................3 Eclipse user interface.........................11 agile software development.............................7 boolean type.... == operator)........................................................................................................................................14 Generate Getters and Setters Wizard.......................................................................................................................................................................................15 getBooksForPerson() method.................................................................10 build path..........................2 comments: in-line (//).....................................................................2 curly brace.......................................................................4 fields (class).....................................................................................................................................................................................9........2 Eclipse scrapbook.............................................................................................................................................................................................12 class (Java).............10 Book class..........................10 JAR archive file............................................................................................................................3 extends keyword.........................................................................................................................................................................................................................................................16 java -jar command.............................................................16 Copyright © 2007 Mark Dexter..........................................................3 Export to Java Archive (JAR) file............................................................1 checkOut() method...............................................................................................................................................................................................................................................................................................................................................................................................................................................Eclipse and Java for Total Beginners Tutorial Companion Document addPerson() method......................................................................................................................................3 instanceof operator......................................................... 10 get() method........................................................................................4 extreme programming......................................................13 Eclipse code assist (CTRL+Space)................... ArrayList...................................................................5 assertTrue() method..................................11 CTRL+/........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................2 Eclipse Explorer class view...............................................................................................................................................................................0......................................... Eclipse scrapbook.................................................8 CTRL+Shift+P – find matching curly brace........................................................................................................................................................................................................................................9 getAvailableBooks() method ...

................................................................................................................................ Eclipse.................................................................................................8 Quick fix (CTRL+1)...........................................................................................................7 test method as specification .........................................................1 packages......................................................................................................................................................................................................... create new...........5 JUnit View...................................6 package-protected access modifier................................................. Java....................................................................................................16 private access modifier..............................................................................................................................14 Object class.......................... Java........................................2 setup() method.............................................................................2 printStatus() method....................................................................... in test-first development.................................................................................................................... create ......................................................................................................................................11 Source folder.................................................................................... Page 10 of 45 ....................................................................................................................................................................................................................................................................................... create new......................................................................................................................................................................5 test suite......6 test method..................................................................................................11 scrapbook...................................................................6 Copyright © 2007 Mark Dexter.....16 new keyword............... JUnit test class..................................................... method .....jar file...................................Eclipse and Java for Total Beginners Tutorial Companion Document JUnit test class..................4 Quick fix (CTRL+1).................................................................................................. compare actual with expected....................................................................................................................................................4 JUnit test.................................................................................................................3 Task view.............4 superclass... in Java ..............................................................................................................................................................................................3 object dependency........................................................................................ Eclipse........................println() command............3 NullPointerException..........0........................................................................................................10 package................3 setter methods....... set imports button....................................................................................................2 MyLibrary class..........4 JUnit test library.........................................................................................................................................................................................................................................................................................................4 System............................................................................. creating..........1 perspective (Eclipse)...................................................................................................10 mylibrary............................................................................7 Refactor Menu.............................................................5 subclass .......8 object equality........................... Licensed under the Educational Community License version 1..................................................................................................................................11 removeBook() method............out....................................................................................................................................................................16 methods (class)............................................11 removePerson() method.....................8 override.................................................................. JUnit............................................. running..............................5 JUnit.........................................................................................................................................................................................................................................................................................................................................................................................................4 statements.............................3 scrapbook...................................................................8 test-driven development (TDD)......................................................................... TODO comments...............................................................................................1 main() method.............................................. creating............................................5 lending library application................................................................................................2 static methods.......1 public access modifier...........3 Person class................................................................................................6 test-first development............8 project....

........2 welcome screen (Eclipse)....................15 testGetBooksForPerson() method ................2 workbench regions....................................................................................................................................................................................................................................................... task list..........................................................................................................................13 testGetUnavailableBooks() method.............................................. 6 TODO comment.....................................................................................................6 unit test.......................2 != operator (not equal to)..7 testCheckOut() method ....................................................................2 && operator (and operator)...........................12 testGetAvailableBooks() method.........................................................................................2 /* */ comments.........................................................................................................................................................................................................14 == operator (equals).......................................................15 this keyword.............4 view (Eclipse).................................................................................................................................................................................................. semicolon................................................................0....................2.....................................1 .......................................................................................................................................12 Copyright © 2007 Mark Dexter........ Licensed under the Educational Community License version 1...................................................Eclipse and Java for Total Beginners Tutorial Companion Document testBook() method ... Page 11 of 45 ...........12 ( ) parentheses..........................................................................................................................................................................................................................................................................................2 workspace (Eclipse)..........................................................................2 { } curly braces................................................................................7 toString() method .......................................................................................................................................................................................................................................... in Java....................................................................... in Java..................1 workbench (Eclipse).. in Java..............................................

that provides the different tools required to develop a software package. Copyright © 2007 Mark Dexter. These contain the instructions used by the JVM to actually run the programs on a Windows PC. etc. Used with the “new” keyword (e. like Eclipse. Usually marked private so that other programs cannot directly access. unit testing as part of development process. Contains members. only this class. like a subroutine or function in other languages). Control whether classes and members may be accessed from any class. if you prefer. Method Member in a class that does some processing (e. Licensed under the Educational Community License version 1. Person p = new Person() calls the Person() constructor). including fields and methods.g.. JUnit Test A Java class used to test individual methods in a class.. “private”. age. Classes are the “blueprint” for creating objects. a Linux computer. etc.class files.g. Field Member in a class that holds data (e. Page 12 of 45 .g. IDE (Integrated Development Environment) Program. Used to build test cases. e. subclasses. API (Application Programming Interface) The way one program uses another program. an object whose type is the class).g. name. Default is access from any class in the package. a Mac computer. JVM (Java Virtual Machine) (also known as Java Runtime Engine or JRE) The program that runs Java programs on a specific platform. Constructor Special block of code used to create an instance of a class (or.). The JVM is written for each platform supported by Java. when using agile development methodology. “protected” in Java.Eclipse and Java for Total Beginners Tutorial Companion Document Glossary of Terms Term Quick Definition Access Modifier Reserved words “public”.0. among other things. Java source code is compiled into . the API can be thought of as the collection of public methods for a class or package. Agile (or Extreme) Development Methodology for developing software that emphasizes. Class Main building block in Java.. In Java..

in the method public setName(String name) {…} “name” is the parameter for this method. have the same name but different signatures)..g. Package Packages are imported into a source file to save typing the full name of the class (e. this method is said to be overridden. Licensed under the Educational Community License version 1. When you invoke a method. “thisCookie”) would be an object created using the class. Each package can contain multiple classes. can say “Person” instead of “org. String lastName) could be an overload of “setName(String name)” because it as a different signature (“setName(String. Copyright © 2007 Mark Dexter. Method Parameters refers to the list of variables in a method declaration.setName(“Fred”). same name but different signatures)..e.Eclipse and Java for Total Beginners Tutorial Companion Document Term Quick Definition Method Argument. If this method is used as follows: myObject. Method signatures are important because they allow methods to be overloaded (i.g. Project In Eclipse. In other words. For example. For example. Object An instance of a class. For example. Parameter Arguments are the actual values that are passed in when the method is invoked.0. Method Signature A method’s name plus it’s parameter list. Page 13 of 45 . Overload (Method) To provide multiple methods with the same name but different parameters (i. Override (Method) When a subclass implements a method inherited from the super class. “Fred” is the argument of the method and it must match the type of the method’s parameter.eclipsetraining.Person” and to avoid the possibility of two classes having identical names. For example. An Eclipse workspace can contain multiple projects.librarytutorial. “thisCookie” is an object of type Cookie or an instance of Cookie. a way to organize your work. Each project can contain multiple packages. Cookie could be a class. String)”). and a cookie (e. a method defined as “setName (String name)” has a method signature of “setName(String)”. the arguments used must match the declaration's parameters in type and order.. the method “setName(String firstName.e.

Points to an area on the “heap” where the object resides.Eclipse and Java for Total Beginners Tutorial Companion Document Term Quick Definition Refactor To improve a program without changing the way it works (i. Invoked with <Class>. Swing A set of standard Java packages that implement a graphical user interface without using any “native” code.).. These are just a few that I’ve found helpful. Used for methods that don’t rely on any one instance of a class. Holds multiple projects. For objects. Scrapbook Page Area in Eclipse where you can execute Java code “snippets” and see how they work. Value Variable In Java.getTotalCount()). only one workspace can be active. an attribute of a variable to indicate either a primitive type (int. Type In Java. streamlining code.. Workspace Top-level container for Eclipse work.g. Reference Variable In Java. Types also include interfaces and enumerations. the type is the class to which it belongs.g. Example include renaming fields or variables. etc.). Very important in agile development because of emphasis on self-documenting code. Used to create the Eclipse IDE.. SWT (Standard Widget Toolkit) Set of Java classes and native programs developed by Eclipse to allow Java programs to have the look and feel of native programs on each platform. Copyright © 2007 Mark Dexter. its API). Contrast with reference variable.0. boolean. Held in the memory stack.. variable that holds the value of a Java primitive (e. etc. character. integer. Static Method A method that belongs to the entire class instead of one instance of the class.g. Page 14 of 45 . Person. Licensed under the Educational Community License version 1. Great for experimenting with Java statements. p = new Person().) or class membership. Additional Resources There are many resources available for learning more about Eclipse and Java. etc. In a single Eclipse session. variable that holds an object reference (e.<Method> (e.e. Contrast with value variable.

arctechsoftware. Code Snapshots The following pages contain code snapshots as of the end of each lesson.newcomer newsgroup. Concise book documents specific recommendations for Java best practices.javaranch.exampledepot.0. demonstrations and other resources on a variety of topics related to Eclipse.4 (http://www. with knowledgeable moderators.com/tutorial/tutorial. and many other Java topics. if you want to start the tutorial in the middle. Link to home page is https://www. creative book for Java and OOP beginners. Written tutorial to get you started with Eclipse and Java. since there is a good chance that your question has already been asked and answered. Also.  Beginning Eclipse Tutorial on ArcTech Software LLC website.arctechsoftware. The gold standard for learning Java. This is a friendly.com/tutorial/welcomePage. by Kathy Sierra & Bert Bates.html). The search feature of this and other newsgroups can be especially valuable. active newsgroup where newcomers to Eclipse can ask questions.  JavaRanch Big Moose Saloon web site (http://saloon. books.com/). Licensed under the Educational Community License version 1. If needed. It has a very good section on downloading and installing the Java JDK. Java Books  Head First Java.Eclipse and Java for Total Beginners Tutorial Companion Document Eclipse Websites  www. Login required to download. Java in General (intermediate). presentations.com/cgibin/ubb/ultimatebb. Contains Java code samples for many topics.com/docs/books/tutorial/java/index. including Java in General (beginner). Page 15 of 45 . Lesson 1 – Person class (fields and constructor) Copyright © 2007 Mark Dexter. Java Websites  The Java Tutorials from Sun (http://java.  Effective Java. and it’s free.do?subcatId=1.eclipse. This has a variety of forums. Link to tutorial is https://www.sun. by Bruce Eckel. These can be used to compare your code to or to help you fix any problems you might have. you can copy and past this code into your Eclipse Java source files. fun. For all levels of programmer.org/resources.  Thinking In Java. thorough reference for Java.cgi?category=1). For intermediate to advanced programmers. these can help you catch up to the correct point. Excellent.  The Java Developers Almanac 1.  eclipse. Very active and friendly. Excellent.do. by Joshua Bloch. This lists a number of articles.

} //methods public String getName() { return name. } } Lesson 2 – Person class (with get and set methods) Note: Highlighted code added in this lesson. // name of the person private int maximumBooks. Licensed under the Educational Community License version 1. } public int getMaximumBooks() { Copyright © 2007 Mark Dexter. // name of the person private int maximumBooks. maximumBooks = 3. maximumBooks = 3. // most books the person can check out // constructors public Person() { name = "unknown name".tutorial.Eclipse and Java for Total Beginners Tutorial Companion Document package org. } public void setName(String anyName) { name = anyName. package org.0.totalbeginner. public class Person { // fields private String name. // most books the person can check out // constructors public Person() { name = "unknown name".totalbeginner. Page 16 of 45 .tutorial. public class Person { // fields private String name.

setName(“Fred”). Copyright © 2007 Mark Dexter.getName()). p1. public class PersonTest extends TestCase { public void testPerson() { Person p1 = new Person(). import junit. a = a * 10. Page 17 of 45 . Licensed under the Educational Community License version 1.Eclipse and Java for Total Beginners Tutorial Companion Document return maximumBooks.totalbeginner.*) Person p = new Person(). a (after import of org.framework.maximumBooks = maximumBooks. } } Lesson 3 (scrapbook snapshots) Expressions: 2 + 2 int a = 5.tutorial.0. P Lesson 5 – PersonTest class package org.tutorial. assertEquals("unknown name". } public void setMaximumBooks(int maximumBooks) { this.TestCase.totalbeginner. p.

p1. p3. Page 18 of 45 .getMaximumBooks()). } Copyright © 2007 Mark Dexter. public class Person { // fields private String name. p2.Eclipse and Java for Total Beginners Tutorial Companion Document assertEquals(3. } } Lesson 6 – Added toString() Method to Person class Note: Person and PersonTest classes are complete at this point. } //methods public String getName() { return name. } public void testSetMaximumBooks() { Person p3 = new Person().setName("Fred"). p2.0. // name of the person private int maximumBooks. package org.getName()). } public void testSetName() { Person p2 = new Person().totalbeginner. maximumBooks = 3.getMaximumBooks()). // most books the person can check out // constructors public Person() { name = "unknown name". assertEquals("Fred". } public void setName(String anyName) { name = anyName. p3.tutorial. Licensed under the Educational Community License version 1. assertEquals(10.setMaximumBooks(10).

} public void testSetMaximumBooks() { Person p3 = new Person(). } public String toString() { return this.getName()).getMaximumBooks()). } public void setMaximumBooks(int maximumBooks) { this. p2. assertEquals(10.getMaximumBooks()). assertEquals(3.setName("Fred").totalbeginner. p3.setName("Fred Flintstone"). assertEquals("unknown name". public class PersonTest extends TestCase { public void testPerson() { Person p1 = new Person().setMaximumBooks(10). Page 19 of 45 .Eclipse and Java for Total Beginners Tutorial Companion Document public int getMaximumBooks() { return maximumBooks. } public void testToString() { Person p4 = new Person().0.maximumBooks = maximumBooks. p1. assertEquals("Fred". p3. } public void testSetName() { Person p2 = new Person().tutorial.getMaximumBooks() + " books)". p4. import junit. p1.framework. } } package org. Licensed under the Educational Community License version 1.getName() + " (" + this. Copyright © 2007 Mark Dexter.getName()). p2.TestCase.

toString()).setMaximumBooks(7). this. } } package org.author).author = "unknown author". Page 20 of 45 . assertEquals("Great Expectations".tutorial. public class BookTest extends TestCase { public void testBook() { Book b1 = new Book("Great Expectations").framework. assertEquals(testString. String testString = "Fred Flintstone (7 books)". } Copyright © 2007 Mark Dexter. b1.Eclipse and Java for Total Beginners Tutorial Companion Document p4. } } Lesson 7 – TestBook and Book Classes package org. public class Book { String title.tutorial.totalbeginner.title = string. p4. assertEquals("unknown author". public Book(String string) { this. Licensed under the Educational Community License version 1.title).0.TestCase. } public String getAuthor() { return author.totalbeginner. String author. b1. import junit.

Person person. Licensed under the Educational Community License version 1. } public String getTitle() { return title. public class AllTests { public static Test suite() { TestSuite suite = new TestSuite("Test for org.tutorial.Eclipse and Java for Total Beginners Tutorial Companion Document public void setAuthor(String author) { this. import junit. Page 21 of 45 .author = author. //$JUnit-END$ return suite.totalbeginner.class).tutorial.TestSuite.totalbeginner. import junit.framework.framework.addTestSuite(PersonTest. } } Lesson 8 – Add Person to Book Class Note: BookTest and Book classes are complete at this point.0. package org.totalbeginner. //$JUnit-BEGIN$ suite. Copyright © 2007 Mark Dexter. } } package org. String author.class).addTestSuite(BookTest. suite. public class Book { String title.tutorial").Test.

} public void setPerson(Person p2) { this. } public void setAuthor(String author) { this.author = "unknown author".Eclipse and Java for Total Beginners Tutorial Companion Document public Book(String string) { this. } } package org.person. } public String getTitle() { return title.title).author). } public void testGetPerson() { Copyright © 2007 Mark Dexter. Page 22 of 45 . assertEquals("unknown author". Licensed under the Educational Community License version 1. } public String getAuthor() { return author.title = string.TestCase.tutorial.0.person = p2. public class BookTest extends TestCase { public void testBook() { Book b1 = new Book("Great Expectations"). this. import junit.author = author. assertEquals("Great Expectations". b1. b1.framework. } public Person getPerson() { return this.totalbeginner.

Person p2 = new Person().setName("Elvis"). // method to say book is loaned to this person b2. Page 23 of 45 .setPerson(p2).add(b1). testName). Book b1 = new Book("Great Expectations"). assertEquals("Elvis".setName("Fred").add(b2). // // String testName = b2. Copyright © 2007 Mark Dexter.setPerson(p1). Book b2 = new Book("War and Peace"). if needed use the Person and PersonTest classes from Lesson 6 and the Book and BookTest classes from Lesson 8. } } Lesson 9 – MyLibrary Class and ArrayList Scrapbook Example ArrayList<Book> list = new ArrayList<Book>().getPerson(). p2. package org. list.0. list.Eclipse and Java for Total Beginners Tutorial Companion Document Book b2 = new Book("War And Peace"). Licensed under the Educational Community License version 1. b1.getName().getName().tutorial.getPerson().remove(b1). Person p1 = new Person(). // get the name of the person who has the book Person testPerson = b2. list Lesson 10 – Start on MyLibrary Class Note: From this point on. String testName = testPerson. list. p1.totalbeginner.

util. } } Lesson 11 – Create first methods in MyLibrary class Copyright © 2007 Mark Dexter.name = name.people instanceof ArrayList). ml.name).util.totalbeginner. Page 24 of 45 . public class MyLibrary { String name.TestCase.tutorial. public MyLibrary(String name) { this. books = new ArrayList<Book>().Eclipse and Java for Total Beginners Tutorial Companion Document import java. import junit. assertTrue(ml. ArrayList<Person> people.books instanceof ArrayList).0. assertEquals("Test". ArrayList<Book> books. public class MyLibraryTest extends TestCase { // test constructor public void testMyLibrary() { MyLibrary ml = new MyLibrary("Test").framework. Licensed under the Educational Community License version 1. import java.ArrayList. } } package org. assertTrue(ml. people = new ArrayList<Person>().ArrayList.

private Book b2. p1. ml. assertEquals("Test".Eclipse and Java for Total Beginners Tutorial Companion Document package org. ml.ArrayList. public class MyLibraryTest extends TestCase { private Book b1.addBook(b1).name). private MyLibrary ml. import java. ml = new MyLibrary("Test").framework. p2.0.setName("Sue"). // test constructor public void testMyLibrary() { MyLibrary ml = new MyLibrary("Test"). private Person p1. ml.getBooks(). p1 = new Person(). Page 25 of 45 . Copyright © 2007 Mark Dexter.tutorial.totalbeginner.util. private Person p2.people instanceof ArrayList).TestCase. Licensed under the Educational Community License version 1. assertTrue(ml. } public void setup() { b1 = new Book("Book1"). b2 = new Book("Book2"). p2 = new Person(). } public void testAddBook() { //create test objects setup(). import junit.size()). assertTrue(ml.setName("Fred").books instanceof ArrayList). //test initial size is 0 assertEquals(0.

addBook(b2). assertEquals(1. Licensed under the Educational Community License version 1. assertEquals(1. assertEquals(0. books = new ArrayList<Book>(). assertEquals(0.totalbeginner.Eclipse and Java for Total Beginners Tutorial Companion Document ml. ArrayList<Person> people.indexOf(b2)). ArrayList<Book> books. } public ArrayList<Book> getBooks() { return books. ml. ml.removeBook(b1). ml. public class MyLibrary { String name. assertEquals(0. people = new ArrayList<Person>().getBooks(). ml. public MyLibrary(String name) { this.indexOf(b1)). ml.util.removeBook(b2).getBooks(). } Copyright © 2007 Mark Dexter. Page 26 of 45 . assertEquals(2.getBooks(). ml. } public ArrayList<Person> getPeople() { return people.getBooks(). } public String getName() { return name.size()).indexOf(b2)). } } package org.size()). ml. ml.size()).getBooks().0.name = name.tutorial. import java.getBooks().ArrayList.

import junit.util. } } Lesson 12 – Create checkOut.name). Copyright © 2007 Mark Dexter.remove(b1).Eclipse and Java for Total Beginners Tutorial Companion Document public void addBook(Book b1) { this.people. import java. // test constructor public void testMyLibrary() { MyLibrary ml = new MyLibrary("Test"). checkIn Methods package org.books.add(p1). public class MyLibraryTest extends TestCase { private Book b1.add(b1). ml. assertEquals("Test".ArrayList. } public void removePerson(Person p1) { this. Licensed under the Educational Community License version 1.framework.totalbeginner. } public void addPerson(Person p1) { this. private Person p2. } public void removeBook(Book b1) { this. private Book b2.remove(p1).0.books. private MyLibrary ml.people.TestCase. private Person p1. Page 27 of 45 .tutorial.

p1. ml.setName("Sue"). assertEquals(0. ml. assertEquals(1.size()). ml = new MyLibrary("Test").size()). assertEquals(0. } public void testAddBook() { //create test objects setup(). } private void addItems() { ml. ml.size()).getBooks(). } public void setup() { b1 = new Book("Book1"). assertEquals(1.books instanceof ArrayList). Copyright © 2007 Mark Dexter. ml.removeBook(b1).getBooks().Eclipse and Java for Total Beginners Tutorial Companion Document assertTrue(ml. p2. assertEquals(2. Page 28 of 45 .0.addBook(b1). Licensed under the Educational Community License version 1.removeBook(b2).getBooks(). ml. ml. ml.addBook(b1). //test initial size is 0 assertEquals(0.getBooks(). ml.getBooks().getBooks().addBook(b2).getBooks().indexOf(b2)). assertTrue(ml. ml. b2 = new Book("Book2").indexOf(b2)).people instanceof ArrayList). assertEquals(0.addPerson(p1).indexOf(b1)). ml. ml.setName("Fred").addBook(b2). p1 = new Person(). ml. ml. p2 = new Person().size()).

getPerson().name = name.p1)). ml.checkOut(b1. b1.checkIn(b1)). books = new ArrayList<Book>(). Licensed under the Educational Community License version 1. public MyLibrary(String name) { this.util. addItems().checkIn(b1)). ml. Copyright © 2007 Mark Dexter.tutorial.checkOut(b1. ml. } public void testCheckOut() { // set up objects setup(). ml. assertFalse("Book was already checked in".totalbeginner. assertFalse("Book was never checked out". Page 29 of 45 .ArrayList. public class MyLibrary { String name.checkIn(b2)).Eclipse and Java for Total Beginners Tutorial Companion Document ml. ArrayList<Person> people. import java. assertTrue("Book check in failed".getName()).0. assertEquals("Fred". ArrayList<Book> books. assertFalse("Book was already checked out".addPerson(p2). ml. } } package org.p2)). assertTrue("Book did not check out correctly".

Eclipse and Java for Total Beginners Tutorial Companion Document people = new ArrayList<Person>().getPerson() != null) { Copyright © 2007 Mark Dexter.people. Person p1) { if ((b1.getPerson() == null) ){ b1. } public ArrayList<Book> getBooks() { return books.setPerson(p1).0.people. } public void removeBook(Book b1) { this. } public void addPerson(Person p1) { this.add(b1). Page 30 of 45 . } else { return false. } public void removePerson(Person p1) { this.books. } public ArrayList<Person> getPeople() { return people.books.add(p1). Licensed under the Educational Community License version 1.remove(p1). } public void addBook(Book b1) { this. } public boolean checkOut(Book b1. return true. } public String getName() { return name.remove(b1). } } public boolean checkIn(Book b1) { if (b1.

people = new ArrayList<Person>().util.ArrayList.tutorial. return true.0. ArrayList<Book> books. } else { return false. } public ArrayList<Person> getPeople() { return people. } public ArrayList<Book> getBooks() { return books. } Copyright © 2007 Mark Dexter. ArrayList<Person> people.Eclipse and Java for Total Beginners Tutorial Companion Document b1. Licensed under the Educational Community License version 1. public class MyLibrary { String name. books = new ArrayList<Book>().totalbeginner. } public String getName() { return name. public MyLibrary(String name) { this.setPerson(null). Page 31 of 45 . } } } Lesson 13 – Continue checkOut Method package org. import java.name = name.

0. Page 32 of 45 . } public boolean checkOut(Book b1. } public void removePerson(Person p1) { this.people. } public ArrayList<Book> getBooksForPerson(Person p1) { // TODO Auto-generated method stub return null. Person p1) { if ((b1.setPerson(p1). } } Copyright © 2007 Mark Dexter.add(p1). return true.add(b1).books.books. } } public boolean checkIn(Book b1) { // TODO Auto-generated method stub return false. } public void addPerson(Person p1) { this.getPerson() == null) ){ b1. } else { return false.people. } public void removeBook(Book b1) { this.remove(b1). Licensed under the Educational Community License version 1.remove(p1).Eclipse and Java for Total Beginners Tutorial Companion Document public void addBook(Book b1) { this.

add(p1).tutorial. Licensed under the Educational Community License version 1.people. } public String getName() { return name. } public ArrayList<Person> getPeople() { return people. people = new ArrayList<Person>(). } public void addPerson(Person p1) { this.books. books = new ArrayList<Book>().Eclipse and Java for Total Beginners Tutorial Companion Document Lesson 14 – Finish checkOut Method package org. ArrayList<Person> people.books. public class MyLibrary { String name. public MyLibrary(String name) { this. } public ArrayList<Book> getBooks() { return books. } Copyright © 2007 Mark Dexter. } public void removeBook(Book b1) { this.remove(b1).name = name.util.add(b1).0.ArrayList. } public void addBook(Book b1) { this.totalbeginner. ArrayList<Book> books. import java. Page 33 of 45 .

} else { return false. } public boolean checkOut(Book b1. Page 34 of 45 . } } return result. for (Book aBook : this.getMaximumBooks()){ b1.0. } } public ArrayList<Book> getBooksForPerson(Person p1) { ArrayList<Book> result = new ArrayList<Book>().setPerson(p1).getPerson(). } else { return false.setPerson(null).getBooks()) { if ((aBook. if ((b1.size(). Licensed under the Educational Community License version 1. return true. return true.Eclipse and Java for Total Beginners Tutorial Companion Document public void removePerson(Person p1) { this.add(aBook).getPerson() != null) && (aBook.getPerson() == null) && booksOut < p1.people. } } public boolean checkIn(Book b1) { if (b1.getBooksForPerson(p1).getPerson() != null) { b1.remove(p1).getName()))) { result. Person p1) { int booksOut = this.getName() . } } Copyright © 2007 Mark Dexter.equals(p1.

Page 35 of 45 .people instanceof ArrayList).0. private MyLibrary ml.name).setName("Sue"). import java. private Book b2.framework.Eclipse and Java for Total Beginners Tutorial Companion Document Lesson 15 – Finish MyLibrary Methods package org. b2 = new Book("Book2"). p2. // test constructor public void testMyLibrary() { MyLibrary ml = new MyLibrary("Test").books instanceof ArrayList).TestCase. } public void testAddBook() { //create test objects setup(). assertTrue(ml. public class MyLibraryTest extends TestCase { private Book b1. p2 = new Person(). Licensed under the Educational Community License version 1. import junit. ml = new MyLibrary("Test").totalbeginner.util. p1.setName("Fred"). p1 = new Person(). } public void setup() { b1 = new Book("Book1"). ml.tutorial.ArrayList. assertEquals("Test". private Person p2. //test initial size is 0 Copyright © 2007 Mark Dexter. assertTrue(ml. private Person p1.

assertEquals(1. ml. addItems().removeBook(b2). ml.size()).indexOf(b2)).getBooks(). assertFalse("Book was already checked out". Page 36 of 45 . ml.p2)). ml. b1.checkIn(b2)).checkIn(b1)).removeBook(b1).setMaximumBooks(1). assertEquals(1. ml.checkIn(b1)).0.getBooks(). } public void testCheckOut() { // set up objects setup(). ml.size()). ml. Licensed under the Educational Community License version 1. ml.getName()).getBooks().checkOut(b1. assertTrue("Book check in failed".indexOf(b2)).size()). ml. // additional test for maximumBooks setup().indexOf(b1)). p1. assertFalse("Book was never checked out".addBook(b1).addBook(b2).getPerson().p1)). assertEquals(0.getBooks(). ml.getBooks(). ml. ml. assertEquals(0. assertEquals(2. assertEquals(0.getBooks(). Copyright © 2007 Mark Dexter.size()). ml. assertEquals("Fred". assertFalse("Book was already checked in". assertTrue("Book did not check out correctly". addItems().getBooks().Eclipse and Java for Total Beginners Tutorial Companion Document assertEquals(0. ml. ml.checkOut(b1. ml.

Eclipse and Java for Total Beginners Tutorial Companion Document assertTrue("First book did not check out". testBooks.addPerson(p1).checkOut(b1. } public void testGetAvailableBooks() { setup(). ArrayList<Book> testBooks = ml. ml. testBooks. ml.getAvailableBooks(). ml. p1)). assertEquals(0. addItems(). p1). testBooks = ml.checkOut(b2. assertEquals(1. assertEquals(0. assertEquals(1.addBook(b1). testBooks. assertEquals(2.getAvailableBooks().size()). } public void testGetBooksForPerson() { setup(). testBooks. ml. assertEquals(1. testBooks. assertFalse("Second book should not have checked out". ml. testBooks = ml. p1)). assertEquals(1. Copyright © 2007 Mark Dexter. p1).indexOf(b2)). Page 37 of 45 .size()). p1). testBooks. addItems(). ArrayList<Book> testBooks = ml. ml.addPerson(p2). assertEquals(2.indexOf(b2)). Licensed under the Educational Community License version 1.size()).checkOut(b2. testBooks.size()).checkOut(b1. ml. } private void addItems() { ml. assertEquals(0.addBook(b2).getBooksForPerson(p1). ml.0.checkOut(b1.indexOf(b2)). testBooks.indexOf(b1)).getBooksForPerson(p1).getBooksForPerson(p1).size()). ml.

} public void testToString() { setup().Eclipse and Java for Total Beginners Tutorial Companion Document ml.size()).size()).util. ml.checkOut(b2.checkOut(b1. p1). Copyright © 2007 Mark Dexter.getUnavailableBooks().size()). testBooks = ml. testBooks.". p2). ArrayList<Book> testBooks = ml. assertEquals(0. ml.getUnavailableBooks(). testBooks = ml. addItems().tutorial. testBooks. Page 38 of 45 .getUnavailableBooks().getAvailableBooks(). ml. assertEquals(1.indexOf(b1)). 2 people. } } package org.toString()). testBooks. p1).ArrayList.indexOf(b2)). import java.checkOut(b2. testBooks. } public void testGetUnavailableBooks() { setup(). assertEquals("Test: 2 books. assertEquals(0. ml. public class MyLibrary { String name.size()). assertEquals(1. assertEquals(2. addItems(). Licensed under the Educational Community License version 1.totalbeginner. assertEquals(0.0. testBooks.

} public String getName() { return name. people = new ArrayList<Person>().getPerson() == null) && booksOut < p1.books. } public boolean checkOut(Book b1.size(). Copyright © 2007 Mark Dexter. public MyLibrary(String name) { this. } public ArrayList<Person> getPeople() { return people. } public void addPerson(Person p1) { this.people. if ((b1.books.setPerson(p1).getBooksForPerson(p1). ArrayList<Person> people. } public void addBook(Book b1) { this. Page 39 of 45 .add(b1).getMaximumBooks()){ b1.0.remove(b1). return true.Eclipse and Java for Total Beginners Tutorial Companion Document ArrayList<Book> books.remove(p1).people. } public void removeBook(Book b1) { this.add(p1).name = name. } public void removePerson(Person p1) { this. Licensed under the Educational Community License version 1. } public ArrayList<Book> getBooks() { return books. books = new ArrayList<Book>(). Person p1) { int booksOut = this.

} public ArrayList<Book> getUnavailableBooks() { ArrayList<Book> result = new ArrayList<Book>(). for (Book aBook : this.0. } } return result.getPerson() != null) && (aBook.getName()))) { result.getBooks()) { if (aBook.add(aBook).setPerson(null). } } public boolean checkIn(Book b1) { if (b1.equals(p1.getPerson() != null) { Copyright © 2007 Mark Dexter.getPerson(). return true. for (Book aBook : this. Page 40 of 45 . } } public ArrayList<Book> getBooksForPerson(Person p1) { ArrayList<Book> result = new ArrayList<Book>(). } else { return false.getPerson() != null) { b1. } } return result.Eclipse and Java for Total Beginners Tutorial Companion Document } else { return false.getBooks()) { if ((aBook.add(aBook). for (Book aBook : this.getBooks()) { if (aBook. } public ArrayList<Book> getAvailableBooks() { ArrayList<Book> result = new ArrayList<Book>().getPerson() == null) { result. Licensed under the Educational Community License version 1.getName() .

size() + " people.totalbeginner.add(aBook).getName() + ": " + this. } } return result.size() + " books. } } Lesson 16 – Create main Method and JAR File package org. public MyLibrary(String name) { this.0. } public String getName() { return name. import java.ArrayList. ArrayList<Book> books.".getPeople(). Licensed under the Educational Community License version 1. Page 41 of 45 .Eclipse and Java for Total Beginners Tutorial Companion Document result. } public ArrayList<Book> getBooks() { return books. books = new ArrayList<Book>().tutorial.getBooks(). " + this. public class MyLibrary { String name.util. } Copyright © 2007 Mark Dexter. ArrayList<Person> people. } public String toString() { return this. people = new ArrayList<Person>().name = name.

if ((b1. return true. } public void addPerson(Person p1) { this.setPerson(null).people. } } public boolean checkIn(Book b1) { if (b1.getPerson() == null) && booksOut < p1. Page 42 of 45 . } else { return false.books.books.getMaximumBooks()){ b1.remove(b1). } public boolean checkOut(Book b1.size().getBooksForPerson(p1).setPerson(p1). } } public ArrayList<Book> getBooksForPerson(Person p1) { Copyright © 2007 Mark Dexter.0. return true. } public void removePerson(Person p1) { this.people.add(p1).Eclipse and Java for Total Beginners Tutorial Companion Document public ArrayList<Person> getPeople() { return people. Licensed under the Educational Community License version 1.add(b1). } else { return false. Person p1) { int booksOut = this.getPerson() != null) { b1.remove(p1). } public void removeBook(Book b1) { this. } public void addBook(Book b1) { this.

for (Book aBook : this.".Eclipse and Java for Total Beginners Tutorial Companion Document ArrayList<Book> result = new ArrayList<Book>().0. } } return result.getBooks()) { if (aBook.getName()))) { result. } } return result.getName() + ": " + this. Book b1 = new Book("War And Peace").size() + " books. Page 43 of 45 . " + this. } } return result. } public String toString() { return this.add(aBook).getPerson() == null) { result. } public static void main(String[] args) { // create a new MyLibrary MyLibrary testLibrary = new MyLibrary("Test Drive Library").equals(p1.add(aBook). } public ArrayList<Book> getUnavailableBooks() { ArrayList<Book> result = new ArrayList<Book>().add(aBook).getPerson() != null) && (aBook.size() + " people. Copyright © 2007 Mark Dexter. for (Book aBook : this. Licensed under the Educational Community License version 1.getBooks()) { if (aBook. } public ArrayList<Book> getAvailableBooks() { ArrayList<Book> result = new ArrayList<Book>(). for (Book aBook : this.getName() .getPerson() != null) { result.getBooks()) { if ((aBook.getPerson().getPeople().getBooks().

} System. sue. testLibrary.addPerson(sue).println("Do some more stuff"). System. testLibrary.out. testLibrary. testLibrary.getPeople()) { int count = this.getBooksForPerson(p).0.println("Status Report of MyLibrary \n" + this.println(thisBook). System.checkIn(b1).addBook(b2).size().addBook(b1). b1.setAuthor("Dickens"). System.setName("Jim").printStatus(). testLibrary.End of Status Report ---").checkOut(b1. sue). for (Book thisBook : this.out.println(p + " (has " + count + " of my books)"). testLibrary. Licensed under the Educational Community License version 1. System. } private void printStatus() { System. Copyright © 2007 Mark Dexter. Person jim = new Person(). Page 44 of 45 .checkOut(b2.out . testLibrary.printStatus().toString()). testLibrary. } for (Person p : this.setAuthor("Tolstoy").out. jim).size()).getAvailableBooks().out.printStatus().println("Check out War And Peace to Sue"). System. testLibrary. b2.println("Books Available: " + this.out.addPerson(jim). jim.println("Just created new library").setName("Sue").out. Person sue = new Person().Eclipse and Java for Total Beginners Tutorial Companion Document Book b2 = new Book("Great Expectations"). testLibrary.getBooks()) { System.out.println("--.

Licensed under the Educational Community License version 1. Page 45 of 45 .Eclipse and Java for Total Beginners Tutorial Companion Document } } Copyright © 2007 Mark Dexter.0.

Sign up to vote on this title
UsefulNot useful