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
12 changes: 9 additions & 3 deletions src/main/java/com/zipcodewilmington/assessment1/Cat.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ public class Cat extends Pet {
* @param age age of this Cat
*/
public Cat(String name, Integer age) {

this.name = name;
this.age = age;
}

/**
* @param age age of this Cat
*/
public Cat(Integer age) {
this.age = age;
this.name = "Cat name";
}

/**
* @param name name of this Cat
*/
public Cat(String name) {

this.name = name;
this.age = 0;
}

/**
Expand All @@ -32,12 +36,14 @@ public Cat(String name) {
* age is 0
*/
public Cat() {
this.name = "Cat name";
this.age = 0;
}

/**
* @return meow as a string
*/
public String speak() {
return null;
return "Meow";
}
}
12 changes: 9 additions & 3 deletions src/main/java/com/zipcodewilmington/assessment1/Dog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ public class Dog extends Pet {
* @param age age of this dog
*/
public Dog(String name, Integer age) {

this.name = name;
this.age = age;
}

/**
* @param age age of this dog
*/
public Dog(Integer age) {
this.age = age;
this.name = "Dog name";
}

/**
* @param name name of this dog
*/
public Dog(String name) {

this.name = name;
this.age = 0;
}

/**
Expand All @@ -32,12 +36,14 @@ public Dog(String name) {
* age is 0
*/
public Dog() {
this.age = 0;
this.name = "Dog name";
}

/**
* @return bark as a string
*/
public String speak() {
return null;
return "Bark";
}
}
30 changes: 24 additions & 6 deletions src/main/java/com/zipcodewilmington/assessment1/Pet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,73 @@ public abstract class Pet implements Animal {
/**
* nullary constructor
* by default, pet has age of 0; name of "";
*
*/
String name;
Integer age;
PetOwner owner;

public Pet() {
name = "";
age = 0;
owner = null;
}

/**
* @param name name of this pet
*/
public Pet(String name) {
public Pet(String nm) {
name = nm;
age = 0;
owner = null;
}


/**
* @param age age of this pet
*/
public Pet(int age) {
public Pet(int ag) {
name = "";
age = ag;
owner = null;
}

/**
* @param name name of this pet
* @param age age of this pet
*/
public Pet(String name, int age) {
public Pet(String nm, int ag) {
name = nm;
age = ag;
owner = null;
}

/**
* @return name of this pet
*/
public String getName() {
return null;
return name;
}

/**
* @return age of this pet
*/
public Integer getAge() {
return null;
return age;
}

/**
* @param newPetOwner the new owner of this pet
* ensure this instance of `Pet` is added to the owner's composite `pets` list
*/
public void setOwner(PetOwner newPetOwner) {
owner = newPetOwner;
}

/**
* @return PetOwner object whose composite `pets` collection contains this Pet instance
*/
public PetOwner getOwner() {
return null;
return owner;
}
}
47 changes: 39 additions & 8 deletions src/main/java/com/zipcodewilmington/assessment1/PetOwner.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,60 @@
package com.zipcodewilmington.assessment1;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by leon on 2/16/18.
*/
public class PetOwner {

String ownerName;
List<Pet> ownerpets;
/**
* @param name name of the owner of the Pet
* @param pets array of Pet object
*/
public PetOwner(String name, Pet... pets) {
ownerName = name;
ownerpets = Arrays.asList(pets);
}

/**
* @param pet pet to be added to the composite collection of Pets
*/
public void addPet(Pet pet) {
ownerpets.add(pet);
}

/**
* @param pet pet to be removed from the composite collection Pets
*/
public void removePet(Pet pet) {

ownerpets.remove(pet);
}

/**
* @param pet pet to evaluate ownership of
* @return true if I own this pet
*/
public Boolean isOwnerOf(Pet pet) {
return null;
return ownerpets.contains(pet);
}

/**
* @return the age of the Pet object whose age field is the lowest amongst all Pets in this class
*/
public Integer getYoungetPetAge() {
return null;
int youngest = ownerpets.get(0).getAge();

for(int i = 0; i < ownerpets.size();i++){
if(ownerpets.get(i).getAge()<youngest)
youngest = ownerpets.get(i).getAge();
}

return youngest;
}


Expand All @@ -46,35 +64,48 @@ public Integer getYoungetPetAge() {
* @return the age of the Pet object whose age field is the highest amongst all Pets in this class
*/
public Integer getOldestPetAge() {
return null;
int oldest = ownerpets.get(0).getAge();

for(int i = 0; i < ownerpets.size();i++){
if(ownerpets.get(i).getAge()>oldest)
oldest = ownerpets.get(i).getAge();
}

return oldest;
}


/**
* @return the sum of ages of Pet objects stored in this class divided by the number of Pet object
*/
public Float getAveragePetAge() {
return null;
float totalAge = 0;

for(int i = 0; i < ownerpets.size();i++){
totalAge+=ownerpets.get(i).getAge();
}

return totalAge/ownerpets.size();
}

/**
* @return the number of Pet objects stored in this class
*/
public Integer getNumberOfPets() {
return null;
return ownerpets.size();
}

/**
* @return the name property of the Pet
*/
public String getName() {
return null;
return ownerName;
}

/**
* @return array representation of animals owned by this PetOwner
*/
public Pet[] getPets() {
return null;
return ownerpets.toArray(new Pet[0]);
}
}