This paper investigates the preventive replacement policies for an operating system that works for projects at random times. The system is subject to shocks which arrive according to a non-homogeneous Poisson process. When a shock takes place, the system is either replaced by a new one (type 2 failure) or minimally repaired (type 1 failure). The decision to repair or replace the system depends on the number of shocks that have occurred since the last replacement. In this paper, we propose the following two preventive replacement models: (1) the system is preventively replaced before a type 2 failure at age T or at the completion of the Nth working projects or at the kth type 1 failure, whichever occurs last; (2) the system is preventively replaced before a type 2 failure at age T or at the completion of the Nth working projects or at the kth type 1 failure, whichever occurs first. For each model, the optimum preventive replacement schedule that minimizes the long term expected cost per unit time is theoretically presented. Finally, we offer a computational algorithm for determining the optimum replacement policies, and we give a numerical example to illustrate our proposed models. This study provides a general framework such that many existing models are the special cases of the proposed models.