diff --git a/src/main/java/com/serenitydojo/Cat.java b/src/main/java/com/serenitydojo/Cat.java new file mode 100644 index 0000000..de3aeab --- /dev/null +++ b/src/main/java/com/serenitydojo/Cat.java @@ -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; + } + +} diff --git a/src/main/java/com/serenitydojo/Dog.java b/src/main/java/com/serenitydojo/Dog.java new file mode 100644 index 0000000..c824c92 --- /dev/null +++ b/src/main/java/com/serenitydojo/Dog.java @@ -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; + } +} diff --git a/src/test/java/com/serenitydojo/WhenCreatingObjectsTest.java b/src/test/java/com/serenitydojo/WhenCreatingObjectsTest.java new file mode 100644 index 0000000..3bd2533 --- /dev/null +++ b/src/test/java/com/serenitydojo/WhenCreatingObjectsTest.java @@ -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()); + } + +} diff --git a/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithFloatingPointNumbers.java b/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithFloatingPointNumbers.java index 12fc8b7..0dae51a 100644 --- a/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithFloatingPointNumbers.java +++ b/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithFloatingPointNumbers.java @@ -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; @@ -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)); } @@ -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)); } diff --git a/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithStrings.java b/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithStrings.java index 379ec3f..4b59798 100644 --- a/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithStrings.java +++ b/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithStrings.java @@ -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")); } @@ -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")); } @@ -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")); } @@ -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)); } @@ -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")); } } diff --git a/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithWholeNumbers.java b/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithWholeNumbers.java index 326abf6..36a8c13 100644 --- a/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithWholeNumbers.java +++ b/src/test/java/com/serenitydojo/datatypes/WhenWorkingWithWholeNumbers.java @@ -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)); } }