EAGLE, Idaho — A former Eagle High School teacher and basketball coach accused of child sex charges appeared in court for the first time on Thursday.

The Ada County Sheriff's Office claims 32-year-old Jeff Ranstrom had a lengthy sexual relationship with a 17-year-old girl. In court, Ranstrom’s defense attorney said his client admitted to the whole thing.

Ranstrom reportedly told his lawyer, Gabriel McCarthy, that he had committed a crime. From there McCarthy contacted the Ada County Prosecutors Office, who put him in touch with investigators at the sheriff’s office.

The defendant is facing five felony counts including rape, sexual battery of a child, sexual exploitation of a child, and burglary.

In court, lawyers said the charges stem from a relationship he had with a former student. Ranstrom is accused of targeting the girl from the time she was a freshman, a characterization the defense disputed.

RELATED: Former Eagle basketball coach charged with rape, sexual battery of a child

They allegedly had sex more than 100 times in several different locations.

“He would have her meet him places, for example he had a lawn care company so he would have her meet him in the trailer, where the sexual activity would happen,” Ada County Prosecutor John Dinger said. 

“They did this at a storage shed," Dinger continued. "He abused her at her parents homes without her knowledge, at his own home, at his own parents home and more than once he went into the home of the victim while her parents were asleep and engaged her sexually and he also kissed and fondled her at his employment at Eagle High School in his classroom.”

Several former students were in the courtroom to hear the charges against Ranstrom. One of them told KTVB he was shocked at the details of the purported crimes.

RELATED: Former Fruitland High assistant track coach charged with rape

"It just shows you that the world we live in today is really unpredictable," said Braeden Stevens, a former student who had Ranstrom as a teacher his junior year. "It was said she was a family friend, so you never know. You just never know, could be your next-door neighbor, you just never know."

Ranstrom's defense attorney said his client wouldn't have been charged with anything if he hadn't come forward. 

“This case began with him voluntarily confessing and handing the state a slam dunk prosecution on a silver platter,” McCarthy said.

RELATED: Idaho IceWorld coach arrested on child pornography charges

According to McCarthy, Ranstrom spoke with investigators for more than an hour, describing the crimes he had committed.

“I think Jeff deserves some credit for coming forward, he is going to suffer a consequence,” he said. “His eyes are wide open, and I've informed him exactly what the price of tea is for committing this crime in Ada County and its steep.”

The prosecution argued bail should be set at $500,000, while the defense said bail should be lenient because Ranstrom confessed. Ultimately the judge in the case set bail at $500,000. 

Ranstrom is due back in court for a preliminary hearing on the morning of October 17.

The former Eagle High teacher and boy's head basketball coach resigned from his position on Sept. 23. He taught at the school for six years.

RELATED: 'Offenders don’t just groom children': Boise victims' advocate says sex offenders also target families