Untitled

 avatar
unknown
plain_text
2 years ago
11 kB
9
Indexable
/**
 * The Criminal class represents a criminal with a certain severity of crime and a type of crime.
 * @author Pareekshith, Anto, Shreyas, Rishabh
 *
 */
public class Criminal {
	/**
     * The name of the Criminal.
     */
    private String name;
    /**
     * Severity of the crime committed (1-10)
     */
    private int severity;
    /**
     * Type of crime ("violent", "non-violent")
     */
    private String crimeType;

    /**
     * Constructs a new Criminal object with the specified name, severity of crime, and type of crime.
     * @param name, the name of the criminal
     * @param severity, the severity of the criminal's crime (1-10)
     * @param crimeType, the type of the criminal's crime (e.g. "violent", "non-violent")
     */
    public Criminal(String name, int severity, String crimeType) {
      this.name=name;
      this.severity=severity;
      this.crimeType=crimeType;
    }

    /**
     * Returns the severity of the criminal's crime.
     * @return the severity of the criminal's crime
     */
    public int getSeverity() {
        return this.severity;
    }

    /**
     * Returns the type of the criminal's crime.
     * @return the type of the criminal's crime
     */
    public String getCrimeType() {
        return this.crimeType;
    }
    public String getName() {
    	return this.name;
    }
}
/**
 * A class representing a law firm.
 * @author Pareekshith, Anto, Shreyas, Rishabh
 *
 */
public class LawFirm {

    /**
     * Name of the law firm
     */
    private String name;
    /**
     * The fixed pay of the lawyers in the law firm, initialized to 100000
     */
    private static int fixedPay = 100000;
    /**
     * Reputation of the law firm, initialized to 7
     */
    private static int reputation = 7;   
    
    /**
     * array of lawyers in the law firm
     */
    private Lawyer[] lawyers;
    
    /**
     * Constructs a LawFirm object with the given name and array of lawyers.
     *
     * @param name The name of the law firm.
     * @param lawyers vararg for lawyers in the law firm.
     */
    public LawFirm(String name, Lawyer... lawyers) {
         this.name=name;
         this.lawyers=lawyers;
    }

    /**
     * Assigns a client to a lawyer in the law firm.
     * The law firm checks for the lawyer with the least number of clients and try assigning the criminal to them.
     * If a suitable lawyer is found, he is assigned the client and the reputation of the law firm is increased using increasedReputation() function.
     * If a lawyer isn't found then the reputation of the law firm is reduced using decreaseReputation function.
     * @param c The criminal client to be assigned.
     */
    public void assignClient(Criminal c) {
          Lawyer lawyer=lawyers[0];
          int mx=lawyers[0].getNumClients();
          if(lawyers[0].canAssign(c)==false) {
        	  lawyer=null;
        	  mx=0;
          }
          
          for(int i=0;i<this.lawyers.length;i++) {
        	  if(lawyers[i]==null)continue;
        	  if(lawyers[i].canAssign(c)==false)continue;
        	  if(lawyer==null) {
        		  lawyer=lawyers[i];
        		  mx=lawyers[i].getNumClients();
        		  continue;
        	  }
        	  if(lawyers[i].getNumClients()<lawyer.getNumClients()) {
        		  lawyer=lawyers[i];
        		  mx=lawyers[i].getNumClients();
        	  }
          }
          if(lawyer==null) {
        	  decreaseReputation();
          }else {
        	  lawyer.addClient(c);
        	  increaseReputation();
          }
    }
    
    /**
     * Audits the law firm and decreases the reputation based on the number of corrupt lawyers in the firm.
     * Once the number of corrupt lawyers are found, the overloaded function decreaseReputation(numOfCorruptLawyers) is called.
     */
    public void auditLawfirm() {
        int n=0;
        for(int i=0;i<this.lawyers.length;i++) {
        	if(lawyers[i].getCorruption()) {
        		n+=1;
        	}
        }
        decreaseReputation(n);

    }
    
    /**
     * Assigns an array of clients to lawyers in the law firm.
     * 
     * @param criminals The array of criminal clients to be assigned.
     */
    public void assignClient(Criminal[] criminals) {
        for(int i=0;i<criminals.length;i++) {
        	this.assignClient(criminals[i]);
        }
    }

    /**
     * Returns an array of the lawyers in the law firm.
     * 
     * @return The array of lawyers.
     */
    public Lawyer[] getLawyers() {
      return this.lawyers;
    }

    /**
     * Returns the fixed pay of the lawyers in the law firm.
     * 
     * @return The fixed pay.
     */
    public static int getFixedPay() {
         return LawFirm.fixedPay;
    }

    /**
     * Returns the reputation of the law firm.
     * 
     * @return The reputation.
     */
    public static int getReputation() {
          return LawFirm.reputation;
    }

    /**
     * Increases the reputation of the law firm by 1 and the fixed pay of the lawyers by 10000.
     */
    public static void increaseReputation() {
        reputation+=1;
        fixedPay+=10000;
    }

    /**
     * Decreases the reputation of the law firm by 1 and the fixed pay of the lawyers by 10000.
     */
    public static void decreaseReputation() {
    	reputation-=1;
        fixedPay-=10000;
    }
    
