Commit 204bbca9 authored by Colin DAMON's avatar Colin DAMON

Init kata

parent a013cda3
......@@ -24,3 +24,4 @@ include:
- local: "/h2g2/.gitlab-ci.yml"
- local: "/java-streams/.gitlab-ci.yml"
- local: "/game-of-life/.gitlab-ci.yml"
- local: "/movie-rental/.gitlab-ci.yml"
......@@ -49,3 +49,4 @@ Ce dépôt Git a pour but de partager les différents ateliers pouvant être ré
| [Java streams](/java-streams) | Code&coffee | Moyenne |
| [CodingGame Mars Landing Party](https://www.youtube.com/watch?v=FeJa3UnmeHw) | CodingGame | Moyenne |
| [Game of life](/game-of-life) | Kata | Enervé |
| [Movie rental](/movie-rental) | Kata | Moyenne |
package-movie-rental:
variables:
PROJECT_FOLDER: "movie-rental"
extends: .java
only:
refs:
- master
- merge_requests
changes:
- ".gitlab-common-ci.yml"
- "movie-rental/**/*"
<?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>
<parent>
<version>1.0.0</version>
<groupId>fr.ippon.kata</groupId>
<artifactId>java-parent</artifactId>
<relativePath>../java-parent</relativePath>
</parent>
<version>1.0.0-SNAPSHOT</version>
<artifactId>movie-rental</artifactId>
<name>MovieRental</name>
<developers>
<developer>
<email>arey@ippon.fr</email>
<name>Anthony REY</name>
</developer>
<developer>
<email>cdamon@ippon.fr</email>
<name>Colin DAMON</name>
</developer>
</developers>
</project>
# Movie rental
Résolution du kata [Movie rental](https://gitlab.com/azae/craft/movie-rental)
- **Auteurs** : Anthony REY et Colin DAMON
- **Date** : 28/01/2021
- **Langage** : Java
- **Niveau** : Moyen
- **Replay** : TODO
package fr.ippon.rental;
import java.util.ArrayList;
import java.util.List;
public class Customer {
private String _name;
private List<Rental> _rentals = new ArrayList<Rental>();
public Customer(String name) {
_name = name;
}
public void addRental(Rental arg) {
_rentals.add(arg);
}
public String getName() {
return _name;
}
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
String result = "Rental Record for " + getName() + "\n";
for (Rental each : _rentals) {
double thisAmount = 0;
//determine amounts for each line
switch (each.getMovie().getPriceCode()) {
case Movie.REGULAR:
thisAmount += 2;
if (each.getDaysRented() > 2) thisAmount += (each.getDaysRented() - 2) * 1.5;
break;
case Movie.NEW_RELEASE:
thisAmount += each.getDaysRented() * 3;
break;
case Movie.CHILDRENS:
thisAmount += 1.5;
if (each.getDaysRented() > 3) thisAmount += (each.getDaysRented() - 3) * 1.5;
break;
}
// add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && each.getDaysRented() > 1) frequentRenterPoints++;
// show figures for this rental
result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
// add footer lines
result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
return result;
}
}
package fr.ippon.rental;
public class Movie {
public static final int CHILDRENS = 2;
public static final int NEW_RELEASE = 1;
public static final int REGULAR = 0;
private String _title;
private int _priceCode;
public Movie(String title, int priceCode) {
_title = title;
_priceCode = priceCode;
}
public int getPriceCode() {
return _priceCode;
}
public void setPriceCode(int arg) {
_priceCode = arg;
}
public String getTitle() {
return _title;
}
}
package fr.ippon.rental;
/**
* The rental class represents a customer renting a movie.
*/
public class Rental {
private Movie _movie;
private int _daysRented;
public Rental(Movie movie, int daysRented) {
_movie = movie;
_daysRented = daysRented;
}
public int getDaysRented() {
return _daysRented;
}
public Movie getMovie() {
return _movie;
}
}
package fr.ippon.rental;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class CustomerTest {
@Test
public void test() {
Customer customer = new Customer("Bob");
customer.addRental(new Rental(new Movie("Jaws", Movie.REGULAR), 2));
customer.addRental(new Rental(new Movie("Golden Eye", Movie.REGULAR), 3));
customer.addRental(new Rental(new Movie("Short New", Movie.NEW_RELEASE), 1));
customer.addRental(new Rental(new Movie("Long New", Movie.NEW_RELEASE), 2));
customer.addRental(new Rental(new Movie("Bambi", Movie.CHILDRENS), 3));
customer.addRental(new Rental(new Movie("Toy Story", Movie.CHILDRENS), 4));
String expected =
"" +
"Rental Record for Bob\n" +
"\tJaws\t2.0\n" +
"\tGolden Eye\t3.5\n" +
"\tShort New\t3.0\n" +
"\tLong New\t6.0\n" +
"\tBambi\t1.5\n" +
"\tToy Story\t3.0\n" +
"Amount owed is 19.0\n" +
"You earned 7 frequent renter points";
assertThat(customer.statement()).isEqualTo(expected);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment