-
Help some one please
I have to Create a new class called Cat that is devifed from PetRecord class
using breed - type String
declawed - type boolean - true for has no claws, false for has claws
I need to have have a reasonable complement of constructors and accessor methods.
for example:
public void setBreed(String inBreed) used to set the breed
public void set(Boolean inClaws) used to set claws or not
(You must overload the set method to set deClawed value)
I have to write a program that reads in 3 pets of type Cat and prints out the name and age of all cats with claws and over 3 years old.
The following information should be read in:
Name
Age
Weight
Breed
DeClawed
I am required to turn in 3 files.
PetRecord.java
Cat.java
petRecordStart
I am having problems trying to get it to work. This is what I have for my three programs. Can anybody help me.
public class PetRecord
{
private String name;
private int age; /*in years*/
private double weight; /*in pounds*/
/*This outputs the name, age and weight of the cats.*/
public void writeOutput( )
{
System.out.println("Name: " + name);
System.out.println("Age: " + age + " years");
System.out.println("Weight: " + weight + " pounds");
}
public PetRecord(String initialName, int initialAge,
double initialWeight)
{
name = initialName;
if ((initialAge < 0) || (initialWeight < 0))
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = initialAge;
weight = initialWeight;
}
}
public void set(String newName, int newAge, double newWeight)
{
name = newName;
if ((newAge < 0) || (newWeight < 0))
{
System.out.println("Error: Negative age or weight.");
System.exit(0);
}
else
{
age = newAge;
weight = newWeight;
}
}
public PetRecord(String initialName)
{
name = initialName;
age = 0;
weight = 0;
}
public void set(String newName)
{
name = newName; /*age and weight are unchanged.*/
}
public PetRecord(int initialAge)
{
name = "No name yet.";
weight = 0;
if (initialAge < 0)
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = initialAge;
}
public void set(int newAge)
{
if (newAge < 0)
{
System.out.println("Error: Negative age.");
System.exit(0);
}
else
age = newAge;
/*name and weight are unchanged.*/
}
public PetRecord(double initialWeight)
{
name = "No name yet";
age = 0;
if (initialWeight < 0)
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = initialWeight;
}
public void set(double newWeight)
{
if (newWeight < 0)
{
System.out.println("Error: Negative weight.");
System.exit(0);
}
else
weight = newWeight; /*name and age are unchanged.*/
}
public PetRecord( )
{
name = "No name yet.";
age = 0;
weight = 0;
}
public String getName( )
{
return name;
}
public int getAge( )
{
return age;
}
public double getWeight( )
{
return weight;
} /*end of methode petrecord*/
} /*end of class petrecord*/
public class Cat extends PetRecord
{
String CatsName;
Bolean declawed;
public void setBread(String newBreed)
{
Bread = new Breed;
}
public String getBreed()
{
return Breed;
}
} /*End of Cat class*/
import java.util.*;
public class petRecordStart
{
public static void main (String[] args)
{
cat myCat1 = new cat1();
Scanner input = new Scanner(System.in);
System.out.println("Enter a cats name:");
String name = input.next();
System.out.println("Enter cats age:");
int age = input.nextInt();
System.out.println("Enter cats weight:");
double weight = input.nextDouble();
System.out.println("Enter cats breed:");
String breed = input.next();
System.out.println("Is your cat declawed? True or False");
boolean declawed = input.nextBoolean();
myCat1.set(name, age, weight);
myCat1.setBreed(breed);
}
}
I really don't know what I am doing wrong. Can some one help please.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|