Created
July 16, 2020 12:24
-
-
Save jcavat/dee5bac84e5db0274eb7c2486bd46d1a to your computer and use it in GitHub Desktop.
used for personal blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
interface Resource { | |
String info(); | |
} | |
class Room implements Resource { | |
private String id; | |
private int capacity; | |
public Room(String id, int capacity) { | |
this.id = id; | |
this.capacity = capacity; | |
} | |
public String info() { | |
return String.format("room id: %s with capacity: %d", this.id, this.capacity); | |
} | |
} | |
class Professor implements Resource { | |
private String fullname; | |
private String numberPhone; | |
public Professor(String fullname, String numberPhone) { | |
this.fullname = fullname; | |
this.numberPhone = numberPhone; | |
} | |
public String info() { | |
return String.format("professeur fullname: %s, numberphone: %s", this.fullname, this.numberPhone); | |
} | |
} | |
class Student implements Resource { | |
private String fullname; | |
private int subscriptionYear; | |
public Student(String fullname, int subscriptionYear) { | |
this.fullname = fullname; | |
this.subscriptionYear = subscriptionYear; | |
} | |
public String info() { | |
return String.format("student fullname: %s, subscription year: %d", this.fullname, this.subscriptionYear); | |
} | |
} | |
public class ResourceApp { | |
public static void print(Resource resource) { | |
System.out.println(resource.info()); | |
} | |
public static void main(String[] args) { | |
List<Resource> resources = List.of( | |
new Professor("Paul", "62433"), | |
new Professor("Oreste", "62422"), | |
new Room("A406", 50)); | |
for (Resource resource : resources) { | |
print(resource); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment