From ebbb0f99e01de43440748e753509c0ce43721d8b Mon Sep 17 00:00:00 2001 From: Javad Sadati <118483830+Javad2004@users.noreply.github.com> Date: Wed, 24 May 2023 20:29:34 +0330 Subject: [PATCH 1/4] Rental System added --- RentalProject/Book.java | 32 +++++++ RentalProject/Customer.java | 68 ++++++++++++++ RentalProject/Game.java | 32 +++++++ RentalProject/Item.java | 86 +++++++++++++++++ RentalProject/Movie.java | 31 +++++++ RentalProject/Rental.java | 56 +++++++++++ RentalProject/RentalStore.java | 165 +++++++++++++++++++++++++++++++++ 7 files changed, 470 insertions(+) create mode 100644 RentalProject/Book.java create mode 100644 RentalProject/Customer.java create mode 100644 RentalProject/Game.java create mode 100644 RentalProject/Item.java create mode 100644 RentalProject/Movie.java create mode 100644 RentalProject/Rental.java create mode 100644 RentalProject/RentalStore.java diff --git a/RentalProject/Book.java b/RentalProject/Book.java new file mode 100644 index 0000000..2448914 --- /dev/null +++ b/RentalProject/Book.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Book extends Item{ + private String author; + private String publisher; + + public Book(String title, String genre,String author ,String publisher, Date releaseDate, int ID) { + super(title, genre, releaseDate, ID); + this.author = author; + this.publisher = publisher; + } + + public String getPublisher() { + return publisher; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + +} diff --git a/RentalProject/Customer.java b/RentalProject/Customer.java new file mode 100644 index 0000000..f967c6b --- /dev/null +++ b/RentalProject/Customer.java @@ -0,0 +1,68 @@ +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; + 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/RentalProject/Game.java b/RentalProject/Game.java new file mode 100644 index 0000000..952b6a2 --- /dev/null +++ b/RentalProject/Game.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Game extends Item{ + private String publisher; + private String platform; + + public Game(String title, String genre, String publisher, String platform, Date releaseDate, int ID){ + super(title, genre, releaseDate, ID); + this.publisher = publisher; + this.platform = platform; + } + + public String getPlatform() { + return platform; + } + + public String getPublisher() { + return publisher; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + +} diff --git a/RentalProject/Item.java b/RentalProject/Item.java new file mode 100644 index 0000000..ac14654 --- /dev/null +++ b/RentalProject/Item.java @@ -0,0 +1,86 @@ +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public abstract class Item { + private String title; + private String genre; + private Date releaseDate; + private int ID; + private boolean isAvailable; + + public Item(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 rentItem(Customer customer) { + this.setAvailable(false); + Rental rental = new Rental(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 returnItem(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"); + } + + } +} \ No newline at end of file diff --git a/RentalProject/Movie.java b/RentalProject/Movie.java new file mode 100644 index 0000000..c8002ba --- /dev/null +++ b/RentalProject/Movie.java @@ -0,0 +1,31 @@ +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Movie extends Item{ + private String director; + private String cast; + + public Movie(String title, String genre, String director, String cast, Date releaseDate, int ID) { + super(title, genre, releaseDate, ID); + this.director = director; + this.cast = cast; + } + + public String getDirector() { + return director; + } + + public String getCast() { + return cast; + } + + public void setCast(String cast) { + this.cast = cast; + } + + public void setDirector(String director) { + this.director = director; + } + +} diff --git a/RentalProject/Rental.java b/RentalProject/Rental.java new file mode 100644 index 0000000..96132c5 --- /dev/null +++ b/RentalProject/Rental.java @@ -0,0 +1,56 @@ +import java.util.Date; +import java.util.concurrent.TimeUnit; + +public class Rental { + private final Customer customer; + private final Item item; + private final Date rentalDate; + private Date returnDate; + private final int ID; + + public Rental(Customer customer, Item item, int ID) { + this.customer = customer; + this.item = item; + 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 Item getItem() { + return item; + } + + 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/RentalProject/RentalStore.java b/RentalProject/RentalStore.java new file mode 100644 index 0000000..b9ec3f0 --- /dev/null +++ b/RentalProject/RentalStore.java @@ -0,0 +1,165 @@ +import java.util.ArrayList; +import java.util.List; + +public class RentalStore { + private List customers; + private List items; + private List availableItems; + + public RentalStore() { + this.customers = new ArrayList<>(); + this.items = new ArrayList<>(); + this.availableItems = new ArrayList<>(); + } + + public void register(Customer customer) { + this.customers.add(customer); + System.out.println("Registered successfully"); + } + public void addItem(Item item) { + this.items.add(item); + this.availableItems.add(item); + System.out.println("Added successfully"); + } + public void removeItem(Item item) { + boolean check = false; + for (Item item_temp:items) { + if (item_temp == item) { + check = true; + if (!this.availableItems.contains(item)) { + System.out.println("This item can't be removed because it's rented"); + } + else { + this.items.remove(item); + this.availableItems.remove(item); + System.out.println("Removed successfully"); + } + break; + } + } + if (!check) { + System.out.println("Item Not found!"); + } + } + + public List getAvailableItems() { + return availableItems; + } + + public List getCustomers() { + return customers; + } + + public List getItems() { + return items; + } + + public void setCustomers(List customers) { + this.customers = customers; + } + + public void setAvailableItems(List availableItems) { + this.availableItems = availableItems; + } + + public void setItems(List items) { + this.items = items; + } + + public void rentItem(Item item, Customer customer) { + boolean customerChecker = false; + for (Customer customer_temp:customers) { + if (customer_temp == customer) { + customerChecker = true; + boolean itemChecker = false; + for (Item item_temp:items) { + if (item_temp == item) { + itemChecker = true; + if(this.availableItems.contains(item)) { + this.availableItems.remove(item); + item.rentItem(customer); + } + else { + System.out.println("This item can't be rented because it's rented already"); + } + break; + } + } + if(!itemChecker) { + System.out.println("Item not found!"); + } + break; + } + } + if(!customerChecker) { + System.out.println("Customer not found!"); + } + } + + public void returnItem(Rental rental) { + boolean customerChecker = false; + for (Customer customer:customers) { + if (rental.getCustomer() == customer) { + customerChecker = true; + boolean itemChecker = false; + for (Item item:items) { + if (rental.getItem() == item) { + itemChecker = true; + boolean rentalChecker = false; + try { + for (Rental rental_temp:customer.getRentals()) { + if (rental_temp == rental) { + rentalChecker = true; + availableItems.add(item); + item.returnItem(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 Item getItemByID(int ID) { + boolean IDChecker = false; + for (Item item:items) { + if (item.getID() == ID) { + return item; + } + } + if (!IDChecker){ + System.out.println("Not found!!!"); + } + return null; + } +} From ad8d4e49d0f80dd6a5bd4e23da20961389273be8 Mon Sep 17 00:00:00 2001 From: Javad Sadati <118483830+Javad2004@users.noreply.github.com> Date: Wed, 24 May 2023 20:30:13 +0330 Subject: [PATCH 2/4] Delete project_should_be_here --- RentalProject/project_should_be_here | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 RentalProject/project_should_be_here diff --git a/RentalProject/project_should_be_here b/RentalProject/project_should_be_here deleted file mode 100644 index e69de29..0000000 From 83ed98f1e4d56b98e5c60479e8a58af77c01f368 Mon Sep 17 00:00:00 2001 From: Javad Sadati <118483830+Javad2004@users.noreply.github.com> Date: Wed, 24 May 2023 20:32:45 +0330 Subject: [PATCH 3/4] MovieRental added --- MovieRental/Customer.java | 69 +++++++++++++++ MovieRental/Movie.java | 87 ++++++++++++++++++ MovieRental/Rental.java | 57 ++++++++++++ MovieRental/RentalStore.java | 165 +++++++++++++++++++++++++++++++++++ 4 files changed, 378 insertions(+) create mode 100644 MovieRental/Customer.java create mode 100644 MovieRental/Movie.java create mode 100644 MovieRental/Rental.java create mode 100644 MovieRental/RentalStore.java 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; + } +} From 6cea19e43ccb2f4690935a51469fc8b4d0732b88 Mon Sep 17 00:00:00 2001 From: Javad Sadati <118483830+Javad2004@users.noreply.github.com> Date: Wed, 24 May 2023 20:33:53 +0330 Subject: [PATCH 4/4] Delete RentalProject directory --- RentalProject/Book.java | 32 ------- RentalProject/Customer.java | 68 -------------- RentalProject/Game.java | 32 ------- RentalProject/Item.java | 86 ----------------- RentalProject/Movie.java | 31 ------- RentalProject/Rental.java | 56 ----------- RentalProject/RentalStore.java | 165 --------------------------------- 7 files changed, 470 deletions(-) delete mode 100644 RentalProject/Book.java delete mode 100644 RentalProject/Customer.java delete mode 100644 RentalProject/Game.java delete mode 100644 RentalProject/Item.java delete mode 100644 RentalProject/Movie.java delete mode 100644 RentalProject/Rental.java delete mode 100644 RentalProject/RentalStore.java diff --git a/RentalProject/Book.java b/RentalProject/Book.java deleted file mode 100644 index 2448914..0000000 --- a/RentalProject/Book.java +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class Book extends Item{ - private String author; - private String publisher; - - public Book(String title, String genre,String author ,String publisher, Date releaseDate, int ID) { - super(title, genre, releaseDate, ID); - this.author = author; - this.publisher = publisher; - } - - public String getPublisher() { - return publisher; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public void setPublisher(String publisher) { - this.publisher = publisher; - } - - -} diff --git a/RentalProject/Customer.java b/RentalProject/Customer.java deleted file mode 100644 index f967c6b..0000000 --- a/RentalProject/Customer.java +++ /dev/null @@ -1,68 +0,0 @@ -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; - 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/RentalProject/Game.java b/RentalProject/Game.java deleted file mode 100644 index 952b6a2..0000000 --- a/RentalProject/Game.java +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class Game extends Item{ - private String publisher; - private String platform; - - public Game(String title, String genre, String publisher, String platform, Date releaseDate, int ID){ - super(title, genre, releaseDate, ID); - this.publisher = publisher; - this.platform = platform; - } - - public String getPlatform() { - return platform; - } - - public String getPublisher() { - return publisher; - } - - public void setPlatform(String platform) { - this.platform = platform; - } - - public void setPublisher(String publisher) { - this.publisher = publisher; - } - - -} diff --git a/RentalProject/Item.java b/RentalProject/Item.java deleted file mode 100644 index ac14654..0000000 --- a/RentalProject/Item.java +++ /dev/null @@ -1,86 +0,0 @@ -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public abstract class Item { - private String title; - private String genre; - private Date releaseDate; - private int ID; - private boolean isAvailable; - - public Item(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 rentItem(Customer customer) { - this.setAvailable(false); - Rental rental = new Rental(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 returnItem(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"); - } - - } -} \ No newline at end of file diff --git a/RentalProject/Movie.java b/RentalProject/Movie.java deleted file mode 100644 index c8002ba..0000000 --- a/RentalProject/Movie.java +++ /dev/null @@ -1,31 +0,0 @@ -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class Movie extends Item{ - private String director; - private String cast; - - public Movie(String title, String genre, String director, String cast, Date releaseDate, int ID) { - super(title, genre, releaseDate, ID); - this.director = director; - this.cast = cast; - } - - public String getDirector() { - return director; - } - - public String getCast() { - return cast; - } - - public void setCast(String cast) { - this.cast = cast; - } - - public void setDirector(String director) { - this.director = director; - } - -} diff --git a/RentalProject/Rental.java b/RentalProject/Rental.java deleted file mode 100644 index 96132c5..0000000 --- a/RentalProject/Rental.java +++ /dev/null @@ -1,56 +0,0 @@ -import java.util.Date; -import java.util.concurrent.TimeUnit; - -public class Rental { - private final Customer customer; - private final Item item; - private final Date rentalDate; - private Date returnDate; - private final int ID; - - public Rental(Customer customer, Item item, int ID) { - this.customer = customer; - this.item = item; - 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 Item getItem() { - return item; - } - - 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/RentalProject/RentalStore.java b/RentalProject/RentalStore.java deleted file mode 100644 index b9ec3f0..0000000 --- a/RentalProject/RentalStore.java +++ /dev/null @@ -1,165 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -public class RentalStore { - private List customers; - private List items; - private List availableItems; - - public RentalStore() { - this.customers = new ArrayList<>(); - this.items = new ArrayList<>(); - this.availableItems = new ArrayList<>(); - } - - public void register(Customer customer) { - this.customers.add(customer); - System.out.println("Registered successfully"); - } - public void addItem(Item item) { - this.items.add(item); - this.availableItems.add(item); - System.out.println("Added successfully"); - } - public void removeItem(Item item) { - boolean check = false; - for (Item item_temp:items) { - if (item_temp == item) { - check = true; - if (!this.availableItems.contains(item)) { - System.out.println("This item can't be removed because it's rented"); - } - else { - this.items.remove(item); - this.availableItems.remove(item); - System.out.println("Removed successfully"); - } - break; - } - } - if (!check) { - System.out.println("Item Not found!"); - } - } - - public List getAvailableItems() { - return availableItems; - } - - public List getCustomers() { - return customers; - } - - public List getItems() { - return items; - } - - public void setCustomers(List customers) { - this.customers = customers; - } - - public void setAvailableItems(List availableItems) { - this.availableItems = availableItems; - } - - public void setItems(List items) { - this.items = items; - } - - public void rentItem(Item item, Customer customer) { - boolean customerChecker = false; - for (Customer customer_temp:customers) { - if (customer_temp == customer) { - customerChecker = true; - boolean itemChecker = false; - for (Item item_temp:items) { - if (item_temp == item) { - itemChecker = true; - if(this.availableItems.contains(item)) { - this.availableItems.remove(item); - item.rentItem(customer); - } - else { - System.out.println("This item can't be rented because it's rented already"); - } - break; - } - } - if(!itemChecker) { - System.out.println("Item not found!"); - } - break; - } - } - if(!customerChecker) { - System.out.println("Customer not found!"); - } - } - - public void returnItem(Rental rental) { - boolean customerChecker = false; - for (Customer customer:customers) { - if (rental.getCustomer() == customer) { - customerChecker = true; - boolean itemChecker = false; - for (Item item:items) { - if (rental.getItem() == item) { - itemChecker = true; - boolean rentalChecker = false; - try { - for (Rental rental_temp:customer.getRentals()) { - if (rental_temp == rental) { - rentalChecker = true; - availableItems.add(item); - item.returnItem(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 Item getItemByID(int ID) { - boolean IDChecker = false; - for (Item item:items) { - if (item.getID() == ID) { - return item; - } - } - if (!IDChecker){ - System.out.println("Not found!!!"); - } - return null; - } -}