Skip to content

Instantly share code, notes, and snippets.

@mikeymop
Last active July 2, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeymop/250307cf4a7f72e45e1208baa62dae14 to your computer and use it in GitHub Desktop.
Save mikeymop/250307cf4a7f72e45e1208baa62dae14 to your computer and use it in GitHub Desktop.
Pet Check-In
To update our current processes, we outline our current manual check-in process below, which involves
multiple steps and verifications.
First, we determine whether the pet is a dog or a cat. Next, we determine if boarding space is available
for the pet. There are currently 30 spaces for dogs and 12 spaces for cats. We would like the ability to
update these settings as needed. If boarding space is available, we identify whether the pet is a new or
returning visitor. If the pet has stayed with us before, we are seeking the ability to update information
as needed. If the pet is a new visitor, we would like the opportunity to collect all the appropriate
information.
Additionally, we would like the ability to gather information on the length of stay for each pet and if
grooming services are required. Grooming services are only offered for dogs that stay at Pet BAG for two
or more days. No grooming services are offered for cats.
package project1;
public class Dog extends Pet {
public int dogSpaceNbr;
private double dogWeight;
private boolean grooming;
public Dog(String name, int age) {
super(name, age, "Dog");
}
public double getDogWeight() {
return this.dogWeight;
}
public boolean getGrooming() {
return this.grooming;
}
public void setDogWeight(double weight) {
this.dogWeight = (double) weight;
}
public void setGrooming(boolean value) {
this.grooming = value;
}
}
import java.util.Scanner;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
public class Pet {
private String petType;
private String petName;
private int petAge;
private Map<Pet, Integer> dogSpace; // contains the Pet and days it is staying
private Dictionary<Pet, Integer> catSpace;
private int daysStay;
private int amountDue;
/**
* Pet, base class for Dog and Cat
* @param String name - Name of the Pet
* @param int age - Age of the Pet
* @param String type - Cat | Dog
*/
public Pet(String name, int age, String type) {
this.petName = name;
this.petAge = age;
this.petType = type;
this.dogSpace = new HashMap<Pet, Integer>();
}
public void checkIn(Pet pet) {
Scanner in = new Scanner(System.in);
System.out.println("How many days will your " + this.petType + " be staying?");
int days = (int) in.nextInt();
switch(this.petType) {
case "Dog":
if(days > 1) {
System.out.println("Do you require grooming services?");
String needsGrooming = in.next();
boolean grooming;
if(needsGrooming == "yes" || needsGrooming == "y") {
grooming = true;
}
else {
grooming = false;
}
this.checkInDog((Dog) pet, days, grooming); // handle the special dog cases
}
break;
case "Cat":
if(this.catSpace.size() < 12) {
this.catSpace.put(pet, days);
}
break;
}
in.close();
}
/**
* Contains extra steps for checking in a dog.
* @param pet - The dog object.
* @param days - Number of days staying.
* @param grooming - Whether or not the dog needs grooming.
*/
private void checkInDog(Dog pet, int days, boolean grooming) {
pet.setGrooming(grooming);
try {
if(this.dogSpace.size() < 30) {
this.dogSpace.put(pet, days);
pet.dogSpaceNbr = this.dogSpace.size() + 1;
pet.setDaysStay(days);
}
}
catch (Exception e) {
System.out.println("You're our first visitor!");
System.out.print(pet);
this.dogSpace.put(pet, days);
pet.dogSpaceNbr = 1;
System.out.println("" + pet.getPetName() + " will miss you, but is in good hands.");
}
}
package project1;
public class test {
public static void main(String args[]) {
Pet pet = new Pet("Spot", 12, "Dog" );
System.out.println("Pet name is " + pet.getPetName());
Dog dog = new Dog("Pepper", 15);
System.out.println("" + dog.getPetName() + " is " + dog.getPetAge() + " years old.");
Cat cat = new Cat("Bailey", 5);
System.out.println("" + cat.getPetName() + " is " + cat.getPetAge() + " years old.");
pet.checkIn(dog);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment