public void sselectex(String cid, int sid){
		
		while(true){
			try{
				//display all open exercise				
				Connection conn = DBConnection.ConnectDB();
				PreparedStatement stmt = conn.prepareStatement("SELECT eid, hwname, startdate, enddate, allowattempt FROM Exercise WHERE cid=?");
				stmt.setString(1, cid);
				ResultSet rs = stmt.executeQuery();
				
		        String[] exname = new String[20];// Array which stores the course id student enrolled
				int[] eidt = new int[20]; 
				int[] allowattempt = new int[20]; 

		        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
	        	String nowdate = df.format(new Date());
	        	
	        	//System.out.println(nowdate);
		        
	        	int i = 1;	
				while(rs.next()){//list all valid exercises
					exname[i] = rs.getString("hwname");
					eidt[i] = rs.getInt("eid");
					allowattempt[i] = rs.getInt("allowattempt");
					String startdate = rs.getString("startdate");
					String enddate = rs.getString("enddate");
		        	if(nowdate.compareTo(enddate) <=0  && nowdate.compareTo(startdate) >=0)//valid
		        	{
		        		System.out.printf(" %d. %s\n",i,exname[i]);
			        	i++;
		        	}
					
				}
		        System.out.println(" 0. Back");
		        
		        Scanner scan = new Scanner(System.in);
	        	int Choice = -1;
		        // get user choice
		        System.out.println("Please enter the corresponding number:");		        	
		        while(true){
		           	Choice = scan.nextInt();
		           	if(checkint(Choice,0,i-1))
		        		break;			        	
		        }
		        			       
				//System.out.printf("%s",Choice);
		        if (Choice == 0){
		        	System.out.print('\u000C');
		        	break;// go back
		        }
		        else{//eidt[Choice] correspond to the exercise id the student choose
		        	System.out.print('\u000C');
		        	StudentAttemptExercise attempt = new StudentAttemptExercise();
		        	attempt.studentattempt(eidt[Choice],exname[Choice],sid,allowattempt[Choice]);

		        }       
				
		        conn.close();
			}//try
			catch(Exception e){
				System.out.println("Problem : "+ e.getMessage());
			}
			
			
		}//outer while
		
		
		
		
		
	}//public void sselectex