I need the output to look like this: Enter the name of Cat 1: Kim Enter the age
ID: 3627335 • Letter: I
Question
I need the output to look like this:Enter the name of Cat 1: Kim
Enter the age of Cat 1: 1
Enter the weight of Cat 1: 5
Enter the breed of Cat 1: hairy1
Does the cat have claws? True or False?: True
Enter the name of Cat 2: Eric
Enter the age of Cat 2: 4
Enter the weight of Cat 2: 5
Enter the breed of Cat 2: hairy2
Does the cat have claws? True or False?: True
Enter the name of Cat 3: Jerry
Enter the age of Cat 3: 5
Enter the weight of Cat 3: 5
Enter the breed of Cat 3: hairy3
Does the cat have claws? True or False?: False
The Cats over 3 with claws are:
Name: Eric
Age: 4 Years Old
This is what I have so far
import java.util.Scanner; //program uses class Scanner
class Cat
{
private String name;
private int age;
private double weight;
private String breed;
private boolean declawed;
public void setName(String name)
{
this.name=name;
}
public void setBreed(String bre)
{
this.breed=bre;
}
public void setAge(int ag)
{
this.age=ag;
}
public void set(boolean decla)
{
this.declawed=decla;
}
public String getName()
{
return this.name;
}
public String getBreed()
{
return this.breed;
}
public boolean getBoolean()
{
return this.declawed;
}
public int getAge()
{
return age;
}
public void set(String nm, int ag, double wei)
{
name=nm;
age=ag;
wei=weight;
}
}
public class catTest
{
public static void main(String[] args)
{
//instantiate cat class
Cat cat1=new Cat();
//Create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
//inputting cat's name
System.out.println("Enter a cats name:");
String name = input.next();
//input cat's age
System.out.println("Enter cats age:");
int age = input.nextInt();
//input weight
System.out.println("Enter cats weight:");
double weight = input.nextDouble();
//input cat's breed
System.out.println("Enter cats breed:");
String breed = input.next();
System.out.println("Is your cat declawed? True or False");
boolean declawed = input.nextBoolean();
//function call to set
cat1.set(name, age, weight);
//set breed
cat1.setBreed(breed);
//displaying
System.out.println("Cat's Name:"+cat1.getName());
System.out.println("Breed:"+cat1.getBreed());
//exit program
System.exit(0);
}//end main
}//end class
Explanation / Answer
// working now ENJOY
import java.util.Scanner; //program uses class Scanner
class Cat
{
private String name;
private int age;
private double weight;
private String breed;
private boolean declawed;
public void setName(String name)
{
this.name=name;
}
public void setBreed(String bre)
{
this.breed=bre;
}
public void setAge(int ag)
{
this.age=ag;
}
public void set(boolean decla)
{
this.declawed=decla;
}
public String getName()
{
return this.name;
}
public String getBreed()
{
return this.breed;
}
public boolean getBoolean()
{
return this.declawed;
}
public int getAge()
{
return age;
}
public void set(String nm, int ag, double wei)
{
name=nm;
age=ag;
wei=weight;
}
}
public class catTest
{
public static void main(String[] args)
{
//instantiate cat class
Cat cat1=new Cat();
//Create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
//inputting cat's name
System.out.println("Enter a cats name:");
String name = input.next();
//input cat's age
System.out.println("Enter cats age:");
int age = input.nextInt();
//input weight
System.out.println("Enter cats weight:");
double weight = input.nextDouble();
//input cat's breed
System.out.println("Enter cats breed:");
String breed = input.next();
System.out.println("Is your cat declawed? True or False");
boolean declawed = input.nextBoolean();
//function call to set
cat1.set(name, age, weight);
//set breed
cat1.setBreed(breed);
cat1.set(declawed);
Cat cat2 = new Cat();
System.out.println("Enter a cats name:");
name = input.next();
System.out.println("Enter cats age:");
age = input.nextInt();
//input weight
System.out.println("Enter cats weight:");
weight = input.nextDouble();
//input cat's breed
System.out.println("Enter cats breed:");
breed = input.next();
System.out.println("Is your cat declawed? True or False");
declawed = input.nextBoolean();
//function call to set
cat2.set(name, age, weight);
//set breed
cat2.setBreed(breed);
cat2.set(declawed);
//displaying
Cat cat3 = new Cat();
System.out.println("Enter a cats name:");
name = input.next();
System.out.println("Enter cats age:");
age = input.nextInt();
//input weight
System.out.println("Enter cats weight:");
weight = input.nextDouble();
//input cat's breed
System.out.println("Enter cats breed:");
breed = input.next();
System.out.println("Is your cat declawed? True or False");
declawed = input.nextBoolean();
//function call to set
cat3.set(name, age, weight);
//set breed
cat3.setBreed(breed);
cat3.set(declawed);
//displaying
System.out.println("The Cats over 3 with claws are:");
if(cat2.getBoolean())
{
if(cat2.getAge()>3)
{
System.out.println( "Name: " + cat2.getName());
System.out.println("Age: " + cat2.getAge() + " Years Old ");
}
}
if(cat1.getBoolean())
{
if(cat1.getAge()>3)
{
System.out.println( "Name: " + cat1.getName());
System.out.println("Age: " + cat1.getAge() + " Years Old ");
}
}
if(cat3.getBoolean())
{
if(cat3.getAge()>3)
{
System.out.println( "Name: " + cat3.getName());
System.out.println("Age: " + cat3.getAge() + " Years Old ");
}
}
System.exit(0);
}//end main
}//end class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.