I am making a very simple Java application called "Amazing Pets." It involves Humans and their Pets (Cats or Dogs). In this case, we are dealing with the Dogs. How do I create an instance method for Humans (called makeDogMakeNoise) which calls the makeNoise on the Dog and passes a random integer as a parameter? The makeNoise method prints random noise strings to the console. For Example "Ghost barks", "Ghost woofs, "Ghost whimpers". Can anyone please assist on this matter as I cannot seem to find any reliable resources online? Thank you in advance.
AmazingPets.java
public class AmazingPets {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Welcome to Pets and Humans! Created By Marc Beepath.\n____________________________\n");
Dogs firstDog = new Dogs("Ghost");
Humans firstName = new Humans("Alex");
Dogs secondDog = new Dogs("Paperbag");
Humans secondName = new Humans("Michael");
Cats firstCat = new Cats("Tom");
Cats secondCat = new Cats("Mr Furball");
Humans thirdName = new Humans("Bryan");
Humans fourthName = new Humans("Julie");
System.out.printf("%s's dog's name is %s.\n", firstName.getHumanName(), firstDog.getDogName());
System.out.printf("%s's dog's name is %s.\n", secondName.getHumanName(), secondDog.getDogName());
System.out.printf("%s's cat's name is %s.\n", thirdName.getHumanName(), firstCat.getCatName());
System.out.printf("%s's cat's name is %s.\n", fourthName.getHumanName(), secondCat.getCatName());
System.out.printf("\n\nHow many Humans have been created? To get your answer type in the console 'population'. ");
Scanner scan = new Scanner(System.in);
String myLine = scan.nextLine();
String pop = "population";
if (myLine.equalsIgnoreCase(pop)) {
System.out.printf("There are %s Humans.\n", Humans.populationCount());
} else {
System.out.printf("There was an error getting the Population.\n");
}
}
Humans.java
public class Humans {
private String mHumanName;
private static int humanCount = 0;
public Humans(String humanName){
mHumanName = humanName;
humanCount++;
}
public String getHumanName(){
return mHumanName;
}
public static int populationCount() {
return humanCount;
}
}
Dogs.java
public class Dogs {
private final String mDogName;
public Dogs(String dogName){
mDogName = dogName;
}
public String getDogName(){
return mDogName;
}
}