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
32 changes: 30 additions & 2 deletions src/main/java/io/zipcoder/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
package io.zipcoder;

import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

public class Application {
}
public static void main(String[] args) {

HashMap<String, String> petMap = new HashMap<String, String>();
Scanner scan = new Scanner(System.in);
System.out.println("How many pets do you have ?");
int numberOfpets =scan.nextInt();
scan.nextLine();

//going through the loop and setting it equal to number of pets.
for (int i =0; i <numberOfpets; i++){
System.out.println("What kind of pet do you have ?");
//waits for input to be entered before continuing on to the next line.
String pet = scan.nextLine();
System.out.println("What is the name of your pet?");
String petName = scan.nextLine();
petMap.put(pet,petName);

}
//.keySet() returns all the keys in the hashmap, (petMap)

for (String i : petMap.keySet()){
System.out.printf("This pet is a %s named %s%n", i,petMap.get(i));
}


}
}
14 changes: 14 additions & 0 deletions src/main/java/io/zipcoder/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.zipcoder;

public class Cat extends Pet{

// Super keyword is involking constructor of the parent class
public Cat(String name) {
super(name);
}

@Override
public String speak() {
return "Meow!";
}
}
12 changes: 12 additions & 0 deletions src/main/java/io/zipcoder/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.zipcoder;

public class Dog extends Pet {
public Dog(String name) {
super(name);
}

@Override
public String speak() {
return "Bark!";
}
}
13 changes: 13 additions & 0 deletions src/main/java/io/zipcoder/Fish.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.zipcoder;

public class Fish extends Pet {

public Fish(String name) {
super(name);
}

@Override
public String speak() {
return "tinkles";
}
}
27 changes: 27 additions & 0 deletions src/main/java/io/zipcoder/Pet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.zipcoder;

public abstract class Pet {
// Since the Petclass has an abstract method , needed to declare this class abstract.

//Instance Variable
String name;
//Constructor
public Pet(String name) {
//this key word means it is referring to string name.
this.name = name;
}
//Getter retrieves info from instance variable
public String getName() {
return name;
}
// setter updates the value of a variable
public void setName(String name) {
this.name = name;
}
// The pet class must have a speak method that each subclass overrides
// All child classes should override this method. There is no point to implement this method in a parent class.
//making this method abstract will force subclasses to implement this method.
public abstract String speak();


}
31 changes: 31 additions & 0 deletions src/test/java/io/zipcoder/CatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.zipcoder;

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

public class CatTest {
@Test
public void testSpeak() {
// Arrange: create an instance variable (myCat) of the object to act on
Cat myCat = new Cat("Smalls");
String expected = "Meow!";
//Act: call method on our object
String actual = myCat.speak();
//Assert: check the outcome on what we expect.
Assert.assertEquals(expected,actual);
}
@Test
public void testGetName(){
Cat myCat = new Cat("Smalls");
String expected = "Smalls";
//Act: call method on our object
String actual = myCat.getName();
//Assert: check the outcome on what we expect.
Assert.assertEquals(expected,actual);

}
@Test
public void testSetName(){

}
}
29 changes: 29 additions & 0 deletions src/test/java/io/zipcoder/DogTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.zipcoder;

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

public class DogTest {
@Test
public void testSpeak() {
// Arrange: create an instance variable (myCat) of the object to act on
Dog myDog = new Dog("Sparky");
String expected = "Bark!";
//Act: call method on our object
String actual = myDog.speak();
//Assert: check the outcome on what we expect.
Assert.assertEquals(expected,actual);
}
@Test
public void testGetName(){
// Arrange: create an instance variable (myCat) of the object to act on
Dog myDog = new Dog("Sparky");
String expected = "Sparky";
//Act: call method on our object
String actual = myDog.getName();
//Assert: check the outcome on what we expect.
Assert.assertEquals(expected,actual);

}

}
28 changes: 28 additions & 0 deletions src/test/java/io/zipcoder/FishTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.zipcoder;

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

public class FishTest {
@Test
public void testSpeak() {
// Arrange: create an instance variable (myCat) of the object to act on
Fish myFish = new Fish("Tony");
String expected = "tinkles";
//Act: call method on our object
String actual = myFish.speak();
//Assert: check the outcome on what we expect.
Assert.assertEquals(expected, actual);
}

@Test
public void testGetName() {
// Arrange: create an instance variable (myCat) of the object to act on
Fish myFish = new Fish("Tony");
String expected = "Tony";
//Act: call method on our object
String actual = myFish.getName();
//Assert: check the outcome on what we expect.
Assert.assertEquals(expected, actual);
}
}
21 changes: 21 additions & 0 deletions src/test/java/io/zipcoder/PetTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.zipcoder;

import org.junit.Test;

public class PetTest {
//PetTest is an abstract and can not be instantiated
//create a concrete class that inherits the abstract

@Test
public void testGetName() {

}

@Test
public void testSetName() {
}

@Test
public void testSpeak() {
}
}