示例#1
0
 public static void main(String[] args) {
   Console c;
   c = new Console(30, 70);
   Book b[] = new Book[5];
   b[0] = new Book("From Russia With Love", "Greg Hines");
   b[1] = new Book("Living Smart", "Rita Langill");
   b[2] = new Book("Singing in the Rain", "Harry Conner");
   b[3] = new Book("Good Housekeeping", "Pat Burns");
   b[4] = new Book("To Be A Model", "Lisa Lahey");
   c.println("Available books:\n");
   for (int i = 0; i < 5; i++) {
     c.println("Book " + (i + 1) + ": " + b[i]);
   }
   Patron p = new Patron("Kick Neenan");
   c.println("Lending 4 books to " + p.getName());
   for (int i = 0; i < 4; i++) {
     if (p.borrow(b[i])) {
       c.println(b[i].getTitle() + " successfully borrowed.");
     } else {
       c.println(b[i].getTitle() + " could not be borrowed.");
     }
   }
   // return books
   c.println("-------\nAtempting to return the first book:\n--------------");
   if (p.returnBook(b[0])) c.println("" + b[0].getTitle() + " successfully returned.");
   else c.println("" + b[0].getTitle() + " was not borrowed");
   c.println("-------\nHere are a list of books currently lent to " + p.getName() + ".\n----");
   for (int i = 0; i < 5; i++) {
     if (p.hasBook(b[i])) c.println("" + b[i]);
   }
 }
示例#2
0
 public static void main(String[] args) {
   Console c = new Console();
   Format f = new Format();
   double salaryold = 0, salarynew = 40000, raise = 40000;
   c.print(Format.justify('r', "Year", 6));
   c.print(Format.justify('r', "Old Salary", 15));
   c.print(Format.justify('r', "Raise", 11));
   c.print(Format.justify('r', "New Salary\n", 17));
   c.print(Format.justify('r', "----", 6));
   c.print(Format.justify('r', "--- ------", 15));
   c.print(Format.justify('r', "-----", 11));
   c.print(Format.justify('r', "--- ------\n", 17));
   for (int x = 0; x <= 9; x++) {
     c.print(Format.justify('r', x + 1, 6));
     c.print(Format.justify('r', salaryold, 15, 2));
     c.print(Format.justify('r', raise, 12, 2));
     c.println(Format.justify('r', salarynew, 14, 2));
     raise = (salarynew * .03);
     salaryold = salarynew;
     salarynew = raise + salaryold;
   }
 }