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
30 changes: 30 additions & 0 deletions src/main/java/com/serenitydojo/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.serenitydojo;

public class Cat {
private String name;
private String favoriteFood;
private int age;

public Cat(String name, String favoriteFood, int age) {
this.name = name;
this.favoriteFood = favoriteFood;
this.age = age;
}

public void setFavoriteFood(String favoriteFood) {
this.favoriteFood = favoriteFood;
}

public String getName() {
return name;
}

public String getFavoriteFood() {
return favoriteFood;
}

public int getAge() {
return age;
}

}
25 changes: 25 additions & 0 deletions src/main/java/com/serenitydojo/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.serenitydojo;

public class Dog {
public String name;
public String favoriteToy;
public int age;

public Dog(String name, String favoriteToy, int age) {
this.name = name;
this.favoriteToy = favoriteToy;
this.age = age;
}

public String getName() {
return name;
}

public String getFavoriteToy() {
return favoriteToy;
}

public int getAge() {
return age;
}
}
33 changes: 33 additions & 0 deletions src/test/java/com/serenitydojo/WhenCreatingObjectsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.serenitydojo;

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

public class WhenCreatingObjectsTest {

@Test
public void creating_a_cat(){
String name = "Felix";
String favoriteFood = "Tuna";
int age = 4;

// instantiate the Cat class as an object: Felix
Cat felix = new Cat("Felix", "Tuna", 4); // this is the constructor for the Cat class

System.out.println(felix.getName());
System.out.println(felix.getFavoriteFood());

// instantiate the Cat class as an object: Spot
Cat spot = new Cat("Spot", "Fish", 3); // this is the constructor for the Cat class
System.out.println("Spot's age is " + spot.getAge());
}

@Test
public void creating_a_dog(){
Dog fido = new Dog("Fido", "Bone", 5);
Assert.assertEquals("Fido", fido.getName());
Assert.assertEquals("Bone", fido.getFavoriteToy());
Assert.assertEquals(5, fido.getAge());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.Test;

import static java.lang.Math.round;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

Expand All @@ -18,6 +19,8 @@ public void convertToFarenheit() {

// TODO: Use a floating point calculation to calculate the farenheit equivalent of the celcius value.

farenheit = (double) 9 / 5 * celcius + 32;

assertThat(farenheit, equalTo(80.6));
}

Expand All @@ -32,6 +35,8 @@ public void convertMetersToFeet() {

// TODO: Use a floating point calculation to calculate the correct weight in pounds

weightInPounds = weightInKilograms * 2.20462;

assertThat(weightInPounds, equalTo(110.231));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public void convertToLowerCase() {
String lowerCaseTitle = "";
// TODO: Convert the book title to lower case and assign it to the lowerCaseTitle variable

lowerCaseTitle = bookTitle.toLowerCase();

assertThat(lowerCaseTitle, equalTo("the cat in the hat"));

}
Expand All @@ -25,6 +27,8 @@ public void convertToUpperCase() {
String upperCaseTitle = "";
// TODO: Convert the book title to upper case and assign it to the lowerCaseTitle variable

upperCaseTitle = bookTitle.toUpperCase();

assertThat(upperCaseTitle, equalTo("THE CAT IN THE HAT"));
}

Expand All @@ -35,6 +39,8 @@ public void trimExtraSpaces() {
String trimmedTitle = "";
// TODO: Trim the spaces before and after the title text

trimmedTitle = bookTitle.trim();

assertThat(trimmedTitle, equalTo("The Cat In The Hat"));
}

Expand All @@ -45,6 +51,8 @@ public void findTheLengthOfAString() {
int length = 0;
// TODO: Find the number of characters in the string

length = bookTitle.length();

assertThat(length, equalTo(18));
}

Expand All @@ -55,6 +63,8 @@ public void replacingAText() {
String updatedTitle = "";
// TODO: Replace the word "Cat" with "Dog

updatedTitle = bookTitle.replace("Cat", "Dog");

assertThat(updatedTitle, equalTo("The Dog In The Hat"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ public void addingNumbersTogether() {
int targetYear = 0;

// TODO: create a new int variable called timeJump and assign it a value

int timeJump = 30;

// Next, add this variable to initialYear and assign the result to targetYear, so that targetYear is equal to 2015

targetYear = initialYear + timeJump;

assertThat(targetYear, equalTo(2015));
}
}