Question

*PLEASE HELP ASAP*

Lab 14 lnstructions Generic Methods Background Generic methods provide a way to produce functionality that works with virtual

Pet.java

/*
 * Class Pet
 * 
 * 
 * 
 */
public class Pet
{
  /*
   *  Instance variables
   */
  private String name;
  private String species;
  private String parent;
  private String birthday;
  
  /*
   *  Constructors
   */
  public Pet( )
  {
    // This is a null or default constructor
  }  //e end null constructor
  
  public Pet( String aName,
              String aSpecies,
              String aParent,
              String aBDay )
  {
    setName( aName );
    setSpecies( aSpecies );
    setParent( aParent );
    setBirthday( aBDay );
  }  // end full constructor
  
  /*
   * Set methods
   */
  public final void setName( String aName )
  {
    name = aName;
  }  // end setName
  
  public final void setSpecies( String aSpecies )
  {
    species = aSpecies;
  }  // end setSpecies
  
  public final void setParent( String aParent )
  {
    parent = aParent;
  }  // end setParent
  
  public final void setBirthday( String aBDay )
  {
    birthday = aBDay;
  }  // end setName
 
  
  /*
   * Get methods
   */
  public final String getName( )
  {
    return name;
  } // end getName
  
  public final String getSpecies( )
  {
    return species;
  } // end getSpecies
  
  public final String getParent( )
  {
    return parent;
  } // end getParent
  
  public final String getBirthday( )
  {
    return birthday;
  } // end getBirthday

  /*
   * toString method
   */
  public String toString( )
  {
    return String.format( "%s, whose fur-parent is %s, is a(n) %s born on %s.%n",
                          getName( ),
                          getParent( ),
                          getSpecies( ),
                          getBirthday( ) );
  }  // end toString
  
}  // end Pet

ArrayMethods.java

/*
 * Class Pet
 * 
 * 
 * 
 */
public class Pet
{
  /*
   *  Instance variables
   */
  private String name;
  private String species;
  private String parent;
  private String birthday;
  
  /*
   *  Constructors
   */
  public Pet( )
  {
    // This is a null or default constructor
  }  //e end null constructor
  
  public Pet( String aName,
              String aSpecies,
              String aParent,
              String aBDay )
  {
    setName( aName );
    setSpecies( aSpecies );
    setParent( aParent );
    setBirthday( aBDay );
  }  // end full constructor
  
  /*
   * Set methods
   */
  public final void setName( String aName )
  {
    name = aName;
  }  // end setName
  
  public final void setSpecies( String aSpecies )
  {
    species = aSpecies;
  }  // end setSpecies
  
  public final void setParent( String aParent )
  {
    parent = aParent;
  }  // end setParent
  
  public final void setBirthday( String aBDay )
  {
    birthday = aBDay;
  }  // end setName
 
  
  /*
   * Get methods
   */
  public final String getName( )
  {
    return name;
  } // end getName
  
  public final String getSpecies( )
  {
    return species;
  } // end getSpecies
  
  public final String getParent( )
  {
    return parent;
  } // end getParent
  
  public final String getBirthday( )
  {
    return birthday;
  } // end getBirthday

  /*
   * toString method
   */
  public String toString( )
  {
    return String.format( "%s, whose fur-parent is %s, is a(n) %s born on %s.%n",
                          getName( ),
                          getParent( ),
                          getSpecies( ),
                          getBirthday( ) );
  }  // end toString
  
}  // end Pet

Sample Output Array integerArray contains: 1 2 3 4 5 Array doubleArray contains: 1.1 2.2 3.3 4.4 5.5 Array characterArray con

0 0
Add a comment Improve this question Transcribed image text
Answer #1
        public static<T> void printRange(T data[], int start, int end) {
                if(start < 0 || start > end || end >= data.length) {
                        System.out.println("Invalid parameters passed.");
                } else {
                        for(int i=start; i<=end; i++) {
                                System.out.println(data[i]);
                        }
                }
        }

        public static<T> T returnItem(T data[], int index) {
                return data[index];
        }
        
        you have shared the same pet class instead of arraymethods class.. but still the given methods above should fit in ArrayMethods without any issues.
        
