Hello all! I am very new to
Java. I have been working for a couple months on a program for school. It has not gone well. I finally was able to scrap together a working program, but i left something out that needs to be. I have to include input validation to check for negative values, prompting users to re-enter values if negative. Now for the life of me i have not been able to figure this out and could really use some expert help. I have included my current code, the program works perfectly, but i have no idea what to do about the negative numbers. Thanks!!!
package gradplanner;
import java.util.Scanner;
public class GradPlanner {
public static void main(
String[] args) {
Scanner input = new Scanner(System.in);
int numofclasses = 0;
int totalCUs = 0;
System.out.print("Enter number of courses left in the degree program: ");
numofclasses = input.nextInt();
int numCU[] = new int[numofclasses];
for (int i = 0; i < numofclasses; i++) {
System.out.print("Input the number of CUs for course (" + (i + 1) + "): ");
numCU[i] = input.nextInt();
totalCUs += numCU[i];
}
System.out.println("Total total number of CUs for all courses: " + totalCUs);
double plannedCUs = 0;
do {
System.out.print("How many CUs you are planning to take each term: ");
plannedCUs = input.nextInt();
if (plannedCUs < 12 || plannedCUs > totalCUs) {
System.out.println("Take each term with a minimum of 12 CUs being selected and upto total");
}
} while (plannedCUs < 12 || plannedCUs > totalCUs);
double numTermsToCompletion = Math.ceil(totalCUs / plannedCUs);
System.out.println("Number of terms to completion: " + numTermsToCompletion);
System.out.println("Tuition cost based on number of terms to completion: $" + (numTermsToCompletion * 2890));
System.out.println("Number of months to completion: " + (numTermsToCompletion * 6));
}
}