Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class App {
- public static void main(String[] args) {
- MovieStore movieStore = new MovieStore();
- movieStore.start();
- }
- }
- public class Video {
- private final String title;
- public String getTitle() {
- return title;
- }
- public Video(String name, LocalDate due) {
- this.title = name;
- }
- }
- public class MovieStore {
- private final ArrayList<Video> videos = new ArrayList<>();
- private final Map<String, VideoStoreDates> overDueVideos = new HashMap<>();
- private final Map<String, LocalDate> checkedOutVideos = new HashMap<>();
- public void start() {
- getMoviesFromAFile();
- getAllVideos();
- randomCheckOutVideos();
- getAllCheckedOutVideos();
- storeAllOverDueVideos();
- getAllOverDueVideos();
- }
- private void getMoviesFromAFile() {
- try {
- BufferedReader bufferedReader = getBufferedReader();
- addAllVideos(bufferedReader);
- } catch (IOException e) {
- throw new FileSystemNotFoundException("The file could not be found, check the file or adjust the location");
- }
- }
- private BufferedReader getBufferedReader() throws FileNotFoundException {
- File file = new File("src/main/resources/MovieList.txt");
- FileReader fileReader = new FileReader(file);
- return new BufferedReader(fileReader);
- }
- private void addAllVideos(BufferedReader bufferedReader) throws IOException {
- String line;
- int MAX_LINE = 22;
- for (int i = 0; i < MAX_LINE; i++) {
- line = bufferedReader.readLine().toLowerCase(Locale.ROOT);
- videos.add(new Video(line, LocalDate.now()));
- }
- }
- private void getAllVideos() {
- System.out.println("Videos available");
- for (Video video : videos) {
- System.out.println(video.getTitle());
- }
- }
- private void randomCheckOutVideos() {
- int randomVideosCheckedOut = (int) (Math.random()*videos.size());
- VideoStoreDates videoStoreDates = new VideoStoreDates();
- for (int i = 0; i < randomVideosCheckedOut; i++) {
- int randomVide = (int) (Math.random() * videos.size());
- checkedOutVideos.put(videos.get(randomVide).getTitle(), videoStoreDates.getDue());
- }
- }
- private void getAllCheckedOutVideos() {
- for (Map.Entry<String, LocalDate> entry : checkedOutVideos.entrySet()) {
- System.out.println("Videos that are checked out '" + entry.getKey() + "' and due: " + entry.getValue());
- }
- }
- private void storeAllOverDueVideos() {
- VideoStoreDates videoStoreDates = new VideoStoreDates();
- for (int i = 0; i < checkedOutVideos.size(); i++) {
- int randomVideo = (int) (Math.random() * checkedOutVideos.size());
- if (videoStoreDates.getOverDue().isAfter(videoStoreDates.getDue())) {
- overDueVideos.put(videos.get(randomVideo).getTitle(), videoStoreDates);
- }
- }
- }
- private void getAllOverDueVideos() {
- for (Map.Entry<String, VideoStoreDates> entry : overDueVideos.entrySet()) {
- System.out.println("Videos that are overdue '" + entry.getKey() + "' Date due to be given back '" + entry.getValue().getDue() + "' date brought back '" + entry.getValue().getOverDue() + "'");
- }
- }
- }
- public class VideoStoreDates {
- private final int DUE_DATE = 1;
- private final int OVERDUE_DATE = 3;
- private final LocalDate due = LocalDate.now().plusWeeks(DUE_DATE);
- private final LocalDate overDue = LocalDate.now().plusWeeks((int)(Math.random()*OVERDUE_DATE));
- public LocalDate getDue() {
- return due;
- }
- public LocalDate getOverDue() {
- return overDue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement