CS 630 - Computing Fundamentals I - Fall 2005
Homework 6


Loyola College > Department of Computer Science > CS 630 > Homework > Homework 6

Due

Monday, October 31st at the beginning of class

Problems

Exercise (p. 274-275)
5.1, 5.2, 5.3

4) Consider the following code segment:

if (i == j) {
   System.out.println("A");
}
else if ((i%j) < 3) {
   System.out.println("B");
}
else if (i < (j - 1)) {
   System.out.println("C");
}
else {
   System.out.println("D");
}
  1. If i is 9 and j is 4, what is the output?
  2. If i is 4 and j is 9, what is the output?
  3. If i is 5 and j is 6, what is the output?
  4. If i is 5 and j is 9, what is the output?

5) Suppose the following definitions are in effect.

   boolean p = true;
   boolean q = false;
   boolean r = false;
   String s = "b";
   String t = "b";
   String u = t;
   int i = 10;
   int j = 0;
Evaluate the following expressions.
  1. !p == q
  2. s != t
  3. t != u
  4. s == u
  5. s.equals(u)
  6. t.equals(u)
  7. r == (p && q)
  8. q && (p || r)
  9. q || (p && !r)
  10. p && !q && !r || (p == !q)

Programming Projects


Objectives

Introduction

The LibraryBook class represents the a library book with fields for title(a String), author(a String), borrower(a String), due date(a GregorianCalendar), call number (a String), and replacement cost (a double). The constructors and some methods have been provided. I suggest browsing them because one or two will be useful when you add the new methods. If a method does what you need it to do, you should call that method rather then rewriting the code in the method. These new methods will use conditionals (if statements).

Assignment

You will add three methods to the LibraryBook class and then add code to main to throughly test your methods

(Some of these methods will crash when called on a book that is not checked out; that is OK for now).

Finish the test driver started in the BookTest class. Your test driver should test all the cases of the methods described above. For example, to test isReference you would display the result of calling isReference on a reference book and a non-reference book. Part of your grade will depend on how completely you test your class.
Hint: You may draw a flow chart of your methods. To completely test them, you need to provide conditions that execute every path in the flow chart. Depending on how you write the methods, you may require different numbers of test cases.

Download Code

LibraryBook.java
BookTest.java