Summary of Business Process of Automobile Rental Project


- I. Demand Analysis

- two,


- 1. Demand Analysis and Data Table Design

Demand map:

Discovery class:

    01.moto class (automobile parent class):

        01.1: bus (bus)

        01.2: car (car)

        01.3: Truck class (truck class)

    02.mototype class (automobile type class)

    03. User class: User of software system, the person who logs in the system management, such as administrator, business manager, etc.

    04. Customer category: car renters.

    05. Company category: People who handle the business process of car rental and change.

- II. Design outline design

Database design:


- 3. Detailed design

  1. Implementing Information Input of Vehicles


    One problem: Trucks are different from buses and cars, so it is necessary to determine what type of car is in the business layer, but this code is bloated, not conducive to expansion, not object-oriented programming.

    Solution: Using the object-oriented characteristics (inheritance and polymorphism), the method of inputting vehicle information in moto class is established, so that the bus can have its own method of inputting vehicle information by inheriting moto class.


Code demonstration:

Class moto:

public abstract class Moto {
	private String mno;              //License plate number
	private int seatCount;       
	private MotoType mtype;		  	
	

	//The get set method is omitted here
	
	public Moto(MotoType mtype,String mno,int seatCount){
		this.mno = mno;
		this.seatCount = seatCount;
		this.mtype = mtype;
	}
	
	/**
	 * Store the current object in the database
	 * @throws Exception
	 */
	public void saveDB() throws Exception{
		CompanyDao dao = new CompanyDao();
		try {
			dao.addMoto(this);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			dao.closeConnection();
		}
	}
}

car class: You can use the methods in the moto class directly

public class Car extends Moto{
	public Car(MotoType mtype,String mno) {
		super(mtype,mno, 5);
	}
}

truck class: overrides the saveDB() method of the moto class

public class Truck extends Moto{
	private int dun;
	private double priceEachDun;            //Unit price per ton per day	

	public int getDun() {
		return dun;
	}
	public double getPriceEachDun() {
		return priceEachDun;
	}
	public void setPriceEachDun(double priceEachDun) {
		this.priceEachDun = priceEachDun;		
	}
	public Truck(MotoType mtype, String mno, int seatCount,int dun) {
		super(mtype, mno, seatCount);
		this.dun = dun;		
	}
	public double getDayMoney() {
		return priceEachDun*dun;
	}
	
	/**
	 * Store the current object in the database - ----------- rewrite
	 * @throws Exception
	 */
	@Override
	public void saveDB() throws Exception{
		CompanyDao dao = new CompanyDao();
		try {
			dao.beginTransaction();
			dao.addMoto(this);
			TruckEntity truckEntity = new TruckEntity();
			truckEntity.setMno(this.getMno());
			truckEntity.setDun(dun);
			truckEntity.setPriceEachDun(priceEachDun);
			dao.addTruck(truckEntity);
			dao.commit();
		} catch (Exception e) {
			e.printStackTrace();
			dao.rollback();
			throw e;
		}finally{
			dao.closeConnection();
		}
	}
}

At the business logic level, the approach is simple:

private List<Moto> motos;
/**
* Add car
* @param moto
* @throws Exception
*/
public void addMoto(Moto moto) throws Exception{
	if(moto != null ){			
		moto.saveDB();                      //OO polymorphism
		motos.add(moto);
	}else{
		throw new Exception("Participation moto error");
	}		
}


2. Implementing Car Rental Business

Illustration:

    Note: Since the whole rental process involves multiple table modifications, such as adding two orders to operate the same car at about the same time, there must be a problem with one order, which requires the consistency and integrity of the transaction.


Code at the business logic level can:

public class RentCompany {
	
	private String name;	
	private List<Moto> motos;               //Cars to be leased
	
	public String getName() {
		return name;
	}	

	public List<Moto> getMotos() {
		return motos;
	}

	public RentCompany(String name){
		
		this.name = name;
		motos = new ArrayList<Moto>(50);
		
	}	
	
	/**
	 * Car Rental
	 * @param motos
	 * @param client
	 * @param rentinfo
	 * @return            The lease is successful and the order number is returned.
	 * @throws Exception
	 */
	public String rent(List<Moto> motos,TClient client,TRentInfo rentinfo) throws Exception{
		String rentno = null;
		
		if(motos != null && client != null && rentinfo!= null){
			CompanyDao dao = new CompanyDao();
			try {
				dao.beginTransaction();                                 //Open transaction
				//Adding customer data		
				dao.addTClient(client);
				//Adding car rental information
				rentno = dao.addRentInfo(rentinfo);
				//Add Lease Details
				for(Moto moto : motos){
					TRentDetail rentDetail = getTRentDetail(rentno,moto);
	                dao.addRentDetail(rentDetail);
				}			
				dao.commit();                                         //Submission of affairs	
			} catch (Exception e) {
				dao.rollback();                                       //Rollback transaction
				rentno = null;
				throw e;
			}finally{
				dao.closeConnection();
			}		
		}else{			
			throw new Exception("Entry error, please check");
		}		
		
		return rentno;
	}
	
	private TRentDetail getTRentDetail(String rentno,Moto moto){
		TRentDetail detail = new TRentDetail();
		
		detail.setMno(moto.getMno());
		detail.setRentno(rentno);
		detail.setDaymoney(moto.getDayMoney());
		
		return detail;
	}	
}

3. Achieving Car Return Business




Keywords: Database Programming

Added by Walle on Thu, 23 May 2019 01:48:20 +0300