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
Next Next commit
Adding Shape and Movies projects.
  • Loading branch information
jdjBolivia committed Mar 8, 2017
commit 5377c07f5e13037f78e012c570d97891c7116de4
65 changes: 65 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.jalasoft.selenium;

import java.util.Enumeration;
import java.util.Vector;

class Customer {
private String _name;
private Vector _rentals = new Vector();

public Customer(String name) {
_name = name;
}

public void addRental(Rental arg) {
_rentals.addElement(arg);
}

public String getName() {
return _name;
}

public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = _rentals.elements();
String result = "Rental Record for " + getName() + "\n";
while (rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental) rentals.nextElement();
//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;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jalasoft.selenium;

public class Main {

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.

Remove this unnecessary class
because it will replaced by unit tests

public static void main(String[] args) {
Customer customer = new Customer("Test");
customer.addRental(new Rental(new Movie("The Revenant", 1), 2));
customer.addRental(new Rental(new Movie("Terminator", 0), 2));
System.out.println(customer.statement());
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jalasoft.selenium;

public class Movie {
public static final int CHILDRENS = 2;
public static final int REGULAR = 0;
public static final int NEW_RELEASE = 1;

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.

Do you still need to keep those constants ?
you need to take advantage of inheritance here.

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;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/Rental.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.jalasoft.selenium;

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;
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/movies/movieType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.jalasoft.selenium;

/**
* Created by Automation on 3/6/2017.
*/
public abstract class movieType {

public double calculateAmount;
}


public class childrens extends movieType {

private final int priceCode = 2;

public childrens(){}

public double calculateAmount(){

}
}

public class regular extends movieType {

private final int priceCode = 0;

public regular(){}

public double calculateAmount(){

}
}

public class new_release extends movieType {

private final int priceCode = 1;

public new_release(){}

public double calculateAmount(){

}
}

47 changes: 47 additions & 0 deletions src/main/java/com/jalasoft/selenium/leonardo/shape/baseShape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.jalasoft.selenium;

/**
* Created by Automation on 3/3/2017.
*/

/** calculo del area y perimetro de un circulo, cuadrado y rectangulo */
/** 1. herencia 2. abstract class or interface 3. unit test */
public abstract class baseShape {

abstract double calculateArea();

abstract double calculatePerimeter();

}

/**
public class circleShape extends baseShape {

}

public class rectangleShape extends baseShape{
int width;

public float areaShape(){
return areaShape

}

public float perimeterShape(){

}

}public class squareShape extends rectangleShape{

public float areaShape(){

}

public float perimeterShape(){

}

}*/



Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.jalasoft.selenium;

/**
* Created by Automation on 3/3/2017.
*/
public class circleShape extends baseShape {
private double radio;

public circleShape(double radio){ /**constructor instanciar clase*/
this.radio = radio;
}

public double calculateArea(){
double returnValue;
return returnValue = 3.14*(this.radio*2);
}

public double calculatePerimeter(){
double returnValue;
return returnValue = 2*3.14*this.radio;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jalasoft.selenium;

/**
* Created by Automation on 3/3/2017.
*/
public class rectangleShape extends baseShape{
private double l;
private double w;

public rectangleShape(double l, double w){ /**instanciar clase*/
this.l = l;
this.w = w;
}

public double calculateArea(){
double returnValue;
return returnValue = this.l*this.w;
}

public double calculatePerimeter(){
double returnValue;
return returnValue = 2*(this.l+this.w);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jalasoft.selenium;

/**
* Created by Automation on 3/3/2017.
*/
public class squareShape extends rectangleShape{

public squareShape(double l){ /**instanciar clase*/
super (l,l);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.jalasoft.selenium;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Automation on 3/3/2017.
*/
public class circleShapeTest {

private static final int DELTA = 0;

private baseShape circle;

@Before
public void setUp(){
//Given
final int radio = 5;
circle = new circleShape(radio);
}

@Test /**nomenclatura 1*/
public void testCalculateAreaWhen() {

//when - action to test
final double actualArea = circle.calculateArea();

//then - assertion
final double expectedArea = 10;
assertEquals(expectedArea, actualArea, DELTA);
}

@Test /**nomenclatura 2*/
public void test_calculatePerimeter_when() {

//when - action to test
final double actualPerimeter = circle.calculatePerimeter();

//then - assertion
final double expectedPerimeter = 10;
assertEquals(expectedPerimeter, actualPerimeter, DELTA);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.jalasoft.selenium;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Automation on 3/6/2017.
*/
public class rectangleShapeTest {

private static final int DELTA = 0;

private baseShape rectangle;

@Before
public void setUp(){
//Given
final double l = 5;
final double w = 7;
rectangle = new rectangleShape(l, w);
}

@Test /**nomenclatura 1*/
public void testCalculateAreaWhen() {

//when - action to test
final double actualArea = rectangle.calculateArea();

//then - assertion
final double expectedArea = 10;
assertEquals(expectedArea, actualArea, DELTA);
}

@Test /**nomenclatura 2*/
public void testCalculatePerimeterWhen() {

//when - action to test
final double actualPerimeter = rectangle.calculatePerimeter();

//then - assertion
final double expectedPerimeter = 10;
assertEquals(expectedPerimeter, actualPerimeter, DELTA);
}
}
Loading