diff --git a/MovieRental/Customer.java b/MovieRental/Customer.java new file mode 100644 index 0000000..ec3b361 --- /dev/null +++ b/MovieRental/Customer.java @@ -0,0 +1,69 @@ +import java.util.ArrayList; +import java.util.List; + +public class Customer { + private String name; + private String email; + private String phone_number; + private String address; + private int ID; + private List rentals; + + + public Customer(String name, String email, String phone_number, String address, int ID) { + this.name= name; + this.email = email; + this.phone_number = phone_number; + this.address = address; + this.ID = ID; + this.rentals = new ArrayList<>(); + } + + public int getID() { + return ID; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public String getPhone_number() { + return phone_number; + } + + public String getAddress() { + return address; + } + + public List getRentals() { + return rentals; + } + + public void setID(int ID) { + this.ID = ID; + } + + public void setAddress(String address) { + this.address = address; + } + + public void setEmail(String email) { + this.email = email; + } + + public void setName(String name) { + this.name = name; + } + + public void setPhone_number(String phone_number) { + this.phone_number = phone_number; + } + + public void setRentals(List rentals) { + this.rentals = rentals; + } +} diff --git a/MovieRental/Movie.java b/MovieRental/Movie.java new file mode 100644 index 0000000..dcf1959 --- /dev/null +++ b/MovieRental/Movie.java @@ -0,0 +1,87 @@ +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Movie { + private String title; + private String genre; + private Date releaseDate; + private int ID; + private boolean isAvailable; + + public Movie(String title, String genre, Date releaseDate, int ID) { + this.ID = ID; + this.genre = genre; + this.releaseDate = releaseDate; + this.title = title; + } + + public int getID() { + return ID; + } + + public Date getReleaseDate() { + return releaseDate; + } + + public String getGenre() { + return genre; + } + + public String getTitle() { + return title; + } + + public boolean isAvailable() { + return isAvailable; + } + + public void setAvailable(boolean available) { + isAvailable = available; + } + + public void setGenre(String genre) { + this.genre = genre; + } + + public void setID(int ID) { + this.ID = ID; + } + + public void setReleaseDate(Date releaseDate) { + this.releaseDate = releaseDate; + } + + public void setTitle(String title) { + this.title = title; + } + + public void rentMovie(Customer customer) { + this.setAvailable(false); + + Rental rental = new Rental(customer,this, Integer.parseInt(this.getID() + String.valueOf(customer.getID()))); + + try { + customer.getRentals().add(rental); + } catch (NullPointerException e) { + List rentals = new ArrayList<>(); + rentals.add(rental); + customer.setRentals(rentals); + } + + System.out.println("Item named " + this.getTitle() + " rented"); + } + + public void returnMovie(Rental rental) { + this.setAvailable(true); + + try { + rental.getCustomer().getRentals().remove(rental); + System.out.println("Item named " + this.getTitle() + " returned"); + System.out.println("Your lateFee: " + rental.calculateLateFee() + 'T'); + } catch (NullPointerException e) { + System.out.println("No rentals"); + } + + } +} diff --git a/MovieRental/Rental.java b/MovieRental/Rental.java new file mode 100644 index 0000000..d0c7f1f --- /dev/null +++ b/MovieRental/Rental.java @@ -0,0 +1,57 @@ +import java.util.Date; +import java.util.concurrent.TimeUnit; + +public class Rental { + private final Customer customer; + private final Movie movie; + private final Date rentalDate; + private Date returnDate; + private final int ID; + + public Rental(Customer customer, Movie movie, int ID) { + this.customer = customer; + this.movie = movie; + this.ID = ID; + this.rentalDate = new Date(); + // Adding 7 days to rentalDate to create return date + this.returnDate = new Date(rentalDate.getTime() + TimeUnit.DAYS.toMillis(7)); + } + + public int getID() { + return ID; + } + + public Movie getMovie() { + return movie; + } + + public Customer getCustomer() { + return customer; + } + + public Date getRentalDate() { + return rentalDate; + } + + public void setReturnDate(Date returnDate) { + this.returnDate = returnDate; + } + + public Date getReturnDate() { + return returnDate; + } + + public double calculateLateFee() { + int lateFee = 10000; + Date date = new Date(); + + long diffInMillie = date.getTime() - this.returnDate.getTime(); + long diff = TimeUnit.DAYS.convert(diffInMillie, TimeUnit.MILLISECONDS); + + if(diff<=0) { + return 0; + } + + return lateFee * diff; + } +} diff --git a/MovieRental/RentalStore.java b/MovieRental/RentalStore.java new file mode 100644 index 0000000..16a66fa --- /dev/null +++ b/MovieRental/RentalStore.java @@ -0,0 +1,165 @@ +import java.util.ArrayList; +import java.util.List; + +public class RentalStore { + private List customers; + private List movies; + private List availableMovies; + + public RentalStore() { + this.customers = new ArrayList<>(); + this.movies = new ArrayList<>(); + this.availableMovies = new ArrayList<>(); + } + + public void register(Customer customer) { + this.customers.add(customer); + System.out.println("Registered successfully"); + } + public void addMovie(Movie movie) { + this.movies.add(movie); + this.availableMovies.add(movie); + System.out.println("Added successfully"); + } + public void removeMovie(Movie movie) { + boolean check = false; + for (Movie movie_temp:movies) { + if (movie_temp == movie) { + check = true; + if (!this.availableMovies.contains(movie)) { + System.out.println("This movie can't be removed because it's rented"); + } + else { + this.movies.remove(movie); + this.availableMovies.remove(movie); + System.out.println("Removed successfully"); + } + break; + } + } + if (!check) { + System.out.println("Movie Not found!"); + } + } + + public List getAvailableMovies() { + return availableMovies; + } + + public List getCustomers() { + return customers; + } + + public List getMovies() { + return movies; + } + + public void setCustomers(List customers) { + this.customers = customers; + } + + public void setAvailableMovies(List availableMovies) { + this.availableMovies = availableMovies; + } + + public void setMovies(List movies) { + this.movies = movies; + } + + public void rentMovie(Movie movie, Customer customer) { + boolean customerChecker = false; + for (Customer customer_temp:customers) { + if (customer_temp == customer) { + customerChecker = true; + boolean itemChecker = false; + for (Movie movie_temp:movies) { + if (movie_temp == movie) { + itemChecker = true; + if(this.availableMovies.contains(movie)) { + this.availableMovies.remove(movie); + movie.rentMovie(customer); + } + else { + System.out.println("This movie can't be rented because it's rented already"); + } + break; + } + } + if(!itemChecker) { + System.out.println("movie not found!"); + } + break; + } + } + if(!customerChecker) { + System.out.println("Customer not found!"); + } + } + + public void returnMovie(Rental rental) { + boolean customerChecker = false; + for (Customer customer:customers) { + if (rental.getCustomer() == customer) { + customerChecker = true; + boolean itemChecker = false; + for (Movie movie:movies) { + if (rental.getMovie() == movie) { + itemChecker = true; + boolean rentalChecker = false; + try { + for (Rental rental_temp:customer.getRentals()) { + if (rental_temp == rental) { + rentalChecker = true; + availableMovies.add(movie); + movie.returnMovie(rental); + break; + } + } + if (!rentalChecker) { + System.out.println("Not borrowed"); + } + } catch (NullPointerException e) { + System.out.println("No rentals"); + } + + break; + } + } + if (!itemChecker) { + System.out.println("Item not found!"); + } + break; + } + } + if (!customerChecker) { + System.out.println("Customer not found!"); + } + + } + + public Customer getCustomerByID(int ID) { + boolean IDChecker = false; + for (Customer customer:customers) { + if (customer.getID() == ID) { + return customer; + } + } + if (!IDChecker){ + System.out.println("Not found!!!"); + } + return null; + } + + public Movie getMovieByID(int ID) { + boolean IDChecker = false; + for (Movie movie:movies) { + if (movie.getID() == ID) { + return movie; + } + } + if (!IDChecker){ + System.out.println("Not found!!!"); + } + return null; + } +} diff --git a/RentalProject/project_should_be_here b/RentalProject/project_should_be_here deleted file mode 100644 index e69de29..0000000