As input i have a File containing a list of rooms. Each room has the following information: (1 line of the file)
ID;name;phonenumber;PIN e.g.:
1234;A 0.12;1234;123456789 (ID is same as [first] phonenumber)
2345;A 0.12;2345;123456789 (A room can have more than 1 phonenumber - in a new line like in the example)
Now i need a java program which returns a list like this:
Example Input: 1127,A 0.01,1127,1 2476,A 0.01,2476,1 2309,A 0.01,2309,1 2306,A 0.01,2306,1 2706,A 0.01,2706,1 2757,A 0.01,2757,1 Generates Output: 1127,A 0.01,1127,2476,2309,2306,2706,2757,1
ID;name;phonenumber1;...;phonenumberN;PIN
This code (without main function) adds a second phone number to the existing one, if the rooms from 2 lines are the same.
public static String duplicateNumbers(String s, String x) {
String result = s;
if(compareString(s, x)) {
result = result.substring(0, 21)
+ x.charAt(21) + x.charAt(22) + x.charAt(23) + x.charAt(24)
+ result.substring(20);
}
return result;
}
public static boolean compareString(String s, String x) {
for(int i = 5; i < 10; i++) {
if(s.charAt(i) != x.charAt(i)) return false;
}
return true;
}
ß
Aucun commentaire:
Enregistrer un commentaire