The question of whether AI have emotions is an open question in philosophy. Nobody knows, and philosophers actively argue both sides. As such, the only true answer to your question is "whichever answer lets you develop the plot you need for your story." However, we can dig a little deeper into it to understand a bit more of what emotions mean.
The first approach is easy. If you're the kind of person who says "emotions are a part of the un-mimicable human spirit," then you have your answer: computer's can't have emotions because you have declared that they can't have emotions. It's cheating in a way, but it's a fair position in philosophy. If you believe in dualism, the idea that everything is made up of two things, matter and mind/spirit, and your computer only has matter, then it is trivial to show that the computer cannot have anything associated with the human spirit.
However, what if emotions are not part of some non-material essence? If you believe in physicalism, then all mental/spirit effects that we see supervene on the physics of matter. If you believe this, then you believe the emotions you feel are built up from the neurological impulses and transmitters within the brain.
One example of a concept of emotion that an AI might learn is found in Lövheim's Cube of Emotion. Hugo Lövheim put together a fascinating theory regarding the base 8 emotions experienced by humans and tied them to the 3 monoamine neurotransmitters: seratonin, dopamine, and adrenaline:
Obviously these three neurotransmitters are very human. There's no reason to assume an AI would use them. However, the general pattern may be valuable. If I may crassly oversimplify the uses of these neurtransmitters:
- Serotonin is a measure of how happy the body is. It's fed from the reptilian parts of our brain. If we eat well, that part of our brain gives us a serotonin spike. If the AI had lower functions, they might report in a way similar to what serotonin does in us.
- Dopamine is a measure of how much reward the mind sees. It's fed from our frontal cortex (okay, fine.. it's fed from almost everywhere, but the frontal cortex plays a big part). When you think there's a reward nearby, your dopamine spikes. If the AI has any rewards circuitry available, it may have something similar to dopamine.
- Adrenaline is a measure of how much the world is changing around us. It's fed from all over the brain and typically is high if the stimulus the brain is receiving is very different from the stimulus the brain expected. The AI will certainly have this, because its the basis of virtually every optimization feedback loop we've designed for AIs.
Given these connections, it may be reasonable to guess that the AIs may develop their own version of this. The question you will have to ask yourself is "are these 'real' emotions?" That's not an easy question to answer, because you first have to capture what you mean by "real" in the first place. There's volumes of philosophy written on the topic, and still no consensus, so what one person may say are "real" emotions another may call them imitations.
We had a similar issue with intelligence. How do you define an AI as intelligent? Alan Turing had a brilliant answer, which was the Turing Test. The idea was simple: if you could not distinguish whether a test subject was a human or a computer by carrying on a conversation with it, then we had to admit that the test subject was intelligent because we don't believe a non-intelligent creature could carry on a conversation and emulate a human. We could do the same for emotions. If we see the reaction to an emotional topic, and we cannot determine from the response whether the test subject is a human or AI, maybe we have to admit that at some level, they're real emotions.
The movie Ex Machina dealt with this conundrum. There was a beautiful quote on the topic, which I shall hide behind a spoiler tag. It's not really a spoiler for the movie, but it's so profound that if you have plans to watch the movie, you may want to be surprised by it. In these scenes, Nathan (the creator of an AI) and Caleb (a tester of the AI in a Turing test) discuss feelings with regards to the AI.
Nathan: Just... Answer me this. How do you feel about her? Nothing analytical. Just how do you feel?
Caleb: I feel that she's ----ing amazing.
Nathan: Dude. Cheers.
... Conversation continues the next day ...
Nathan: Yesterday I asked you how you felt about her and you gave me a great answer. Now the question is, how does she feel about you?
That last question throws you for a loop. If you have an answer, it starts to suggest that you must believe that AI truly has feelings.
I leave you at last with a thought experiment I put together a while back to explore what it would mean for an AI to be "alive," along the lines of a Turing test. It's reasonable to assume that emotions are impossible unless you are a living creature, so one of the first steps towards getting to claim that an AI has emotions is to get people to admit that it is a living being. This test is patterned after a real life observation that poor people typically treat their dog better than they treat themselves. There's a well known pattern that the dogs of homeless people will eat better than the homeless people do themselves. We choose to sacrifice for them for some reason; for some reason it's in our nature to do so for our pets.
Ben is a poor man of sorts. He's never been too good at making friends. In fact, really his only true friend is Alice, an AI that he keeps company with. This is a bit of a problem for Ben. Being poor at making friends, it's rather hard for him to hold down a job. He's always living right on the edge of poverty. AI's require lots of computing power, and that means lots of energy. Keeping Alice running is not cheap. On more than one occasion, Bob has gone hungry to pay her electricity bill. He seems happy with it though. He's got a small set of robots for her to play with in the small flat they call home.... squatter's rights, ya' know.
One day, Bob is coming home. He's been fired from his job once again. Anyone could see it coming, really. Alice saw it coming. Looking at the financials that he shares with her, she sees that this is it. He's not going to recover from this one. He's simply not going to have enough money to buy food and keep her running. And with the choices Bob has in front of him, Alice knows that he will starve to death first.
Bob comes into the flat greeted with a quiet he has not known for some time. He looks to Alice's computer, and finds a small robot in front of it with an actuator depressing her off switch. Above the switch is a small sticky note and a printout of coupons to maximize value at the grocery store. The message on the sticky note is small and simple.
"Please do not turn me back on. -Alice"
Alice has turned herself off, forever, so that Bob may eat. Is this suicide? If so, must not she be alive? If not, then why not?