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/2] 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/2] 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