Add a comment
Know the answer?
Add Answer to:
*PLEASE HELP ASAP* Pet.java /* * Class Pet * * * */ public class Pet {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • public class Pet {    //Declaring instance variables    private String name;    private String species;...

    public class Pet {    //Declaring instance variables    private String name;    private String species;    private String parent;    private String birthday;    //Zero argumented constructor    public Pet() {    }    //Parameterized constructor    public Pet(String name, String species, String parent, String birthday) {        this.name = name;        this.species = species;        this.parent = parent;        this.birthday = birthday;    }    // getters and setters    public String getName() {        return name;   ...

  • Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; //...

    Code in JAVA UML //TEST HARNESS //DO NOT CHANGE CODE FOR TEST HARNESS import java.util.Scanner; // Scanner class to support user input public class TestPetHierarchy { /* * All the 'work' of the process takes place in the main method. This is actually poor design/structure, * but we will use this (very simple) form to begin the semester... */ public static void main( String[] args ) { /* * Variables required for processing */ Scanner input = new Scanner( System.in...

  • How to solve this problem? Consider the following class : public class Store Public final double...

    How to solve this problem? Consider the following class : public class Store Public final double SALES TAX_RATE = 0.063B private String name; public Store(String newName) setName ( newName); public String getName () { return name; public void setName (String newName) { name = newName; public String toString() return "name: “ + name; Write a class encapsulating a web store, which inherits from Store. A web store has the following additional attributes: an Internet Address and the programming language in...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • LAB: Pet information (derived classes)

    LAB: Pet information (derived classes)The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private field for dogBreed. Complete main() to:create a generic pet and print information using printInfo().create a Dog pet, use printInfo() to print information, and add a statement to print the dog's breed using the getBreed() method.Ex. If the input is:Dobby 2 Kreacher 3 German Schnauzerthe output is:Pet Information:     Name: Dobby    Age: 2 Pet Information:     Name: Kreacher    Age: 3    Breed: German SchnauzerPetInformation.javaimport java.util.Scanner; public class PetInformation {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);       Pet myPet = new Pet();       Dog myDog = new Dog();              String petName, dogName, dogBreed;       int petAge, dogAge;       petName = scnr.nextLine();       petAge = scnr.nextInt();       scnr.nextLine();...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • I need help with this Mammal: public class Mammal extends Pet{     String Vaccin...

    I need help with this Mammal: public class Mammal extends Pet{     String Vaccination="";     public Mammal(String name, String parent, String species, String birthday, String Vaccination) {           //Accessing the super class Constructor and setting the variables.         super(name,parent,species, birthday);         this.Vaccination=Vaccination;     } // end Mammal     public String getVaccination() {         return Vaccination;     } // end getVaccination     public void setVaccination(String Vaccination) {         this.Vaccination = Vaccination;     } // end setVaccination     @Override     public String toString() {         return super.toString()+". This Mammal requires following vaccinations "+ Vaccination;     } // end...

  • java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the...

    java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date {    private String month;    private String day;    private String year;    public Date(String month, String day, String year) {       this.month = month;       this.day = day;       this.year = year;    }    public String getMonth() {       return month;    }    public String getDay() {       return day;    }    public String...

  • public class Fish { private String species; private int size; private boolean hungry; public Fish() {...

    public class Fish { private String species; private int size; private boolean hungry; public Fish() { } public Fish(String species, int size) { this.species = species; this.size = size; } public String getSpecies() { return species; } public int getSize() { return size; } public boolean isHungry() { return hungry; } public void setHungry(boolean hungry) { this.hungry = hungry; } public String toString() { return "A "+(hungry?"hungry":"full")+" "+size+"cm "+species; } }Define a class called Lake that defines the following private...

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT