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
25 changes: 25 additions & 0 deletions RentalProject/RentalProject/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
Empty file.
52 changes: 52 additions & 0 deletions RentalProject/RentalProject/src/main/java/AllModules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@


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;
}
}

32 changes: 32 additions & 0 deletions RentalProject/RentalProject/src/main/java/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import java.util.*;

class Book extends Item {
private final String author;
private final String publisher;
private boolean availableForRent;

public Book(String title, String genre, Date releaseDate, double rentalFee, String author, String publisher , long id) {
super(title, genre, releaseDate, rentalFee , id);
this.author = author;
this.publisher = publisher;
this.availableForRent = true;
}

public String getAuthor() {
return author;
}

public String getPublisher() {
return publisher;
}

public boolean isAvailableForRent() {
return availableForRent;
}

public void setAvailableForRent(boolean availableForRent) {
this.availableForRent = availableForRent;
}

}
46 changes: 46 additions & 0 deletions RentalProject/RentalProject/src/main/java/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.util.*;

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

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

public long getId() {
return id;
}

public String getName() {
return name;
}

public String getEmail() {
return email;
}

public String getPhone() {
return phone;
}

public String getAddress() {
return address;
}

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

public void addRent(Rental rental) {
}
}
32 changes: 32 additions & 0 deletions RentalProject/RentalProject/src/main/java/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import java.util.*;

public class Game extends Item {
private final String platform;
private final String publisher;
private boolean availableForRent;

public Game(String title, String genre, Date releaseDate, double rentalFee, String platform, String publisher , long id) {
super(title, genre, releaseDate, rentalFee, id);
this.platform = platform;
this.publisher = publisher;
this.availableForRent = true;
}

public String getPlatform() {
return platform;
}

public String getPublisher() {
return publisher;
}

public boolean isAvailableForRent() {
return availableForRent;
}

public void setAvailableForRent(boolean availableForRent) {
this.availableForRent = availableForRent;
}

}
40 changes: 40 additions & 0 deletions RentalProject/RentalProject/src/main/java/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

import java.util.*;
public class Item {

private String title;
private String genre;
private Date releaseDate;
protected double rentalFee;
private long id;

public Item( String title, String genre, Date releaseDate, double rentalFee , long id) {

this.title = title;
this.genre = genre;
this.releaseDate = releaseDate;
this.rentalFee = rentalFee;
this.id = id;
}

public long getId() {
return id;
}

public String getTitle() {
return title;
}

public String getGenre() {
return genre;
}

public Date getReleaseDate() {
return releaseDate;
}

public double getRentalFee() {
return rentalFee;
}

}
79 changes: 79 additions & 0 deletions RentalProject/RentalProject/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException {
System.out.println("Hi!");
Gson gson = new Gson();
Reader reader = new FileReader("C:\\Users\\nilofar\\Rental Clone\\RentalSystem\\RentalProject\\src\\test\\TestYourFork.json");//open the input file
AllModules allModules = gson.fromJson(reader, new TypeToken<AllModules>() {
}.getType());

Customer Joshn = allModules.getCustomers().get(0);
Customer Emily = allModules.getCustomers().get(1);
Customer Michael = allModules.getCustomers().get(2);

for (Book newBook : allModules.getBooks()) {
if (newBook.getId() == 3) {
RentalStore.rentBook(newBook, Joshn);
} else if (newBook.getId() == 6) {
RentalStore.rentBook(newBook, Joshn);
}
}
for (Book newBook1 : allModules.getBooks()) {
if (newBook1.getId() == 1) {
RentalStore.rentBook(newBook1, Emily);
} else if (newBook1.getId() == 7) {
RentalStore.rentBook(newBook1, Emily);
}
}
for (Book newBook2 : allModules.getBooks()) {
if (newBook2.getId() == 9) {
RentalStore.rentBook(newBook2, Michael);
} else if (newBook2.getId() == 4) {
RentalStore.rentBook(newBook2, Michael);
}
}

for (Game newGame : allModules.getGames()) {
if (newGame.getId() == 3) {
RentalStore.rentGame(newGame, Joshn);
} else if (newGame.getId() == 6) {
RentalStore.rentGame(newGame, Joshn);
}
}
for (Game newGame1 : allModules.getGames()) {
if (newGame1.getId() == 1) {
RentalStore.rentGame(newGame1, Emily);
} else if (newGame1.getId() == 7) {
RentalStore.rentGame(newGame1, Emily);
}
}
for (Game newGame2 : allModules.getGames()) {
if (newGame2.getId() == 9) {
RentalStore.rentGame(newGame2, Michael);
} else if (newGame2.getId() == 4) {
RentalStore.rentGame(newGame2, Michael);
}
}

reader.close();



Gson writing = new Gson();
String json = writing.toJson(allModules);
String filePath ="C:\\Users\\nilofar\\Rental Clone\\RentalSystem\\RentalProject\\src\\test\\TestYourFork.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();
}
}
}

33 changes: 33 additions & 0 deletions RentalProject/RentalProject/src/main/java/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import java.util.*;

public class Movie extends Item {
private final String director;
private final String cast;
private boolean availableForRent;

public Movie(String title, String genre, Date releaseDate, double rentalFee, String director, String cast, long id) {
super(title, genre, releaseDate, rentalFee, id);
this.director = director;
this.cast = cast;
this.availableForRent = true;
}

public String getDirector() {
return director;
}

public String getCast() {
return cast;
}

public boolean isAvailableForRent() {
return availableForRent;
}

public void setAvailableForRent(boolean availableForRent)
{
this.availableForRent = availableForRent;
}

}
Loading