rt

Reader's Theatre
Log | Files | Refs | README | LICENSE

group.java (1174B)


      1 package space.nocebo;
      2 
      3 import java.lang.Math;
      4 
      5 public class group implements Cloneable {
      6 	private acc[] gAccounts = new acc[3];
      7 	private int nelem;
      8 	private int cmet;		// condition met flag - when set conditions are met
      9 	private float tscr;
     10 	String gid;
     11 
     12 	public group() {
     13 		nelem = 0;
     14 		cmet = 1;
     15 		tscr = 0.0f;
     16 		gid = util.getAlphaNumString();
     17 	}
     18 
     19 	public Object clone() throws CloneNotSupportedException {
     20 		return super.clone();
     21 	}
     22 	
     23 	public synchronized int add(acc m) {
     24 		if (nelem < 3) {
     25 			for (int i = 0; i < nelem; i++)
     26 				if (Math.abs(gAccounts[i].getScore() - m.getScore()) > 2)
     27 					cmet = 0;
     28 			if (cmet == 1) {
     29 				gAccounts[nelem] = m;
     30 				nelem++;
     31 				cmet = 1;
     32 				return 1;
     33 			}
     34 		}
     35 		return 0;
     36 	}
     37 
     38 	public String getGid() {
     39 		return gid;
     40 	}
     41 	
     42 	public synchronized int getNumMem() {
     43 		return nelem;
     44 	}
     45 
     46 	public synchronized float getAvgscr() {
     47 		tscr = 0.0f;
     48 		for (int i = 0; i < nelem; i++)
     49 			tscr += gAccounts[i].getScore();
     50 		return tscr/nelem;
     51 	}
     52 
     53 	public synchronized void getAccUname() {
     54 		String s = "dbg group: ";
     55 		for (int i = 0; i < nelem; i++) {
     56 			s += " " + gAccounts[i].getUname();
     57 		}
     58 		s += " " + nelem;
     59 		System.out.println(s);
     60 	}
     61 }