Newer
Older
moobreeder / Cow.java
/**
 * Moobreeder is a simple cow breeding game to illustrate the principles of
 * selective breeding to KS3 pupils.
 *
 * (c) Daniel Vedder 2018,
 * Amano Christian School
 */

/*
 * 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;

	public Cow(String desiredSex)
	{
		//Default cow/bull
		sex = desiredSex;
		id = idCounter;
		idCounter++;
		name = makeName(sex, id);
		generation = 0;
		milk = 1;
		strength = 5;
		meat = 1;
		aggression = 10;
	}

	public Cow(Cow father, Cow mother)
	{
		//Constructor used for reproduction
		//TODO
	}

	public String rateCow(Cow c, String use)
	{
		int rating = 0;
		if (use == "dairy") {
			rating = rateDairyCow(c);
		}
		else if (use == "plowing") {
			rating = ratePlowCow(c);
		}
		else if (use == "meat") {
			rating = rateMeatCow(c);
		}
		else {
			//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)
	{
		if (rating < 1) return "useless";
		else if (rating < 3) return "terrible";
		else if (rating < 6) return "pretty bad";
		else if (rating < 9) return "moderate";
		else if (rating < 12) return "passable";
		else if (rating < 15) return "fairly good";
		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);
	}
	
}