Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(1) Pet store The pet store program should start with the user being able to cho

ID: 3716093 • Letter: #

Question

(1) Pet store

The pet store program should start with the user being able to choose to adopt a pet or give a pet the to the shop. If the user wants to adopt a pet, they should be able to see either all available pets, unless they say they know what type of pet they want, then show only available pets of that type.

The 4 methods that will need to be created for this program should:

1. add new pets

2. get a pet adopted

3. show pets by type

4.show pets available for adoption

//Please use comments on code and upload a screenshot*************

The below code and screenshot is the skeleton "Object Class: Pets.java" Please add to that

import java.util.*;

public class Pets {
private double age; //age of the animal (e.g. for 6 months the age would be .5)
private String petName; //name of the animal
private String aType; //the type of the pet (e.g. "bird", "dog", "cat", "fish", etc)
private int collarID; //id number for the pets
private boolean isAdopted = false; //truth of if the pet has been adopted or not
private String newOwner;
private Date adoptionDate;

public Puppy(String pName, double pAge, String type) {
petName = pName;
age = pAge;
aType = type;
}

public void adoptPet(String owner, Date adoptionDate, int pID){
boolean isAdopted = true;
newOwner = owner;
this.adoptionDate = adoptionDate;
collarID = pID;
}
  
public String getPetType(){
return aType;
}
  
public int getPetAge(){
return age;
}
  
public String getPetName(){
return petName;
}
  
}

3 public class Pets t private double age; private String petName; //name of the animal private String aType; private int collarID; private boolean isAdopted-false; //truth of if the pet has been adopted or not private String newOwner private Date adoptionDate; 4 //age of the animal (e.g. for 6 months the age would be .5) //the type of the pet (e.g. "bird", "dog", "cat", "fish", etc) 6 7 8 9 //id number for the pets 12 public Puppy (String pName, double pAge, String type) petName -pName; age pAge; a lype type 16 17 18 19 20 21 public void adoptPet (String owner, Date adoptionDate, int pID) boolean isAdopted-true; newOwner- owner this.adoptionDate-adoptionDate; collarIDpID; 23 24 25 26 27 28 29 public String getPetType ) return aType; public int getPetAge return age; 31 32 public String getPetName) 34 35 36 37 38 return petName;

Explanation / Answer


//// PetsStore .java
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
public class PetsStore {
public static void main(String[] args) {
Pets pets= new Pets();
Scanner sc=new Scanner(System.in);
List<Pets> petList= new ArrayList<Pets>();
for(;;){
System.out.println("Menu List :");
System.out.println("1. Add New Pets");
System.out.println("2. Get a pet adopt");
System.out.println("3. Show pets by type");
System.out.println("4. Show pets available for adoption");
System.out.println("5. Quit");
System.out.println("Please Select Any One Option :");
int option =sc.nextInt();
if(option==1){
System.out.println("Please enter the pet Name");
String petname=sc.next();
System.out.println("Please enter the pet Age");
int petAge=sc.nextInt();
System.out.println("Please enter the pet Type");
String petType=sc.next();
System.out.println("Please enter the pet CollarId");
int petCollarId=sc.nextInt();
petList = addPets(petList,petname,petAge,petType,petCollarId);
}
if(option==2){
System.out.println("Please Enter the Pet Name That you Want to Adopt :");
String petname = sc.next();
petList=GetAdopted(petname,petList);
}
if(option==3){
   ShowPetsByType(petList);
}
if(option==4){
ShowPetsAdoption(petList);
}
if(option==5){
   System.out.println("Bye......");
break;
}
}
}
public static List<Pets> GetAdopted(String petname, List<Pets> petList) {
int flag=0;
for(Pets pet : petList){
if(pet.getPetName().equalsIgnoreCase(petname)){
flag=1;
pet.setAdoptated(true);
}
}
if(flag==0){
System.out.println("No pet found with this name");
}
else{
System.out.println("Pet Got Adopted.");
}
return petList;
}
public static void ShowPetsByType(List<Pets> petList) {
System.out.println("List Of Pets of Type Bird :");
for(Pets pet : petList){
if(pet.getaType().equalsIgnoreCase("bird")){
System.out.println(pet.getPetName());
}
}
System.out.println("List Of Pets of Type Dog :");
for(Pets pet : petList){
if(pet.getaType().equalsIgnoreCase("dog")){
System.out.println(pet.getPetName());
}
}
System.out.println("List Of Pets of Type Fish :");
for(Pets pet : petList){
if(pet.getaType().equalsIgnoreCase("fish")){
System.out.println(pet.getPetName());
}
}
System.out.println("List Of Pets of Type Cat :");
for(Pets pet : petList){
if(pet.getaType().equalsIgnoreCase("cat")){
System.out.println(pet.getPetName());
}
}
}
public static void ShowPetsAdoption(List<Pets> petList) {
System.out.println("List of pets that are not Adopted :");
System.out.println();
System.out.println("PetName"+" "+"PetAge"+" "+"PetType"+" "+"PetCollarId");
for(Pets pet : petList){
if(!pet.isAdoptated){
System.out.println(pet.getPetName()+" "+pet.getAge()+" "+pet.getaType()+" "+pet.getCollarId());
}
}
}
public static List<Pets> addPets(List<Pets> petList, String petname, int petAge, String petType, int petCollarId) {
Pets pets= new Pets();
pets.setPetName(petname);
pets.setAdoptated(false);
pets.setAdoptionDate(new Date());
pets.setAge(petAge);
pets.setaType(petType);
pets.setCollarId(petCollarId);
petList.add(pets);
System.out.println("Pet Added Succesfully");
return petList;
}


}

//////////////Pets.java

import java.util.Date;
public class Pets {
public double age;
public String petName;
public String aType;
public int collarId;
public boolean isAdoptated;
public Date adoptionDate;
public double getAge() {
return age;
}
public void setAge(double age) {
this.age = age;
}
public String getPetName() {
return petName;
}
public void setPetName(String petName) {
this.petName = petName;
}
public String getaType() {
return aType;
}
public void setaType(String aType) {
this.aType = aType;
}
public int getCollarId() {
return collarId;
}
public void setCollarId(int collarId) {
this.collarId = collarId;
}
public boolean isAdoptated() {
return isAdoptated;
}
public void setAdoptated(boolean isAdoptated) {
this.isAdoptated = isAdoptated;
}
public Date getAdoptionDate() {
return adoptionDate;
}
public void setAdoptionDate(Date adoptionDate) {
this.adoptionDate = adoptionDate;
}
@Override
public String toString() {
return "Pets [age=" + age + ", petName=" + petName + ", aType=" + aType + ", collarId=" + collarId
+ ", isAdoptated=" + isAdoptated + ", adoptionDate=" + adoptionDate + "]";
}


}