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

Pet store The pet store program should start with the user being able to choose

ID: 3714934 • Letter: P

Question

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 Comment on Code************

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


//Add a new Pet and return the object of the newly added pet
Pets addpet(string name,double age,string type,int collerid)
{
Pets p=new Pet();
p.petName=name;
p.age=age;
p.aType=type;
p.collarID=collerId;
p.isAdopted=false;
rertun p;
}
//adopt the pet of given type;
void adopt(Pets petlist[],String ownerName,String type,Date adoptDate)
{
for(int i=0;i<petlist.length;i++)
{
if(petlist[i].isAdopted==false && petlist.Type.equalsIgnoreCase(type ) )
{
petlist[i].isAdopted=true;
petlist[i].newOwner=ownerName;
petlist[i].adoptionDate=adoptDate;
return ;
}
}
}
void Available(Pets p[] )
{
System.out.println("list of not adopted pets");
for(int i=0;i<p.length;i++)
{
if(p[i].isAdopted==false)
System.out.println(p[i].petName+" "+p[i].age+" "+p[i].aType+" "+p[i].collerID);
}
}
//showing pets by its type
void showBytype(Pets p[])
{
Set<String> set = new Set<String>();
for(int i=0;i<p.length;i++){
set.add(p[i].aType);
}
Iterator<String> itr = set.iterator();
while(itr.hasNext())
{
String type = itr.next();
system.out.println(type+"of pet list :");
for(int i=0;i<p.length;i++){
if(p[i].aType.equalsIgnoreCase(type))
{
System.out.println(p[i].petName+" "+p[i].age+" "+p[i].aType+" "+p[i].collerID+" "+p[i].isAdopted);
}
}
System.out.println(" ");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote