Originally Posted by
aussiemcgr
Ok, let's not deal with an abstract Animal class right now. We will do that in Part 2.
cool.
* int pigCount
* int cowCount
* int sheepCount
- promptUser()
- createAnimal(String type)
This seem's alright, though I'm not too sure how they will be set up, how the count's will be tracked. I'm guessing that pigCount will = 0 and be incremented by every creation of Pig.
So we'll put the exit option into version 2 as well? cool cool....
I'm thinking about the createAnimal and promptUser at the moment. So the prompt user would ask what type of animal they wanted to create...... Would this then lead to an if elseif statement? Or a switch?
I'm not sure if this is the kind of thing
If(userInput == CowAnimal){
cowCount++;
CowClass cow[cowCount] = new CowClass;
}
Still confuses me how everything will link in, but I think that'll click when I see it...
Pig Class -- This would have a constructor which accepts a String, to set the sound variable
* String sound
- getSound()
ok, so the constructor for the pig can contain the sound because that's not going to change like the count. so It's be pigClass(String "oink") ?
I'm really unsure how the scanner should be integrated into all of this - though the only place I can see it being is in the Farm Class.
public void promptUser(){
System.out.println("Which farm animal would you like to create?");
Scanner scan = new Scanner(System.in);
String animalType = scan.nextLine();
if (animalType == PigClass){
PigCount++
}elseif (animalType.ignoreCase == CowClass.ignoreCase
}
Not sure if that's how they would integrate... think I might have used method's that don't exist there as well (though there's a similar thing)
Sound's good though, cheers
--- Update ---
Just had a bash at making the FarmClass -
import java.util.Scanner;
public class FarmClass {
int pigCount;
int cowCount;
int sheepCount;
public void promptUser() {
System.out.println("what kind of animal would you like to create?");
}
public String createAnimal(String animal) {
Scanner scan = new Scanner(System.in);
animal = scan.nextLine();
return animal;
}
}
What's still throwing me is how to link these together.... The createAnimal class - I'm assuming that it should be taking input from the user and incrementing the pigCount... I've tried using a Scanner for this but I'm not sure that it's the right way, or whether a scanner should be inside a method like that.