File tree Expand file tree Collapse file tree 5 files changed +67
-0
lines changed
Expand file tree Collapse file tree 5 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ # [ Classy Extentions] ( https://www.codewars.com/kata/classy-extentions " https://www.codewars.com/kata/55a14aa4817efe41c20000bc ")
2+
3+ The goal of this kata is to train the basic OOP concepts of inheritance and method overriding.
4+
5+ You will be preloaded with the ` Animal ` class, so you should only edit the ` Cat ` class.
6+
7+ ### Task
8+
9+ Your task is to complete the ` Cat ` class which extends ` Animal ` and replace the ` speak ` method to return the cats name + meows.
10+ e.g. ` 'Mr Whiskers meows.' `
11+
12+ The name attribute is accessible in the class with ` this.name ` .
13+
14+ Reference: [ Oracle docs] ( https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html )
Original file line number Diff line number Diff line change 1+ class Animal {
2+ protected final String name ;
3+
4+ Animal (String name ) {
5+ this .name = name ;
6+ }
7+
8+ public String speak () {
9+ return this .name + " makes a noise." ;
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ class Cat extends Animal {
2+ Cat (String name ) {
3+ super (name );
4+ }
5+
6+ @ Override
7+ public String speak () {
8+ return "%s meows." .formatted (this .name );
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ import static org .junit .jupiter .api .Assertions .assertEquals ;
2+ import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
3+
4+ import org .junit .jupiter .api .Test ;
5+
6+ class SampleTest {
7+ @ Test
8+ void wildBoar () {
9+ Animal animal = new Animal ("Wild Boar" );
10+ assertEquals ("Wild Boar makes a noise." , animal .speak ());
11+ }
12+
13+ @ Test
14+ void mrWhiskers () {
15+ Cat cat = new Cat ("Mr Whiskers" );
16+ assertEquals ("Mr Whiskers meows." , cat .speak ());
17+ assertInstanceOf (Animal .class , cat );
18+ }
19+
20+ @ Test
21+ void lamp () {
22+ Cat cat = new Cat ("Lamp" );
23+ assertEquals ("Lamp meows." , cat .speak ());
24+ }
25+
26+ @ Test
27+ void moneyBags () {
28+ Cat cat = new Cat ("$$Money Bags$$" );
29+ assertEquals ("$$Money Bags$$ meows." , cat .speak ());
30+ }
31+ }
Original file line number Diff line number Diff line change 3131- [ Century From Year] ( century-from-year " 5a3fe3dde1ce0e8ed6000097 ")
3232- [ Circles in Polygons] ( circles-in-polygons " 5a026a9cffe75fbace00007f ")
3333- [ Classic Hello World] ( classic-hello-world " 57036f007fd72e3b77000023 ")
34+ - [ Classy Extentions] ( classy-extentions " 55a14aa4817efe41c20000bc ")
3435- [ Closest elevator] ( closest-elevator " 5c374b346a5d0f77af500a5a ")
3536- [ Collatz Conjecture (3n+1)] ( collatz-conjecture-3n-plus-1 " 577a6e90d48e51c55e000217 ")
3637- [ Collinearity] ( collinearity " 65ba420888906c1f86e1e680 ")
You can’t perform that action at this time.
0 commit comments