Campbell Ritchie wrote:If you want to assign a value at ransom
Campbell Ritchie wrote:You probably don't need an else because you already have the value 0 set.
Serenity Quinn wrote:I'm really not sure where to start, though I thought arrays may be a good place. Does anyone have resources or ideas about how I could go about this project?
Could I please receive some guidance on what I could use/ resources I could read to:
A). Contain all the males, females, and offspring genotypes so I can print them and get an easy to read list?
B). Take a genotype randomly between the males and females to get a genotype for the offspring?
Hahahahahahahahahahahaha!Mike Simmons wrote:. . . we normally do not condone holding values for ransom . . .
Yes; I was mistaken there.I think she does, given the way the code is currently structured. . . .
I prefer that way to write that method, even though beginners are often scared of the ?: operator.This same method could also be written:
java 17
Grzegorz Wilanowski wrote:I'd create a separate class for Being with allele represented by booleans (why waste int for 0/1 values?).
Why? Memory is cheap; you won't get anywhere near the available heap size for 1,000 objects. Or maybe 100,000,000. You will probably run short before you reach 1,000,000,000 objects, however.Grzegorz Wilanowski wrote:. . . allele represented by booleans
It's not a waste; it will allow you to introduce a third allele for each gene. You will have to refactor all your code if you only permit two possibilities. Of course, an allele isn't a number. Something is only a number if you can do arithmetic with it. So I think none of the primitive datatypes is suitable for that field. Least of all boolean, so I am disagreeing with Mike.(why waste int for 0/1 values?). . . .
Then I pushed submit instead of preview by mistake. So there is more to write.A few minutes ago, I wrote:. . . enum class type (also called enumerated type).
Well, allowing for the known imprecisions of the double datatype, those figures below do add up to 1.0.A few minutes ago, I wrote:. . . the frequencies need to add up to 1. . . .
That looks like what I was thinking of.To get ≥ write ≥ The bits about \u201c/d are posh quotes: “”.Junilu Lacar wrote:. . . I'd probably do something like: . . .
In which case it would be best to change the name of the field in that post to frequency.This morning, I wrote:. . . the frequencies need to add up to 1. . . .
Campbell Ritchie wrote:I regard your method to convert booleans to numbers as awkward.
Also the method to choose an allele takes Math.random() twice, and I think that means you get the alleles with 50% frequency each.
If you go beyond two elements, however, it becomes awkward to choose an allele.
You might implement that by iterating the array of choices and adding the frequencies of the alleles until you reach the probability value passed.
It also means the enum needs a frequency field and all the frequencies need to add up to 1.
It would be one way to implement choice if, as usually happens in real life, you get a gene with more than two alleles. Blood group is an example: you have the alleles A and B, as well as an allele not doing anything, which corresponds to group O.Junilu Lacar wrote:. . . I don't think that's necessary . . .
No; if you get something happening half the time it has a frequency of 0.5. The frequency of the blood group allele O is about √0.4, which is something like 0.63.Aren't frequencies cardinal numbers that denote quantities, not fractions?
Campbell Ritchie wrote:No; if you get something happening half the time it has a frequency of 0.5.
Mike Simmons wrote:[Posted in response to Campbell's last post, before seeing Junilu's ABO enum above.]
If you're talking about a double between 0 and 1 that represents the chance that a given element would be 1 rather than 0, I think I would skip the ambiguity of "frequency" and instead call it "probability".
My getting it wrong first ime doubtless didn't helpJunilu Lacar wrote:. . . The "frequency" name is definitely throwing me for a loop. . . .
Junilu Lacar wrote:On a side note, I've never seen that kind of annotation in a quote before. Very Chat GPT-esque, to be honest. Kudos to whoever added that feature!
Mike Simmons wrote:My wife will find it very amusing that I have been likened to a program for simulating human conversation.
A and B are the other alleles, which are codominant. They can both be expressed, in which case you get the type AB.Junilu Lacar wrote:. . . with blood types, type O is the most common even though it's made of recessive alleles. . . .
Mike Simmons wrote:using an int probably won't be wasting any more space than a boolean - Java usually implements booleans with a full 32-bit or 64-bit word (usually the latter, nowadays).)
java 17
The Java® Language Specification says an int occupies 32 bits and doesn't specify a size for a boolean. Maybe the serialised version occupies different memory from that.Grzegorz Wilanowski wrote:. . . int variable occupies 8 bytes in file and boolean occupies 5 bytes in file. . . .
My wife would find it even funnier if somebody said that about me.Mike Simmons wrote:. . . I have been likened to a program for simulating human conversation.
Campbell Ritchie wrote:The Java® Language Specification says an int occupies 32 bits and doesn't specify a size for a boolean. Maybe the serialised version occupies different memory from that.
Junilu Lacar wrote:If you're representing alleles as 0 and 1 and assuming 1 is the dominant allele and 0 is the recessive allele, then you'd have 11, 10, 10, 00 as your possible genotypes.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |