I have tried using the Scanner & Stringtokenizer classes to count the number of times a specific pet is inputed but end up getting the no output. I cannot seem to figure out what method I need to count the number of pets(dogs, cat, etc..) so I can get the right output for the number of dogs, cats, etc.
String pet,temp, output, dog = "dog", cat ="cat", other ="other";
double payment, totalPayment = 0, dogCount = 0, catCount = 0, otherCount = 0, totalDogNum = 0;
int more = 0;
while(more == JOptionPane.YES_OPTION)
{
pet = JOptionPane.showInputDialog(null,
"Enter the pet type ", "",JOptionPane.QUESTION_MESSAGE);
temp = JOptionPane.showInputDialog(null,
"Enter the payment for the appointment ", "",JOptionPane.QUESTION_MESSAGE);
payment = Double.parseDouble(temp);
more = JOptionPane.showConfirmDialog(null, "Would you like to add another pet?", "", JOptionPane.YES_NO_OPTION );
if (pet == dog )
{
dogCount = dogCount + 1;
}
else if (pet == cat)
{
catCount += 1;
}
else
{
otherCount += 1;
}
totalPayment += payment;
}
output = "Number of Dogs: "+ dogCount
+ "\n" + "Number of Cats: " + catCount
+ "\n" + "Number of Other Pets: " + otherCount