Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update files according best practice suggested by gradle. first part.
  • Loading branch information
daniel-jauregui authored and JoaquinGonzales committed Mar 14, 2017
commit c3e8a1ddbc8f4015a6b10368504f1b1181dcda56
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
package com.jalasoft.selenium.daniel.jauregui.movies;

/**
* Class Children
* Class Children.
*/
public class Children extends aMovie {

public Children(String _title,int bonus) {
super(_title, bonus);
public class Children extends MovieAbs {
private final int restOfRentedDays = 3;
private final double multiplyOfRentedDays = 1.5;
/**
* Constructor of Children.
* @param title will contain the name of Movie.
* @param bonus will give to the movie a bonus.
*/
public Children(final String title, final int bonus) {
super(title, bonus);
}

/**
*
* @param rentedDays: number of day where movie was rented.
* @return
*/
@Override
public double calculateRate(int rentedDays, double thisAmount) {
if (rentedDays <= 0) { return 0; }
thisAmount += 1.5;
if (rentedDays > 3)
thisAmount += (rentedDays - 3) * 1.5;
public double calculateRate(final int rentedDays) {
if (rentedDays <= 0) {
return 0;
}
double thisAmount = multiplyOfRentedDays;
if (rentedDays > restOfRentedDays) {
thisAmount += (rentedDays - restOfRentedDays) * multiplyOfRentedDays;
}
return thisAmount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,60 @@

import java.util.ArrayList;
import java.util.Iterator;

/**
* Customer class.
* @author Daniel Jauregui
*/
class Customer {
private final String _name;
private final ArrayList<Rental> _rentals = new ArrayList();

public Customer(String name) {
_name = name;
private final String name;
private final ArrayList<Rental> rentals = new ArrayList();
/**
* Constructor of Customer class.
* @param name : Name of the customer.
*/
public Customer(final String name) {
this.name = name;
}

public void addRental(Rental arg) {
_rentals.add(arg);
/**
* addRental will add the movies that customer is renting.
* @param arg : will have a Rental object.
*/
public void addRental(final Rental arg) {
this.rentals.add(arg);
}


/**
* getRentals.
* @return : Get Object with all rentals of customer.
*/
public ArrayList getRentals() {
return _rentals;
return this.rentals;
}

/**
* Get the Name of Customer.
* @return : Will return the name of Customer.
*/
public String getName() {
return _name;
return this.name;
}

/**
* Generate the Statement Rentals of Customer.
* @return : Will return the summary of Customer Statement
*/
public String statement() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is doing 3 things
please split it.

double totalAmount = 0;
int frequentRenterPoints = 0;
Iterator<Rental> rentals = _rentals.iterator();
Iterator<Rental> rentals = this.rentals.iterator();
String result = "Rental Record for " + getName() + "\n";
Rental each;
double thisAmount;
while (rentals.hasNext()) {
each = (Rental) rentals.next();
// Get rate of movie
thisAmount = each.getMovie().calculateRate(each.getDaysRented(), 0);
thisAmount = each.getMovie().calculateRate(each.getDaysRented());
// add frequent renter points and bonus for a two day new release rental
frequentRenterPoints += each.getMovie().calculateBonus(each.getDaysRented());
//show figures for this rental
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package com.jalasoft.selenium.daniel.jauregui.movies;

public class Main {
public static void main(String[] args) {
/**
* Movies Class.
* @author Daniel Jauregui
*/
class Movies {
/**
* Constructor.
*/
public void movies() {
// Nothing to do
}
/**
* Initial method of application.
* @param args : Initial Arguments.
*/
public static void main(final String[] args) {
Customer customer = new Customer("Test");
customer.addRental(new Rental(new NewRelease("The Revenant",1), 2));
customer.addRental(new Rental(new Regular("Terminator",0), 2));
customer.addRental(new Rental(new NewRelease("The Revenant", 1), 2));
customer.addRental(new Rental(new Regular("Terminator", 0), 2));
System.out.println(customer.statement());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.jalasoft.selenium.daniel.jauregui.movies;

/**
* MovieAbs Abstract class.
* @author Daniel Jauregui
*/
abstract class MovieAbs implements MovieInt {
private String title;
private int bonus;

/**
* Constructor of Class.
* @param title will have the name of movie.
* @param bonus will have the value of bonus.
*/
public MovieAbs(final String title, final int bonus) {
this.title = title;
this.bonus = bonus;
}

/**
* Get the Bonus of movie.
* @return the integer number of bonus.
*/
public int getBonus() {
return this.bonus;
}

/**
* Set a bonus for a movie.
* @param bonus the new bonus value.
*/
public void setBonus(final int bonus) {
this.bonus = bonus;
}

/**
* Get the title of movie.
* @return an String with the title of movie.
*/
public String getTitle() {
return this.title;
}

/**
* Set a new title of movie.
* @param title will get the new title for the movie.
*/
public void setTitle(final String title) {
this.title = title;
}

/**
* Calculate the bonus for frequent renter points.
* @param rentedDays get the rented days of movie.
* @return the bonus if it is major than 0.
*/
public int calculateBonus(final int rentedDays) {
if ((this.bonus != 0) && (rentedDays > 1)) {
return (this.bonus + 1);
}
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jalasoft.selenium.daniel.jauregui.movies;
/**
* Interface MovieInt.
* @author Daniel Jauregui
*/
interface MovieInt {
/**
* calculateRate of movie.
* @param rentedDays give a number of days movie was rented.
* @return calculated rate.
*/
double calculateRate(int rentedDays);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package com.jalasoft.selenium.daniel.jauregui.movies;

public class NewRelease extends aMovie {

public NewRelease(String _title, int bonus) {
super(_title, bonus);
/**
* Class NewRelease.
*/
public class NewRelease extends MovieAbs {
private final int restOfRentedDays = 3;
/**
* Constructor of Children.
* @param title will contain the name of Movie.
* @param bonus will give to the movie a bonus.
*/
public NewRelease(final String title, final int bonus) {
super(title, bonus);
}

/**
*
* @param rentedDays: number of day where movie was rented.
* @return
*/
@Override
public double calculateRate(int rentedDays, double thisAmount) {
if (rentedDays <= 0) { return 0; }
thisAmount += rentedDays * 3;
return thisAmount;
public double calculateRate(final int rentedDays) {
if (rentedDays <= 0) {
return 0;
}
return (double) (rentedDays * restOfRentedDays);
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package com.jalasoft.selenium.daniel.jauregui.movies;

public class Regular extends aMovie {

public Regular(String _title, int bonus) {
super(_title,bonus);
/**
* Class NewRelease.
*/
public class Regular extends MovieAbs {
private final int restOfRentedDays = 2;
private final double multiplyOfRentedDays = 1.5;
/**
* Constructor of Children.
* @param title will contain the name of Movie.
* @param bonus will give to the movie a bonus.
*/
public Regular(final String title, final int bonus) {
super(title, bonus);
}

/**
*
* @param rentedDays: number of day where movie was rented.
* @return
*/
@Override
public double calculateRate(int rentedDays, double thisAmount) {
if (rentedDays <= 0) { return 0; }
thisAmount += 2;
if (rentedDays > 2)
thisAmount += (rentedDays - 2) * 1.5;
public double calculateRate(final int rentedDays) {
if (rentedDays <= 0) {
return 0;
}
double thisAmount = restOfRentedDays;
if (rentedDays > restOfRentedDays) {
thisAmount += (rentedDays - restOfRentedDays) * multiplyOfRentedDays;
}
return thisAmount;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package com.jalasoft.selenium.daniel.jauregui.movies;

/**
* Rental Class.
* @author Daniel Jauregui
*/
class Rental {
private final aMovie _movie;
private final int _daysRented;

public Rental(aMovie movie, int daysRented) {
_movie = movie;
_daysRented = daysRented;
private final MovieAbs movie;
private final int daysRented;
/**
* Constructor of Class.
* @param movie : Object of Abstract Class MovieAbs.
* @param daysRented : Days of movie was rented.
*/
public Rental(final MovieAbs movie, final int daysRented) {
this.movie = movie;
this.daysRented = daysRented;
}

/**
* Get the rented days of the movie rented.
* @return integer name as day.
*/
public int getDaysRented() {
return _daysRented;
return this.daysRented;
}

public aMovie getMovie() {
return _movie;
/**
* Get the object movie.
* @return an object of movie associated to this class.
*/
public MovieAbs getMovie() {
return this.movie;
}
}
}
Loading