final project q9
This commit is contained in:
42
finalproject/Question9/Lender.java
Normal file
42
finalproject/Question9/Lender.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Author: CHEN Yongyuan (Walter) 1930006025 from OOP(1007)
|
||||
* Date: 2022-04-25
|
||||
* Description: This is the Lender class.
|
||||
*/
|
||||
|
||||
public class Lender extends User {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name The user's name.
|
||||
* @param book number of bookds lent by the user. This will be store in negetive value.
|
||||
*/
|
||||
public Lender(String name, int book) {
|
||||
// lender negetive book value
|
||||
super(name, -book);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the number of bookds.
|
||||
*
|
||||
* @param book the number of books.
|
||||
*/
|
||||
public void moreBook(int book) {
|
||||
setBook(getBook() - book);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test.
|
||||
*/
|
||||
public static void testLender() {
|
||||
Lender l = new Lender("Anna", 5);
|
||||
System.out.println(l.getName() == "Anna");
|
||||
System.out.println(l.getBook() == -5);
|
||||
l.setBook(-6);
|
||||
System.out.println(l.getBook() == -6);
|
||||
l.moreBook(2);
|
||||
System.out.println(l.getBook() == -8);
|
||||
l.moreBook(-9);
|
||||
System.out.println(l.getBook() == 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user