    /**
     * Decreases the reputation of the law firm by numOfCorruptLawyers and the fixed pay of the lawyers by 5000 for each corrupt lawyer in the firm
	 *@param numOfCorruptLawyers denotes number of corrupt lawyers in the firm
	
	*/
	public static void decreaseReputation(int numOfCorruptLawyers) {
       reputation-=numOfCorruptLawyers;
       fixedPay-=numOfCorruptLawyers*5000;
    }
	/**
	 * The Law Firm has the authority to set the fixedPay of the lawyers through setFixedPay function.
	 * @param fixedPay The new fixedPay of the Lawyers.
	 */
	public static void setFixedPay(int fixedPay) {
		
	 LawFirm.fixedPay=fixedPay;
	}
	/**
	 * The reputation of the law firm can be magically saved by *cough* bribing the auditors.
	 * This function is used to set the reputation to desired number
	 * @param reputation the new reputation of the firm
	 */
	public static void setReputation(int reputation) {
		LawFirm.reputation=reputation;
	}
	
}
/**
 * A class representing a lawyer.
 * @author Pareekshith, Anto, Shreyas, Rishabh
 *
 */
public class Lawyer {
    
    /**
     * The name of the lawyer.
     */
    private String name;
    
    /**
     * The influence of the lawyer, which affects the severity of crime that they can take on.
     */
    private int influence;
    
    /**
     * An array of the lawyer's clients.
     */
    private Criminal[] clients;
    
    /**
     * The area of specialization of the lawyer ("violent" , "non-violent")
     */
    private String specialization;
    
    /**
     * The salary of the lawyer.
     */
    private int salary;
    
    /**
     * The number of clients currently assigned to the lawyer.
     */
    private int numClients;
    
    /**
     * A boolean indicating whether the lawyer is corrupt or not.
     */
    private boolean isCorrupt;

    /**
     * The maximum number of clients a lawyer can have at once.
     */
    public static final int MAX_CLIENTS = 10;

    /**
     * Creates a new lawyer with the given name, influence, and area of specialization.
     * Assigns the appropriate salary to the lawyer.
     * @param name the name of the lawyer
     * @param influence the influence of the lawyer
     * @param specialization the area of specialization of the lawyer
     * @param isCorrupt whether the lawyer is corrupt or not
     */
    public Lawyer(String name, int influence, String specialization, boolean isCorrupt) {
              this.name=name;
              this.influence=influence;
              this.specialization=specialization;
              this.isCorrupt=isCorrupt;
              this.clients=new Criminal[MAX_CLIENTS];
              this.salary=0;
    }

    /**
     * Calculates and returns the salary of the lawyer based on the fixed pay of the law firm and the lawyer's influence.
     * salary = (fixedPay of law firm)*(1.0 + influence/10.0).
     * @return the salary of the lawyer
     */
    private int calculateSalary() {
        this.salary=(int)((LawFirm.getFixedPay())*(1.0+this.influence/10.0));
        return this.salary;
    }

    /**
     * Checks if the lawyer can take on the given client based on their specialization, influence, and the number of clients they currently have.
     <pre>
     * A lawyer can take on the case based on the following conditions
     * 1) His specialization matches the crime type of the criminal.
     * 2) Severity of crime is less than or equal to influence of lawyer
     * 3) number of clients of lawyer is less than max clients the lawyer can take in.
     * 4) Lastly, a corrupt lawyer takes a client if the severity of the cases greater than or equal to 8 irrespective of his specialty and influence, provided condition 3 still holds true.
     </pre>
     * @param c the client to check
     * @return true if the lawyer can take on the client, false otherwise
     */
    public boolean canAssign(Criminal c) {
    	 if(this.numClients>Lawyer.MAX_CLIENTS) {
         	return false;
         }
    	 if(this.isCorrupt && c.getSeverity()>=8) {
    		 return true;
    	 }
    	 if(this.specialization!=c.getCrimeType())return false;
    	 if(c.getSeverity()>this.influence)return false;
    	 return true;

    }

    /**
     * Adds the given client to the lawyer's list of clients. 
     * @param c the client to add
     */
	public void addClient(Criminal c) {
        if(this.canAssign(c)) {
        	this.clients[this.numClients++]=c;
        }
    }
	
    /**
     * Returns an array of the lawyer's clients.
     * @return an array of the lawyer's clients
     */
    public Criminal[] getClients() {
        return this.clients;
    }

    /**
     * Returns the number of clients currently assigned to the lawyer.
     * @return the number of clients currently assigned to the lawyer.
     */
    public int getNumClients() {
       return this.numClients;
    }

    /**
     * Returns the influence of the lawyer.
     * @return the influence of the lawyer
     */
    public int getInfluence() {
        return this.influence;
    }

    /**
     * Returns the name of the lawyer.
     * @return the name of the lawyer
     */
    public String getName() {
      return this.name;
    }

    /**
     * Returns the area of specialization of the lawyer.
     * @return specialization
	
	*/
	public String getSpecialization() {
       return this.specialization;
    }
	/**
     * Returns the Salary of the lawyer.
     * @return salary
	*/
	
    public int getSalary() {
    	return this.calculateSalary();
        
    }
	
	/**
     * Returns whether the lawyer is corrupt or not
     * @return isCorrupt
	*/
	public boolean getCorruption(){
		return this.isCorrupt;
	}

}

Editor is loading...