-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProxy
More file actions
51 lines (40 loc) · 1.07 KB
/
Proxy
File metadata and controls
51 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package controller;
import java.util.Scanner;
//Returns a summary or the full book, based on the readers' age.
public class Demo {
public static void main(String[] args) {
LibraryProxy library = new LibraryProxy();
System.out.println("What's your age");
Scanner keyboard = new Scanner(System.in);
int ageReader = keyboard.nextInt();
library.returnBook(ageReader);
}
}
class LibraryProxy implements Book{
@Override
public void returnBook(int age) {
if (age<25){
Book book = new emptyBook();
book.returnBook(age);
}else {
Book book = new fullBook();
book.returnBook(age);
}
}
}
class emptyBook implements Book{
@Override
public void returnBook(int age) {
System.out.println("Returns the summary");
}
}
class fullBook implements Book{
@Override
public void returnBook(int age) {
System.out.println("Returns the full book");
}
}
//////////interface////////////
public interface Book {
void returnBook(int age);
}