lonlonmalon
Jun 3rd, 2007, 09:32 AM
Alright, so I am making a program with two parts - the client program GetDogs, and the fun and original one it calls upon, Dog. Basically, GetDogs will create new members of the Dog class and will give it random variables if they are not previously supplied.
Unfortunately, I cannot compile GetDogs.
Here is the code for GetDogs:
import java.io.*;
public class GetDogs {
public static void main(String[] args) {
String newAge;
int age;
BufferedReader myInput = new BufferedReader (new InputStreamReader(System.in));
System.out.print("What age would you like Rover the Spaniel to be? ");
newAge = myInput.readLine();
age = Integer.parseInt(newAge);
Dog dog1 = new Dog("Rover", "Spaniel", "Black", "Mediocre", "Emily P.", 3, 4, 9, age);
Dog dog2 = new Dog("Spot", "Border Collie", "Brown", "Great", "Mr. Cop");
System.out.println("How about some doggie details?");
System.out.println(dog1);
System.out.println(dog2);
}
}
And the code for Dog:
public class Dog {
//variables for characteristics
String dogName;
String dogBreed;
String dogColour;
String ownerName;
String health;
int aggression;
int age;
int hunger;
//constructor
public Dog(String dogName, String dogBreed, String dogColour, String health, String ownerName, int aggression, int hunger, int age){
//assign characteristics from parameters
this.dogName = dogName;
this.dogBreed = dogBreed;
this.aggression = aggression;
this.hunger = hunger;
this.age = age;
this.dogColour = dogColour;
this.health = health;
this.ownerName = ownerName;
}
//alternate constructor
public Dog(String dogName, String dogBreed, int age){
//set characteristics from parameters
String newAge;
this.dogName = dogName;
this.dogBreed = dogBreed;
this.dogColour = dogColour;
this.health = health;
this.ownerName = ownerName;
//set other characteristics randomly
this.aggression = (int)(Math.random()*10) + 1;
this.hunger = (int)(Math.random()*10) + 1;
this.age = (int) (Math.random() * 13) + 1;
}
//methods to access characteristics
public void setAggression(int factor){
this.aggression = factor;
}
public void setHunger(int factor){
this.hunger = factor;
}
public String setDogColour() {
return this.dogColour;
}
public String setOwnerName() {
return this.ownerName;
}
public String getHealth() {
return this.health;
}
public String getBreed(){
return this.dogBreed;
}
public String getName(){
return this.dogName;
}
public int getAggression(){
return this.aggression;
}
public int getHunger(){
return this.hunger;
}
public int getAge() {
return this.age;
}
//methods for behaviour or interactions
public void barkFriendly(){
System.out.println("Arf! Arf!");
}
public void barkAngry(){
System.out.println("GRR! RRRFFF!");
}
//method to display info
public String toString(){
String dogData1 = "Name: " + this.dogName + " Breed: " + this.dogBreed + "\n";
String dogData2 = "Aggression factor: " + this.aggression + "\n";
String dogData3 = "Hunger factor: " + this.hunger + "\n";
String dogData4 = "Age: " + this.age + "\n";
String dogData = dogData1 + dogData2 + dogData3 + dogData4;
return dogData;
}
}
When I attempt to compile the GetDogs file, I get these two errors:
cannot find symbol constructor Dog(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,int,int ,int)
and
cannot find symbol constructor Dog(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
both of which occur where I declare dog1 and dog2. The Dog class-ish-area compiles without errors.
Any help you can offer will be greatly appreciated!
Unfortunately, I cannot compile GetDogs.
Here is the code for GetDogs:
import java.io.*;
public class GetDogs {
public static void main(String[] args) {
String newAge;
int age;
BufferedReader myInput = new BufferedReader (new InputStreamReader(System.in));
System.out.print("What age would you like Rover the Spaniel to be? ");
newAge = myInput.readLine();
age = Integer.parseInt(newAge);
Dog dog1 = new Dog("Rover", "Spaniel", "Black", "Mediocre", "Emily P.", 3, 4, 9, age);
Dog dog2 = new Dog("Spot", "Border Collie", "Brown", "Great", "Mr. Cop");
System.out.println("How about some doggie details?");
System.out.println(dog1);
System.out.println(dog2);
}
}
And the code for Dog:
public class Dog {
//variables for characteristics
String dogName;
String dogBreed;
String dogColour;
String ownerName;
String health;
int aggression;
int age;
int hunger;
//constructor
public Dog(String dogName, String dogBreed, String dogColour, String health, String ownerName, int aggression, int hunger, int age){
//assign characteristics from parameters
this.dogName = dogName;
this.dogBreed = dogBreed;
this.aggression = aggression;
this.hunger = hunger;
this.age = age;
this.dogColour = dogColour;
this.health = health;
this.ownerName = ownerName;
}
//alternate constructor
public Dog(String dogName, String dogBreed, int age){
//set characteristics from parameters
String newAge;
this.dogName = dogName;
this.dogBreed = dogBreed;
this.dogColour = dogColour;
this.health = health;
this.ownerName = ownerName;
//set other characteristics randomly
this.aggression = (int)(Math.random()*10) + 1;
this.hunger = (int)(Math.random()*10) + 1;
this.age = (int) (Math.random() * 13) + 1;
}
//methods to access characteristics
public void setAggression(int factor){
this.aggression = factor;
}
public void setHunger(int factor){
this.hunger = factor;
}
public String setDogColour() {
return this.dogColour;
}
public String setOwnerName() {
return this.ownerName;
}
public String getHealth() {
return this.health;
}
public String getBreed(){
return this.dogBreed;
}
public String getName(){
return this.dogName;
}
public int getAggression(){
return this.aggression;
}
public int getHunger(){
return this.hunger;
}
public int getAge() {
return this.age;
}
//methods for behaviour or interactions
public void barkFriendly(){
System.out.println("Arf! Arf!");
}
public void barkAngry(){
System.out.println("GRR! RRRFFF!");
}
//method to display info
public String toString(){
String dogData1 = "Name: " + this.dogName + " Breed: " + this.dogBreed + "\n";
String dogData2 = "Aggression factor: " + this.aggression + "\n";
String dogData3 = "Hunger factor: " + this.hunger + "\n";
String dogData4 = "Age: " + this.age + "\n";
String dogData = dogData1 + dogData2 + dogData3 + dogData4;
return dogData;
}
}
When I attempt to compile the GetDogs file, I get these two errors:
cannot find symbol constructor Dog(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,int,int ,int)
and
cannot find symbol constructor Dog(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
both of which occur where I declare dog1 and dog2. The Dog class-ish-area compiles without errors.
Any help you can offer will be greatly appreciated!