I'm having problems with my output. Essentially I am just trying to print out any Cat who is over 3 years old and has Claws. But my output keeps printing out either nothing at all or the 3rd cat 3 times. I've struggled with this for hours trying to figure out why.. any ideas?
This is my driver java file. It will compile and run just fine but it doesn't work like it is supposed to..

import java.util.Scanner;

public class NathanialProg6
 public static void main(String[] args)
  Scanner input = new Scanner(;

  Cat cat1 = new Cat();
  Cat cat2 = new Cat();
  Cat cat3 = new Cat();
  int numberOfCats = 3;

  for(int i = 0; i < numberOfCats; i++)
  System.out.println("Enter the name of Cat" + (i+1) + ":");
  String name =;

  System.out.println("Enter the age of Cat" + (i+1) + ":");
  int age = input.nextInt();

  System.out.println("Enter the weight of Cat" + (i+1) + ":");
  double weight = input.nextDouble();

  System.out.println("Enter the breed of Cat" + (i+1) + ":");
  String breed =;

  boolean claws = true;
  System.out.println("Does the cat have claws? T or F: ");
  String answer =;
  if (answer.charAt(0) == 'T' || answer.charAt(0) == 't')
      claws = true;
  else if (answer.charAt(0) == 'F' || answer.charAt(0) == 'f')
      claws = false;
  else { System.out.println("Invalid input must be T or F"); }



  System.out.println("The Cats over 3 with claws are: ");

  if(cat1.getAge() > 3 && cat1.getClaws() == true)
  if(cat2.getAge() > 3 && cat2.getClaws() == true)
  if(cat3.getAge() > 3 && cat3.getClaws() == true)


Lines 43-51 you set the same data for all 3 cats, using the data from the third/last pass of you input loop, so when you print them of course you see the same data
You need to set cat1 during the first pass of your loop, cat2 in the second pass (etc).
(ps: An array of Cats would work very well here.)

I dont know much about arrays yet but I did get it figured out. I had create three separate loops for cats 1-3. Painful but it worked.

OK, but just for your information, the array would work something like this:
instead of Cat cat1, cat2, cat3 you have

Cat[] cats = new Cat[3];

then the three Cats are cats[0], cats[1] and cats[2]

then the loop is like

 for(int i = 0; i < numberOfCats; i++) {
    cats[i] = new Cat();
    // prompt for name etc
    // etc

just think what will happen when the next exercise is the same but for 10 cats!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.