public class ConcertSeat implements java.io.Serializable{
public static final int FREE = 0;
public static final int RESERVED = 1;
public static final int ALLOCATED = 2;
private int status;
private String seatString,opName;
/** This method is ConcertSeat constructor.
* @param int x - row number, int y - column number
* @return No return value for constructor
* @exception without throws exceptions
*/
public ConcertSeat(int x, int y){
char pos;
String row;
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
row = String.valueOf(x);
pos = alphabet.charAt(y);
status = FREE;
seatString = row + pos;
}
/** This method is use to get the Seat Number
* @param No parameter
* @return String - Seat Number
* @exception without throws exceptions
*/
public String seatNumber(){ return seatString;}
/** This method is use to get the operator name
* @param No parameter
* @return String - operator name
* @exception without throws exceptions
*/
public String getOperator(){ return opName;}
/** This method is use to get the seat status
* @param No parameter
* @return String - seat status
* @exception without throws exceptions
*/
public int getStatus(){ return status;}
/** This method is set the seat status according to new seat status
* @param int newStatus - required seat status, String operator name - the name of operator who want to change he seat status
* @return boolean - return true is status changed succesfully, otherwise false
* @exception without throws exceptions
*/
public boolean setStatus(int newStatus, String operator){
if(status != ALLOCATED){
if(status == FREE && newStatus == RESERVED){
status = newStatus;
opName = operator;
return(true);
}
else if((newStatus == FREE || newStatus == ALLOCATED) && status == RESERVED && operator.compareTo(opName)==0){
status = newStatus;
return(true);
}
else
return(false);
}
else
return(false);
}
}