Question

int remainingCredit = 144 - (coreCredit + majorCredit); int remainingSubjects = remainingCredit / 6; int e...

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.

Homework Answers

Answer #1
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;
}
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length();...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i].length() < minLength) minLength = array[i].length(); } return minLength; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] strings = new String[50]; for (int i = 0; i < strings.length; i++) { System.out.print("Enter string " + (i + 1) + ": "); strings[i] = in.nextLine(); } System.out.println("Length of smallest...
I am trying to take a string of numbers seperated by a single space and covert...
I am trying to take a string of numbers seperated by a single space and covert them into a string array. I have created the following code but it only works if the numbers are seperated a a comma or something similar to that. Example of what I am trying to achieve: string input = "1 1 1 1 1" turn it into.... int[] x = {1,1,1,1} so that it is printed as... [1, 1, 1, 1]    This is...
Analyze this code and run it, if there are any issues note them and fix them,...
Analyze this code and run it, if there are any issues note them and fix them, if not give the output and Big O notation runtime: public class PrintBits { public static void printBits(int a) { try { String str = Integer.toBinaryString((Integer) a); for(int i = 0; i < str.length(); i++){ System.out.print (str.charAt(i)); } } catch (ClassCastException e) { throw new RuntimeException ("Argument is not an Integer"); } } public static void main (String[] args){ printBits (-17); System.out.println(); printBits (17);...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
JAVA programming language: What is the output? for (int i = 0; i < 3; i++)...
JAVA programming language: What is the output? for (int i = 0; i < 3; i++) { for (int j = 0; j < 8; j++) { if (j>= 2) { break: } System.out.print("" + i + j + " "); } } Select one: a) 00 11 22 00 11 22 b) 00 01 10 11 20 21 c) 012 123 234 d) 000 001 100 110 200 210
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
Modify the CountByFives application so that the user enters the value to count by. Start each...
Modify the CountByFives application so that the user enters the value to count by. Start each new line after 10 values have been displayed. (Cengage Mindtap assignment). This is the java code we are given: public class CountByAnything { // Modify the code below public static void main (String args[]) { final int START = 5; final int STOP = 500; final int NUMBER_PER_LINE = 50; for(int i = START; i <= STOP; i += START) { System.out.print(i + "...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...