int remainingCredit = 144 - (coreCredit + majorCredit);
int remainingSubjects = remainingCredit / 6;
int e = remainingSubjects;
int totalCredit = (coreCredit + majorCredit);
int j;
for (j = e; j > 0; j--) {
int flag = 0;
System.out.print("Please select " + j + " more elective subjects:
");
String electives = sc.nextLine();
String[] electivesSplit = electives.split(",");
switch (select) {
case 1:
int k;
for (k = 0; k < bDataCores.length; k++) {
if (electives.contains(bDataCores[k].getSubjectCode())) {
System.out.print("(note: " + electives + " is in the major, so it
isn't counted)");
System.out.println();
j++;
flag = 1;
break;
}
}
if ((flag == 0)) {
for (Subject subj : cEles) {
if (electives.contains(subj.getSubjectCode())) {
bcs.enrolStudentElectiveSubject(subj, stud1);
System.out.print("(note: " + electives + " is counted)");
System.out.println();
totalCredit = totalCredit + 6;
break;
}
}
}
break;
}
}
How can I get this code to use a string split using a comma. I cannot post the full code, but I hope you can get an idea. What needs to happen is a user should be able to choose electives subjects, using a comma. So they can choose Elective a, Elective b. The code should count both inputs. How can I modify this code to use a string split with a comma. Help would really be appreciated. Thank you.
int remainingCredit = 144 - (coreCredit + majorCredit);
int remainingSubjects = remainingCredit / 6;
int e = remainingSubjects;
int totalCredit = (coreCredit + majorCredit);
int j=e;
while(j>0) {
int flag = 0;
System.out.print("Please select " + j + " more elective subjects: ");
String electives = sc.nextLine();
String[] electivesSplit = electives.split(",");
j=j-(electivesSplit.length());
switch (select) {
case 1:
int k;
for (k = 0; k < bDataCores.length; k++) {
if (electives.contains(bDataCores[k].getSubjectCode())) {
System.out.print("(note: " + electives + " is in the major, so it isn't counted)");
System.out.println();
j++;
flag = 1;
break;
}
}
if ((flag == 0)) {
for (Subject subj : cEles) {
if (electives.contains(subj.getSubjectCode())) {
bcs.enrolStudentElectiveSubject(subj, stud1);
System.out.print("(note: " + electives + " is counted)");
System.out.println();
totalCredit = totalCredit + 6;
break;
}
}
}
break;
}
}
Get Answers For Free
Most questions answered within 1 hours.