| |
---|
| | /* |
---|
| | * This file holds the cow class and associated methods. |
---|
| | */ |
---|
| | |
---|
| | //import java.Exception.*; |
---|
| | |
---|
| | public class Cow |
---|
| | { |
---|
| | private static int idCounter = 1; |
---|
| | |
---|
| | private int id; |
---|
| | private int generation; |
---|
| | private String name; |
---|
| | private String sex; |
---|
| | private int milk, strength, meat, aggression; |
---|
| | |
---|
| |
---|
| | sex = desiredSex; |
---|
| | id = idCounter; |
---|
| | idCounter++; |
---|
| | name = makeName(sex, id); |
---|
| | generation = 0; |
---|
| | milk = 1; |
---|
| | strength = 5; |
---|
| | meat = 1; |
---|
| | aggression = 10; |
---|
| |
---|
| | else if (use == "meat") { |
---|
| | rating = rateMeatCow(c); |
---|
| | } |
---|
| | else { |
---|
| | //error |
---|
| | //throw Exception("No such use: "+use); |
---|
| | } |
---|
| | return "This is a "+rating2string(rating)+" cow for "+use+"."; |
---|
| | } |
---|
| | |
---|
| | private int rateDairyCow(Cow c) |
---|
| | { |
---|
| | //TODO |
---|
| | return 0; |
---|
| | } |
---|
| | |
---|
| | private int rateMeatCow(Cow c) |
---|
| | { |
---|
| | //TODO |
---|
| | return 0; |
---|
| | } |
---|
| | |
---|
| | private int ratePlowCow(Cow c) |
---|
| | { |
---|
| | //TODO |
---|
| | return 0; |
---|
| | } |
---|
| | |
---|
| | /* |
---|
| | * Return a string rating for values between 0 and 20. |
---|
| | */ |
---|
| | private String rating2String(int rating) |
---|
| | private String rating2string(int rating) |
---|
| | { |
---|
| | if (rating < 1) return "useless"; |
---|
| | else if (rating < 3) return "terrible"; |
---|
| | else if (rating < 6) return "pretty bad"; |
---|
| |
---|
| | else if (rating < 18) return "pretty good"; |
---|
| | else if (rating < 20) return "very good"; |
---|
| | else return "brilliant"; |
---|
| | } |
---|
| | |
---|
| | private String makeName(String sex, int id) |
---|
| | { |
---|
| | if (sex == "male") return "Bull #"+id; |
---|
| | else if (sex == "female") return "Cow #"+id; |
---|
| | else return "ERROR No such sex: "+sex; |
---|
| | //else throw Exception("No such sex: "+sex); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |