package com.anna.participant.service;

import com.anna.participant.dao.ParticipantDAO;
import com.anna.participant.util.InvalidInputException;
import com.anna.participate.bean.ParticipantBean;

public class Administrator {
	public static void main(String[] args){
		ParticipantBean bean=new ParticipantBean();
		bean.setName("ABC");
		bean.setPracticalMark1(40);
		bean.setPracticalMark2(40);
		bean.setTheoryMark1(30);
		bean.setTheoryMark2(30);
		bean.setSportsQuota("Yes");
		Administrator admin= new Administrator();
		System.out.println(admin.addParticipant(bean));
	}
	String addParticipant(ParticipantBean bean){
		if(bean.getName().equals("")||bean.getName().length() < 2||(bean.getSportsQuota() != "Yes" &&bean.getSportsQuota() != "No")){
			return (new InvalidInputException().toString());
		}
		if((bean.getTheoryMark1() < 0 && bean.getTheoryMark1() > 40)||(bean.getTheoryMark2() < 0 && bean.getTheoryMark2() > 40)){
			return "THEORY MARK IS INVALID";
		}
		if((bean.getPracticalMark1() < 0 && bean.getPracticalMark1() > 40)||(bean.getPracticalMark2() < 0 && bean.getPracticalMark2() > 40))
			return "PRACTICAL MARK IS INVALID";
		bean.setId(( new ParticipantDAO().generateId(bean.getName())));
		bean.computeTotal();
		bean.computeResult();
		String res = new ParticipantDAO().createParticipant(bean);
		
		if(res.equals("TRUE"))
			return bean.getId()+":"+bean.getResult();
		else
			return "ERROR";
		
	}
}
package com.anna.participant.service;

import com.anna.participant.dao.ParticipantDAO;
import com.anna.participant.util.InvalidInputException;
import com.anna.participate.bean.ParticipantBean;

public class Administrator {
	public static void main(String[] args){
		ParticipantBean bean=new ParticipantBean();
		bean.setName("ABC");
		bean.setPracticalMark1(40);
		bean.setPracticalMark2(40);
		bean.setTheoryMark1(30);
		bean.setTheoryMark2(30);
		bean.setSportsQuota("Yes");
		Administrator admin= new Administrator();
		System.out.println(admin.addParticipant(bean));
	}
	String addParticipant(ParticipantBean bean){
		if(bean.getName().equals("")||bean.getName().length() < 2||(bean.getSportsQuota() != "Yes" &&bean.getSportsQuota() != "No")){
			return (new InvalidInputException().toString());
		}
		if((bean.getTheoryMark1() < 0 && bean.getTheoryMark1() > 40)||(bean.getTheoryMark2() < 0 && bean.getTheoryMark2() > 40)){
			return "THEORY MARK IS INVALID";
		}
		if((bean.getPracticalMark1() < 0 && bean.getPracticalMark1() > 40)||(bean.getPracticalMark2() < 0 && bean.getPracticalMark2() > 40))
			return "PRACTICAL MARK IS INVALID";
		bean.setId(( new ParticipantDAO().generateId(bean.getName())));
		bean.computeTotal();
		bean.computeResult();
		String res = new ParticipantDAO().createParticipant(bean);
		
		if(res.equals("TRUE"))
			return bean.getId()+":"+bean.getResult();
		else
			return "ERROR";
		
	}
}

