From db90eadf632c910242c6e6fc227d97cf6633870f Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Wed, 7 May 2025 08:18:29 +0000 Subject: [PATCH 1/3] Setting up GitHub Classroom Feedback From ee4cc8a5036fc2d17266da067f29417801d7c8ac Mon Sep 17 00:00:00 2001 From: Toader Adrian Date: Wed, 7 May 2025 11:40:06 +0200 Subject: [PATCH 2/3] Completed exercises 1-3 All tests are passed. One exception: for the conversion between Celsius to Fahrenheit, the number is a `double`, not a `float`. --- .../datatypes/WhenWorkingWithFloatingPointNumbers.java | 5 +++++ .../serenitydojo/datatypes/WhenWorkingWithStrings.java | 10 ++++++++++ .../datatypes/WhenWorkingWithWholeNumbers.java | 5 +++++ 3 files changed, 20 insertions(+) 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)); } } From 9a23e3391c893246a3236821f1969159f794b856 Mon Sep 17 00:00:00 2001 From: Toader Adrian Date: Wed, 7 May 2025 15:00:39 +0200 Subject: [PATCH 3/3] Resolve lesson-3-exercises Lesson 3 exercises is about classes and objects. The purpose is to create a new class and a few methods to get the name, the favorite toy and the age. --- src/main/java/com/serenitydojo/Cat.java | 30 +++++++++++++++++ src/main/java/com/serenitydojo/Dog.java | 25 ++++++++++++++ .../serenitydojo/WhenCreatingObjectsTest.java | 33 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 src/main/java/com/serenitydojo/Cat.java create mode 100644 src/main/java/com/serenitydojo/Dog.java create mode 100644 src/test/java/com/serenitydojo/WhenCreatingObjectsTest.java 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()); + } + +}