I had come out a reference code (in this case I finding ages) and it works well ..
Here's the code :
private Map<String, Integer> peopleAge = new HashMap<String, Integer>();
private void loadData() {
peopleAge.put("alex", 21);
peopleAge.put("john", 29);
peopleAge.put("peter", 18);
peopleAge.put("mary", 30);
peopleAge.put("cindy", 18);
peopleAge.put("chris", 17);
peopleAge.put("david", 22);
}
private String whoIsYoungest() {
int lastYoungestAge = 0;
String lastYoungestPerson = null;
for (String currentPerson : peopleAge.keySet()) {
int currentPersonAge = peopleAge.get(currentPerson);
System.out.println("Comparing " + currentPerson + " with age " + currentPersonAge);
if (lastYoungestPerson == null) {
// init to the 1st person
System.out.println("Initialise youngest person to " + currentPerson);
lastYoungestPerson = currentPerson;
lastYoungestAge = currentPersonAge;
} else if (currentPersonAge < lastYoungestAge) {
System.out.println(currentPerson + " is younger than " + lastYoungestPerson);
lastYoungestPerson = currentPerson;
lastYoungestAge = currentPersonAge;
} else {
System.out.println(currentPerson + " is same or older than " + lastYoungestPerson);
}
System.out.println();
}
return lastYoungestPerson;
}
public static void main(String[] args) {
WhoIsYoungerDemo demo = new WhoIsYoungerDemo();
demo.loadData();
System.out.println("***** The youngest person is " + demo.whoIsYoungest());
}
}
But however I'm now stuck ... How can I possible modify this
try {
FileWriter writer = new FileWriter(file);
BufferedReader br1 = new BufferedReader(new FileReader(testfile));
BufferedReader br2 = new BufferedReader(new FileReader(screeningbase));
File[] listOfFiles = folder.listFiles();
String strLine = null;
if ((strLine = br1.readLine()) != null) {
strLine = strLine.substring(strLine.indexOf(".") + 4);
for (int i = 0; i < strLine.length(); i++) {
if (strLine.charAt(i) == '1') {
result1.set(i, true);
}
}
result1.set(strLine.length(), true);
}
while ((strLine = br2.readLine()) != null) {
strLine = strLine.replaceAll(",", "").substring(strLine.indexOf(".") + 5);
BitSet bitSet = new BitSet();
for (int i = 0; i < strLine.length(); i++) {
if (strLine.charAt(i) == '1') {
bitSet.set(i, true);
}
}
bitSet.set(strLine.length(), true);
result2.add(bitSet);
}
for (int i = 0; i < result2.size(); i++) {
BitSet bitSet2 = result2.get(i);
float nresult = bitSet2.cardinality();
bitSet2.and(result1);
writer.append(listOfFiles[i].getName());
writer.append(",");
writer.flush();
for (int j = 0; j < bitSet2.length() - 1 || j < result1.length() - 1; j++) {
if (bitSet2.get(j)) {
writer.append("1");
writer.append(",");
writer.flush();
} else {
writer.append("0");
writer.append(",");
writer.flush();
}
}
float ntarget = result1.cardinality();
float nlast = bitSet2.cardinality();
nlast = (nlast / (ntarget + nresult - nlast));
float round = Round(nlast, 3);
writer.append(round);
writer.append("\n");
}
to something similar to the above ?"listOfFiles" will represent the name(e.g. alex) and "round" will represent the age.


Sign In
Create Account


Back to top









