Michael Anthony Judge Michael Anthony Judge - 11 days ago 8
Java Question

Output failing using the get.Name() in a driver/program file in Java

I have to make a program that is supposed to receive input for pet information and output it in a specific way. Normally this would be cake and take 10 minutes but we just moved into oop and I am having some trouble figuring out what to put in the mutator on the driver.

Driver:

import java.util.HashSet;
import java.util.Set;

public class JMPets {
private String petType;
private String petName;
private int petAge;
private double petWeight;
boolean isMale;

public void setType(String petType)
{
this.petType = petType;
}
public void setName(String petName)
{
this.petName = petName;
}
public void setAge (int petAge)
{
this.petAge = petAge;
}
public void setWeight(double petWeight)
{
this.petWeight = petWeight;
}
public String getType()
{
return petType;
}
public String getName()
{
return petName;
}
public int getAge()
{
return petAge;
}
public double getWeight()
{
return petWeight;
}

public void set(String petType, String petName, int petAge,
double petWeight)
{
//WHAT DO I PUT HERE

}

}





import java.util.Scanner;
public class JMUnit6 {


public static void main(String[] args) {

JMPets myPet1 = new JMPets();
JMPets myPet2 = new JMPets();
JMPets mypet3 = new JMPets();
Scanner stdIn = new Scanner(System.in);
System.out.println("Welcome to the Java Pet Tracker");
System.out.println("Please enter the type of Pet #1:");
String petType = stdIn.nextLine();

System.out.println("Please enter the name of Pet #1:");
String petName = stdIn.nextLine();

System.out.println("Please enter the age of " +petName+":");
int petAge = stdIn.nextInt();

System.out.println("Please enter the weight of "+petName+":");
double petWeight = stdIn.nextDouble();

System.out.println("Is "+petName+" Male?:");
boolean isMale = stdIn.nextBoolean();

myPet1.set(petType, petName, petAge, petWeight);


System.out.println(myPet1.getType());
System.out.println(myPet1.getName());
System.out.println(myPet1.getAge());
System.out.println(myPet1.getWeight());



}//end main
}//end class JMUnit6


Only output i get is null null 0 0.0.

Answer

Take a look at your setters, you already have an answer there.

this.petType = petType;
this.petName = petName;
this.petAge = petAge;
this.petWeight = petWeight;

You're also probably missing isMale.