Greetings,
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(System.in);
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 = input.next();
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 = input.next();
boolean claws = true;
System.out.println("Does the cat have claws? T or F: ");
String answer = input.next();
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("\n");
cat1.setName(name);
cat1.setAge(age);
cat1.setClaws(claws);
cat2.setName(name);
cat2.setAge(age);
cat2.setClaws(claws);
cat3.setName(name);
cat3.setAge(age);
cat3.setClaws(claws);
}
System.out.println("The Cats over 3 with claws are: ");
if(cat1.getAge() > 3 && cat1.getClaws() == true)
{
System.out.println(cat1.getName());
System.out.println(cat1.getAge());
}
if(cat2.getAge() > 3 && cat2.getClaws() == true)
{
System.out.println(cat2.getName());
System.out.println(cat2.getAge());
}
if(cat3.getAge() > 3 && cat3.getClaws() == true)
{
System.out.println(cat3.getName());
System.out.println(cat3.getAge());
}
}
}