We describe in detail how the different components of a multiphase transport (AMPT) model that uses the heavy ion jet interaction generator (HIJING) for generating the initial conditions, Zhang's parton cascade (ZPC) for modeling partonic scatterings, the Lund string fragmentation model or a quark coalescence model for hadronization, and a relativistic transport (ART) model for treating hadronic scatterings are improved and combined to give a coherent description of the dynamics of relativistic heavy ion collisions. We also explain the way parameters in the model are determined and discuss the sensitivity of predicted results to physical input in the model. Comparisons of these results to experimental data, mainly from heavy ion collisions at the BNL Relativistic Heavy Ion Collider, are then made in order to extract information on the properties of the hot dense matter formed in these collisions.