# Remainder issue

• July 4th, 2014, 01:33 PM
mrivera85
Remainder issue
The actual computations aren't working properly when it comes to the remainder. Specifically the variable termLeft. Any suggestions?

Code Java:

```package graduationplanner; import java.util.Scanner; import java.util.ArrayList;   public class GraduationPlanner {   public static void main(String[] args) { Scanner in = new Scanner(System.in); final int MINCU = 12; final int TUITIONCOST = 2890; //stores value for tuition cost per term final int TERMMONTHS = 6; //stores value for number of months in a term int sum = 0;   System.out.println("Welcome to the Western Governor's University Graduation Planner! \nWe will calculate the number of terms you have left until graduation, \nalong with the amount of tuition you have left to pay. \nWe will also provide the number of months until graduation! \nLet's get started by asking a few questions.");   System.out.println("How many CU's are you planning on taking per term?"); //Prompts user for the number of CU's per term int perTerm = in.nextInt(); //storing user input if (perTerm < MINCU){ //verification on positive input by user System.out.println("12 CU's are required per term. Try a higher number!"); System.out.println("How many CU's are required for your degree?"); perTerm = in.nextInt();} //stores corrected number //System.out.println(perTerm);   ArrayList<Integer> leftCU = new ArrayList<>();{ System.out.println("Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done."); leftCU.add(in.nextInt()); while (in.hasNextInt()){ leftCU.add(in.nextInt());} for(int i=0; i < leftCU.size(); i++){ sum = sum + leftCU.get(i);} } //System.out.println(leftCU); //System.out.println(sum);   System.out.println("The number of CU's left are: "+ leftCU); System.out.println("The sum of the number of CU's left are: " + sum);   int tempLeft = sum/perTerm; //Calculates number of terms left int termLeft = 0; if ((tempLeft % 4) == 0){ termLeft = tempLeft;} else {termLeft = tempLeft + 1;} int totalTuition = termLeft * TUITIONCOST; //Calculates the amount of tuition left to pay int monthsLeft = termLeft * TERMMONTHS; //Calculates the number of months left   System.out.println("Number of terms left is " + sum + " divided by " + perTerm + " equals " + termLeft); System.out.println("Total amount of tuition left is " + termLeft + " times " + TUITIONCOST + " equals " + totalTuition); System.out.println("Number of Months left is " + termLeft + " times " + TERMMONTHS + " equals " + monthsLeft);   System.out.println("+----------------------------------------+"); System.out.println("|Number of Terms left is: " + termLeft + "|"); System.out.println("|Total amount of Tuition left is: " + totalTuition + "|"); System.out.println("|Number of Months left is: " + monthsLeft + "|"); System.out.println("+----------------------------------------+"); System.out.println("Thank you for using the WGU Graduation Planner"); } }```
• July 4th, 2014, 01:38 PM
GregBrannon
Re: Remainder issue
Rather than require us to run your code, determine the inputs etc., and find logic errors, could you PLEASE, PLEASE, PLEEEEEEEZE, provide a sample run, describe what inputs you used, what output is expected, and what output was received?
• July 4th, 2014, 03:05 PM
mrivera85
Re: Remainder issue
Quote:

Originally Posted by GregBrannon
Rather than require us to run your code, determine the inputs etc., and find logic errors, could you PLEASE, PLEASE, PLEEEEEEEZE, provide a sample run, describe what inputs you used, what output is expected, and what output was received?

My apologies - here's the output:

Welcome to the Western Governor's University Graduation Planner!
We will calculate the number of terms you have left until graduation,
along with the amount of tuition you have left to pay.
We will also provide the number of months until graduation!
Let's get started by asking a few questions.
How many CU's are you planning on taking per term?
12
Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done.
10
10
10
10
10
q
The number of CU's left are: [10, 10, 10, 10, 10]
The sum of the number of CU's left are: 50
Number of terms left is 50 divided by 12 equals 4
Total amount of tuition left is 4 times 2890 equals 11560
Number of Months left is 4 times 6 equals 24
+----------------------------------------+
|Number of Terms left is: 4|
|Total amount of Tuition left is: 11560|
|Number of Months left is: 24|
+----------------------------------------+
Thank you for using the WGU Graduation Planner.

The 4 should actually increase to 5 because of the If, Else statement, but it's not.
• July 4th, 2014, 03:49 PM
Norm
Re: Remainder issue
Quote:

The 4 should actually increase to 5
What is the reason that the 4 should be incremented to 5?
What line of code should do that?
If the values of the variables don't make the code execute as you want, what values should the variables have?
• July 4th, 2014, 04:37 PM
mrivera85
Re: Remainder issue
Quote:

Originally Posted by Norm
What is the reason that the 4 should be incremented to 5?
What line of code should do that?
If the values of the variables don't make the code execute as you want, what values should the variables have?

Here is the "calculation" portion of the code:

Code Java:

``` int tempLeft = sum/perTerm; //Calculates number of terms left int termLeft = 0; if ((tempLeft % 4) == 0){ termLeft = tempLeft;} else {termLeft = tempLeft + 1;} int totalTuition = termLeft * TUITIONCOST; //Calculates the amount of tuition left to pay int monthsLeft = termLeft * TERMMONTHS; //Calculates the number of months left```

I put in enough for a total of 50 for sum and 12 for term. That should leave a remainder and thus increase the 4 that 50/12 gives to a 5. I know using int as the data type drops the decimal, but the if, else statement is supposed to account for that. What am I missing?

Thanks for helping!
• July 4th, 2014, 04:43 PM
Norm
Re: Remainder issue
Quote:

That should leave a remainder
What variable has that value for a remainder?
What expression is not computing the value that you want?
If you can not tell, add a println() statement after each expression that prints out the value computed.

Quote:

if, else statement is supposed to account for that.
How? What value does the variable have when the if statement is executed?