Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions RentalProject/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions RentalProject/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions RentalProject/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions RentalProject/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions RentalProject/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions RentalProject/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions RentalProject/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>RentalTest</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>




<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
51 changes: 51 additions & 0 deletions RentalProject/src/main/java/org/example/AllModules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.example;

import java.util.ArrayList;

public class AllModules {
private ArrayList<Customer> customers;
private ArrayList<Book> books;
private ArrayList<Game> games;
private ArrayList<Movie> movies;
private ArrayList<Rental> rentals;

public ArrayList<Customer> getCustomers() {
return customers;
}

public void setCustomers(ArrayList<Customer> customers) {
this.customers = customers;
}

public ArrayList<Book> getBooks() {
return books;
}

public void setBooks(ArrayList<Book> books) {
this.books = books;
}

public ArrayList<Game> getGames() {
return games;
}

public void setGames(ArrayList<Game> games) {
this.games = games;
}

public ArrayList<Movie> getMovies() {
return movies;
}

public void setMovies(ArrayList<Movie> movies) {
this.movies = movies;
}

public ArrayList<Rental> getRentals() {
return rentals;
}

public void setRentals(ArrayList<Rental> rentals) {
this.rentals = rentals;
}
}
28 changes: 28 additions & 0 deletions RentalProject/src/main/java/org/example/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.example;

class Book extends Item {
private String author;
private String publisher;
public Book(int id, String title, String genre, int releaseDate, double rentalFee, String author, String publisher) {
super(id, title, genre, releaseDate);
this.author = author;
this.publisher = publisher;
this.available = true;
}

public String getAuthor() {
return author;
}

public String getPublisher() {
return publisher;
}

public void rent() {
// برای اجاره کردن کتاب
}

public void returnItem() {
// برای برگردوندن یک کتاب
}
}
65 changes: 65 additions & 0 deletions RentalProject/src/main/java/org/example/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.example;

import java.util.ArrayList;
import java.util.List;

public class Customer {
private String name;
private String email;
private String phone;
private String address;
private int id;
public ArrayList<Rental> rentals;


public Customer(String name, String email, String phone, String address, int id) {
this.name = name;
this.email = email;
this.phone = phone;
this.address = address;
this.id = id;
rentals=new ArrayList<>();

}

public int getId() {
return this.id;
}

public String getName() {
return this.name;
}

public String getEmail() {
return this.email;
}

public String getPhone() {
return this.phone;
}



public String getAddress() {
return this.address;
}
public void setRentals(ArrayList<Rental> rentals) {

this.rentals = rentals;
}
public ArrayList<Rental>getRentals(){
return rentals;
}






public void addRental(Rental rental) {
if (rentals==null)
rentals=new ArrayList<>();
rentals.add(rental);
}
}

29 changes: 29 additions & 0 deletions RentalProject/src/main/java/org/example/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.example;


class Game extends Item {
private String platform;
private String publisher;

public Game(int id, String title, String genre, int releaseDate, String platform, String publisher) {
super(id, title, genre, releaseDate);
this.platform = platform;
this.publisher = publisher;
}

public String getPlatform() {
return platform;
}

public String getPublisher() {
return publisher;
}

public void rent() {
// برای قرض گرفتن یک بازی
}

public void returnItem() {
// برای پس دادن یک بازی
}
}
41 changes: 41 additions & 0 deletions RentalProject/src/main/java/org/example/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.example;


public class Item {
public int id;
public String title;
public String genre;
public String releaseDate;
public boolean available = true
;

public Item(int id, String title, String genre, int releaseDate) {
this.id = id;
this.title = title;
this.genre = genre;
this.releaseDate = String.valueOf(releaseDate);
}

public int getId() {
return id;
}

public String getTitle() {
return title;
}

public String getGenre() {
return genre;
}

public String getReleaseDate() {
return releaseDate;
}

public boolean isAvailable() {
return available;
}
public void setAvailable(boolean status){
available=status;
}
}
56 changes: 56 additions & 0 deletions RentalProject/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.example;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.*;
import java.util.List;


public class Main {
public static void main(String[] args) throws IOException {
// System.out.println("Hello world!");
RentalStore rentalStore = new RentalStore();
Gson gson = new Gson();
Reader reader = new FileReader("C:\\Users\\Lenovo\\Desktop\\rentalclone\\RentalSystem\\RentalProject\\src\\test\\java\\TestYourFork (1).json");
AllModules models = gson.fromJson(reader, new TypeToken<AllModules>() {
}.getType());
String test = gson.toJson(models);
Customer joshn = models.getCustomers().get(0);
Customer Emily = models.getCustomers().get(1);
Customer Brown = models.getCustomers().get(2);
for (Item item : models.getBooks()) {
if (item.id == 3) {
rentalStore.rentItem(item, joshn);
} else if (item.id == 6) {
rentalStore.rentItem(item, joshn);
}
}
for (Item item : models.getBooks()) {
if (item.id == 1) {
rentalStore.rentItem(item, Emily);
} else if (item.id == 7) {
rentalStore.rentItem(item, Emily);
}
}
for (Item item : models.getBooks()) {
if (item.id == 9) {
rentalStore.rentItem(item, Brown);
} else if (item.id == 4) {
rentalStore.rentItem(item, Brown);
}
}
reader.close();
Gson writing=new Gson();
String json = writing.toJson(models);
String filepath="C:\\Users\\Lenovo\\Desktop\\rentalclone\\RentalSystem\\RentalProject\\src\\test\\java\\TestYourFork (1).json";
try {
FileWriter writer= new FileWriter(filepath);
writer.write(json);
writer.close();
System.out.println("JSON DATA HAS BEEN UPDATED");
}catch (IOException e){
e.printStackTrace();
}
}

}
Loading