We have developed a unique Fokker--Planck code to study the physics of plasmas that are trapped in magnetic and potential wells of general shape on a collisional time scale. The code was designed primarily to apply to mirror machines, either a simple mirror or a tandem mirror. A plasma confined in a mirror machine generally consists of various groups of particles trapped magnetically and/or electrostatically depending on their energy, magnetic moment, and axial position. Characteristic features of such a plasma are: first, that the bounce times of trapped particles are much shorter than the collision times; and second, that particles trapped in different axial locations can have the same energy and magnetic moment. The former feature allows us to perform bounce-orbit averaging of the kinetic equation, and the latter feature indicates that the distribution function can be multivalued. The code solves a relativistic Fokker--Planck equation averaged over bounce orbits for all the trapped-particle groups. In addition to the Coulomb collision operator, the code includes a synchrotron radiation term, a quasilinear rf diffusion operator, and source and loss terms. The numerical method consists of a mapping technique and a Galerkin finite-element method. Example results using the code for electron-cyclotron resonant heatingmore » and neutral beam injection in a tandem mirror are also presented.« less