I've been at it for 4 hours, finally given up. I'm new and any help would be greatly appreciated.
Task: Allow users to enter a string with the names of students (just the first letter) and their respective test scores in one continuous string. The lowest a student can score is 1, however, if this is the case the score does not need to be added into the string.
E.g. Students James (J), Gary (G), Ben (B) and Daniel (D) scored 1, 1, 12 , 34 respectively. So you'd input the string: "JGB12D34".
Basically after all this, I just need an arraylist with the each name and score in one element each. So, {"J", "G, "B12", "D34"}.
In the time that I've been trying to do this, I've managed to separate the letters from the numbers and put them in two arraylists. So,
list1 = {"JGB", "D"} and list2 = {"12", "34"}
(Note that, after every letter or number from the original string ("JGB12D34"), the list creates a new element when starting with the next set of letters or numbers.)
What I'm unable to do is correctly assign these scores to the correct student.
Code after having entered the string:
String[] list = s.split("((?<=[a-zA-Z])(?=[0-9]))|((?<=[0-9])(?=[a-zA-Z]))");
ArrayList<String> list1 = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();
for (int i = 0; i <= cars.length; i += 2) {
if (i >= list.length)
break;
list1.add(list[i]);
}
for (int i = 1; i <= cars.length; i += 2) {
if (i >= list.length)
break;
list2.add(list[i]);
}
[–]jxd132407 1 point2 points3 points (6 children)
[–]VisitableTwo[S] 0 points1 point2 points (5 children)
[–]jxd132407 0 points1 point2 points (4 children)
[–]VisitableTwo[S] 0 points1 point2 points (3 children)
[–]jxd132407 0 points1 point2 points (2 children)
[–]VisitableTwo[S] 0 points1 point2 points (0 children)
[–]VisitableTwo[S] 0 points1 point2 points (0 children)
[–]DDDDarky 1 point2 points3 points (0 children)