50,527
社区成员
发帖
与我相关
我的任务
分享
import java.util.Vector;
public class HiwayTest3 {
// private static final int ROOMCOUNT = 10;//10個教室
private static final int ROOMWIDTH1 = 20*100;//轉換為CM
private static final int ROOMLENGTH1 = 15*100;
private static final int ROOMWIDTH2 = 20*100;
private static final int ROOMLENGTH2 = 12*100;
private static final int DESKWIDTH1 = 60;
private static final int DESKLENGTH1 = 30;
private static final int DESKWIDTH2 = 120;
private static final int DESKLENGTH2 = 30;
private static final int EXPERIMENT = 0;//上機
private static final int OPENBOOKEXAM = 1;//開卷
private static final int OPENROWSPACE = 1;//行間隔
private static final int OPENCOLSPACE = 1;//列間隔
private static final int CLOSEBOOKEXAM = 2;//閉卷
private static final int CLOSEROWSPACE = 2;//行間隔
private static final int CLOSECOLSPACE = 2;//列間隔
private static final int DESKROWSPACE = 40;//桌子前后的間隔
private static final int DESKCOLSPACE = 40;//桌子左右的間隔 過道的寬度
public static void main(String...args){
HiwayTest3 ht = new HiwayTest3();
// 四個參數:教室寬 教室長 桌子寬 桌子長
ht.deskArray(HiwayTest3.ROOMWIDTH1,HiwayTest3.ROOMLENGTH1,HiwayTest3.DESKWIDTH1,HiwayTest3.DESKWIDTH2);
ht.examStudentNum(HiwayTest3.ROOMWIDTH2, HiwayTest3.ROOMLENGTH2, HiwayTest3.DESKWIDTH2, HiwayTest3.DESKLENGTH2, HiwayTest3.OPENBOOKEXAM);
}
// 某種桌子在某種教室的排列情況
private Vector deskArray(int roomWidth,int roomLength,int deskWidth,int deskLength){
ClassRoom cr = new ClassRoom(roomWidth,roomLength);
Desk desk = new Desk(deskWidth,deskLength);
int colCount = cr.getWidth()/(desk.getWidth()+DESKCOLSPACE);
int rowCount = cr.getLenght()/(desk.getLength()+DESKROWSPACE);
System.out.println(cr+"能放"+colCount+"列"+rowCount+"行"+desk+"的桌子");
Vector<Integer> vec_deskArray = new Vector<Integer>();
vec_deskArray.add(rowCount);
vec_deskArray.add(colCount);
return vec_deskArray;
}
// 桌子佈置已定,某種考試類型的人數
private int examStudentNum(int roomWidth,int roomLength,int deskWidth,int deskLength,int type){
Vector<Integer> v = this.deskArray(roomWidth,roomLength,deskWidth,deskLength);
int rowCount = v.get(0);
int colCount = v.get(1);
if(type==HiwayTest3.OPENBOOKEXAM){//開卷考試
rowCount = rowCount/(HiwayTest3.OPENROWSPACE+1)+1;
colCount = colCount/(HiwayTest3.OPENCOLSPACE+1)+1;
System.out.println("開卷考試可以容納:"+(rowCount*colCount)+"人");
return rowCount*colCount;
}
if(type==HiwayTest3.CLOSEBOOKEXAM){
rowCount = rowCount/(HiwayTest3.CLOSEROWSPACE+1)+1;
colCount = colCount/(HiwayTest3.CLOSECOLSPACE+1)+1;
System.out.println("閉卷考試可以容納:"+(rowCount*colCount)+"人");
return rowCount*colCount;
}
if(type==HiwayTest3.EXPERIMENT){
System.out.println("上機考試可以容納:"+(rowCount*colCount)+"人");
return rowCount*colCount;
}
return 0;
}
//
// ====inner class==================
// 教室類
class ClassRoom{
private int width ;
private int length;
public ClassRoom(int width,int length){
this.width = width;
this.length = length;
}
public int getWidth(){
return this.width;
}
public int getLenght(){
return this.length;
}
@Override
public String toString(){
return "教室規格:"+this.width+"\t"+this.length;
}
}
// 課桌類
class Desk{
private int width ;
private int length;
public Desk(int width,int length){
this.width = width;
this.length = length;
}
public int getWidth(){
return this.width;
}
public int getLength(){
return this.length;
}
@Override
public String toString(){
return "桌子規格:"+this.width+"\t"+this.length;
}
}
// 考試類
class Exam{
private int type;
private int rowSpace;
private int colSpace;
public Exam(int type,int rowSpace,int colSpace){
this.type = type;
this.rowSpace = rowSpace;
this.colSpace = colSpace;
}
public int getType(){
return this.type;
}
public int getRowSpace(){
return this.rowSpace;
}
public int getColSpace(){
return this.colSpace;
}
}
}