package test.checkpassword; public class CheckPassword { public String checkValidPassword(String password) { // Write your code here String res ="invalid"; if(password!=null){ int ovelcount = 0; int conscount = 0; char prevchar=9; boolean hasovel=false; boolean hasconovel=false; boolean hasconcon=false; boolean onlychars=false; boolean length=false; boolean repcars=false; if(password.length()>=6 && password.length()<=20){length =true;} if (password.matches("^[a-zA-Z]+$")) { onlychars =true; } for (int i = 0; i < password.length(); i++) { char c = password.charAt(i); if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u'||c=='A' || c=='E' || c=='I' || c=='O' || c=='U') { hasovel=true; ovelcount++; if(ovelcount>=3){hasconovel=true;} conscount=0; } else{ovelcount=0;conscount++; if(conscount>=3){hasconcon=true;} } if(prevchar==c){ Character cha=new Character(c); if(cha.equals('e')||cha.equals('E')||cha.equals('o')||cha.equals('O')){ System.out.println(cha); }else{System.out.println(c);repcars=true;} } prevchar=c; } if(length==true &&hasovel==true&&onlychars==true &&hasconovel==false&&hasconcon==false&&repcars==false){res="valid";} } return res; } // Sample code to test your solution public static void main(String[] args) { try{ // Example 1 { CheckPassword cp = new CheckPassword(); System.out.println(cp.checkValidPassword("marteen")); } // Example 2 { CheckPassword cp = new CheckPassword(); System.out.println(cp.checkValidPassword(null)); } // Example 3 { CheckPassword cp = new CheckPassword(); System.out.println(cp.checkValidPassword("mensquare")); } } catch(Exception e){ e.printStackTrace(); } } } +++++*******====================================================================== public class ScrabbleWord { private boolean getScrabble(String s1, String s2){ if(s1==null || s2==null || s1.trim().equals("") || s2.trim().equals("")){ return false; } if(s2.length()>s1.length()){ return false; } for(int i=0;is1occ){ return false; } } return true; } private int numOfOccurences(String temp, char ch){ int rtrnCnt=0; for(int i=0;i s = new HashSet(); Matcher ma1t = Pattern.compile("[A-Za-z]+").matcher(""); if (!ma1t.reset(charSequence).matches()) return null; Matcher mat = Pattern.compile(".*"+charSequence+".*").matcher(""); String array [] =paragraph.split(" "); for (int i=0;i Invalid11"); return; } for(int i = 0;i= 3){ System.out.println("===> Repeated Vowels"); return; } }else{ consCnt++; vowelCnt = 0; if(consCnt >= 3){ System.out.println("===> Repeated Cons"); return; } } } for(int i=0;i checking " + str.charAt(i+1)); if(str.charAt(i)!='e' && str.charAt(i)!='o'){ if(str.charAt(i) == str.charAt(i+1)){ return; } } } } } import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class HostelManagement { public boolean hostelAllocate(Connection conn, String studname, String htype){ //Write your code here boolean isAllocated = false; int hostelID = 0; String strSQL = "SELECT hostelid from studenthostel WHERE hosteltype='"+htype+"' AND roomsavailable > 0"; Statement stmt = null; ResultSet rs = null; try{ stmt = conn.createStatement(); rs = stmt.executeQuery(strSQL); if(rs != null && rs.next()){ hostelID = rs.getInt("hostelid"); } System.out.println("====> Hostel ID :: " + hostelID); if(hostelID > 0){ strSQL = "INSERT INTO studenthostelallocation(studentallocid,hostelid, studentname) VALUES(1,"+hostelID+",'"+studname+"')"; stmt = conn.createStatement(); int updatedRec = stmt.executeUpdate(strSQL); if(updatedRec > 0){ strSQL = "UPDATE studenthostel SET roomsavailable=roomsavailable-1 WHERE hostelid="+hostelID; stmt = conn.createStatement(); updatedRec = stmt.executeUpdate(strSQL); if(updatedRec > 0){ isAllocated = true; }else{ isAllocated = false; } } }else{ isAllocated = false; } }catch(Exception e){ e.printStackTrace(); } return isAllocated; } ------------------------------------------------------------------------- select * from studenthostel; select * from studenthostelallocation; select roomsavailable from studenthostel where hosteltype = 'B-AC' int noOfWrongTags = obj.getWrongTags(tag); System.out.println("TestCase 3"); if (noOfWrongTags > -1) { System.out.println("Total number of wrong tag = " + noOfWrongTags); } else System.out.println(noOfWrongTags); } catch (Exception e) { e.printStackTrace(); } } } GradeRank ____________ package test.graderank; import java.util.ArrayList; import java.util.Collections; public class GradeComparison { String name; int maths; int physics; int chemistry; public GradeComparison() { } public GradeComparison(String name, int maths, int physics, int chemistry) { this.name = name; this.maths = maths; this.physics = physics; this.chemistry = chemistry; } GradeComparison[] getRankedResults(ArrayList results) { //Write your code here return null; } // Sample code to test your solution public static void main(String[] args) { try { // Example 1 { ArrayList results = new ArrayList(); results.add(new GradeComparison("Tom", 50, 30, 30)); results.add(new GradeComparison("John", 50, 60, 70)); results.add(new GradeComparison("Mathew", 60, 30, 30)); GradeComparison resultObject = new GradeComparison(); GradeComparison[] result = resultObject.getRankedResults(results); if (result != null) for (int i = 0; i < result.length; i++) { System.out.println(result[i].name); } } // Example 2 { ArrayList results = new ArrayList(); results.add(new GradeComparison("Tom", 50, 40, 30)); results.add(new GradeComparison("John", 50, 60, 70)); results.add(new GradeComparison("Mathew", 60, 30, 30)); GradeComparison resultObject = new GradeComparison(); GradeComparison[] result = resultObject.getRankedResults(results); if (result != null) for (int i = 0; i < result.length; i++) { System.out.println(result[i].name); } } } catch (Exception e) { e.printStackTrace(); } } } UserDataBase ------------------- package test.database; import java.sql.*; public class UserDataBase { public boolean insertUserDetails(Connection conn, String name, String password) { //Write your code here return false; } public boolean modifyUserInfo(Connection conn, String name, String password) { //Write your code here return false; } public String selectUser(Connection conn, String name) { //Write your code here return null; } public boolean deleteUser(Connection conn, String name) { //Write your code here return false; } public static void main(String[] args) { Connection conn = null; try { UserDataBase userDataBase = new UserDataBase(); conn = DBConnection.getConnection(); //TestCase 1 try{ System.out.println(userDataBase.insertUserDetails(conn, "Araxie", "Araxie123"));//print true System.out.println(userDataBase.modifyUserInfo(conn, "Araxie", "Araxie321"));//print true System.out.println("The Password is :" + userDataBase.selectUser(conn, "Araxie"));//print Araxie321 System.out.println(userDataBase.deleteUser(conn, "Araxie"));//print true } catch(Exception e){ e.printStackTrace(); } //TestCase 2 try{ System.out.println(userDataBase.insertUserDetails(conn, "Bishop", "Bishop123"));//print true System.out.println(userDataBase.insertUserDetails(conn, "Bishop", "Bishop123"));//print false System.out.println(userDataBase.modifyUserInfo(conn, "Araxie", "Araxie123")); //print false System.out.println("The Password is :" + userDataBase.selectUser(conn, "Araxie"));//print null System.out.println(userDataBase.deleteUser(conn, "Araxie"));//print false } catch(Exception e){ e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) DBConnection.closeConnection(conn); } } } DBConnection------- --------------------------- package test.database; import java.sql.Connection; import java.sql.SQLException; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; // Use the DBConnection class to connect with the database. // All database connection properties are specified. // You don't need to change anything in this class. public class DBConnection { // Use this to get a SQL Connection public static Connection getConnection() throws Exception { try { doInit(); return mDataSrc.getConnection(); } catch (Exception e) { System.out.println("[DBConnection.getConnection]: " + e.toString()); throw e; } } // Use this to close a SQL Connection public static void closeConnection(Connection connection) { try { if (connection != null) { connection.close(); } } catch (Exception e) { System.out.println("[DBConnection.closeConnection]: " + e.toString()); } } // Use this to test whether the database connection works or not. public static void main(String args[]) { try { Connection conn = DBConnection.getConnection(); System.out.println("DBConnection.getConnection Success..."); DBConnection.closeConnection(conn); System.out.println("DBConnection.closeConnection Success..."); } catch (Exception e) { e.printStackTrace(); } } // Private variables and functions private static MysqlDataSource mDataSrc = new MysqlDataSource(); private static boolean isInitDone = false; private static String DB_SERVER = "202.138.101.234"; private static int DB_SERVER_PORT = 3306; private static String DB_NAME = "mysqldb_115404"; private static String USER_NAME = "mysqldb_115404"; private static String USER_PASSWORD = "mysqldb_115404"; private static synchronized void doInit() throws Exception { if (isInitDone) return; mDataSrc.setServerName(DB_SERVER); mDataSrc.setPort(DB_SERVER_PORT); mDataSrc.setDatabaseName(DB_NAME); mDataSrc.setUser(USER_NAME); mDataSrc.setPassword(USER_PASSWORD); isInitDone = true; } } -----------------------------------------------------------------++++++++++++++++ DBConnection ------------------- package test.hostelmanage; import java.sql.Connection; import java.sql.SQLException; import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; // Use the DBConnection class to connect with the database. // All database connection properties are specified. // You don't need to change anything in this class. public class DBConnection { // Use this to get a SQL Connection public static Connection getConnection() throws Exception { try { doInit(); return mDataSrc.getConnection(); } catch (Exception e) { System.out.println("[DBConnection.getConnection]: " + e.toString()); throw e; } } // Use this to close a SQL Connection public static void closeConnection(Connection connection) { try { if (connection != null) { connection.close(); } } catch (Exception e) { System.out.println("[DBConnection.closeConnection]: " + e.toString()); } } // Use this to test whether the database connection works or not. public static void main(String args[]) { try { Connection conn = DBConnection.getConnection(); System.out.println("DBConnection.getConnection Success..."); DBConnection.closeConnection(conn); System.out.println("DBConnection.closeConnection Success..."); } catch (Exception e) { e.printStackTrace(); } } // Private variables and functions private static MysqlDataSource mDataSrc = new MysqlDataSource(); private static boolean isInitDone = false; private static String DB_SERVER = "202.138.101.234"; private static int DB_SERVER_PORT = 3306; private static String DB_NAME = "mysqldb_93985"; private static String USER_NAME = "mysqldb_93985"; private static String USER_PASSWORD = "mysqldb_93985"; private static synchronized void doInit() throws Exception { if (isInitDone) return; mDataSrc.setServerName(DB_SERVER); mDataSrc.setPort(DB_SERVER_PORT); mDataSrc.setDatabaseName(DB_NAME); mDataSrc.setUser(USER_NAME); mDataSrc.setPassword(USER_PASSWORD); isInitDone = true; } } ************************************* HostalManagement package test.hostelmanage; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class HostelManagement { public boolean hostelAllocate(Connection conn, String studname, String htype){ try { Statement prdStment = conn.createStatement(); if(htype.equals("B-AC")||htype.equals("B")||htype.equals("G-AC")||htype.equals("G")) { System.out.println("hostel type is"+htype); ResultSet rs1=prdStment.executeQuery("select roomsavailable from studenthostel where hosteltype = '" + htype+"';"); System.out.println("number of rooms "+rs1.getRow()); int noRooms = Integer.parseInt(rs1.getString(1)); System.out.println("number of rooms "+noRooms); if(noRooms >0) { ResultSet rs=prdStment.executeQuery("select hostelid from studenthostel where hosteltype = '" + htype+"'"); String hstlID = rs.getString(0); prdStment.executeQuery("insert into studenthostelallocation values ''," + hstlID +"," + studname ); noRooms--; prdStment.executeQuery("update studenthostel set roomsavailable = " + noRooms +" where hosteltype = " + htype); return true; } else { return false; } } else { return false; } } catch (SQLException e) { e.printStackTrace(); } return false; } public static void main(String[] args){ Connection conn = null; String[] hosteltype = {"B-AC","B","G-AC","G"}; //TestCase 1 try{ conn = DBConnection.getConnection(); String name = "Mark"; String htype = hosteltype[0]; boolean retout = new HostelManagement().hostelAllocate(conn, name, htype); //Return true System.out.println(retout); } catch(Exception e){ e.printStackTrace(); } finally{ if(conn!=null) DBConnection.closeConnection(conn); } //TestCase 2 try{ conn = DBConnection.getConnection(); String name = "Joe"; String htype = hosteltype[3]; boolean retout = new HostelManagement().hostelAllocate(conn, name, htype); //Return true System.out.println(retout); } catch(Exception e){ e.printStackTrace(); } finally{ if(conn!=null) DBConnection.closeConnection(conn); } //TestCase 3 try{ conn = DBConnection.getConnection(); String name = "Meera"; String htype = hosteltype[3]; boolean retout = new HostelManagement().hostelAllocate(conn, name, htype); //Return false System.out.println(retout); } catch(Exception e){ e.printStackTrace(); } finally{ if(conn!=null) DBConnection.closeConnection(conn); } } } ****************************************************************** package test.wordToNumeric; public class WordToNumeric { public long getNumericValue(String numberInWord) { if(check(numberInWord)) { return -1; } // for(int i=0;i< numberInWord.length();i++) // { // } else { long Number = 0; int num = 0 ; String numSplit[] = numberInWord.split(" "); for(int i=0; i31||Integer.parseInt(sDate2[0])>31) { return "invalid"; } else diffday = Integer.parseInt(sDate2[0])-Integer.parseInt(sDate1[0]); if(Integer.parseInt(sDate1[1])>12||Integer.parseInt(sDate2[1])>12) { return "invalid"; } else diffmon = Integer.parseInt(sDate2[1])-Integer.parseInt(sDate1[1]); if(Integer.parseInt(sDate1[2])>9999||Integer.parseInt(sDate1[2])<1000||Integer.parseInt(sDate2[2])>9999||Integer.parseInt(sDate2[2])<1000) { return "invalid"; } else diffyear = Integer.parseInt(sDate2[2])-Integer.parseInt(sDate1[2]); } return "Days: "+ diffday +" Months: "+ diffmon +" Years: "+diffyear; } public static void main(String[] args) { // testCase 1 { DifferenceCalculator dc = new DifferenceCalculator(); System.out.println(dc.dateDiffrence("12/12/2008", "19/12/2009")); } // testCase 2 { DifferenceCalculator dc = new DifferenceCalculator(); System.out.println(dc.dateDiffrence("32/02/2008", "19/13/2009")); } } }