I know this is not very good. I am currently in my first programming class (Java).  It seems like it works, but I am sure there are things I have not thought of.The goal is to have a user enterthe number of credit units each class they need to take is worth, one by onethe number of credit units to complete in a termThe program should calculatethe number of remaining credit unitsthe number of terms it will take to complete the degreethe costimport java.util.ArrayList;import java.util.Scanner;public class GraduationPlanner {    public static void main(String[] args) {        int sum = 0;        String creditUnits;        int unitsLeft;        int plannedUnits = 0;        int termsLeft = 0;        double tuitionCost = 0;        final double TUITION_RATE = 2890;        ArrayList<Integer> cu = new ArrayList<Integer>();        Scanner in = new Scanner(System.in);        System.out.println(Please input the Credit Units for each course. Press enter after each course. Press Q when finished:  );        while (in.hasNextInt()) {            int temp = (in.nextInt());            if (temp < 0) {                System.out.print(ERROR! Please enter a number 1-9.: );            } else {                cu.add(temp);            }        }        System.out.println(cu);        Scanner ex = new Scanner(System.in);        System.out.print(Please enter the number of Credit Units you will complete per term: );        if (ex.hasNextInt()) {            plannedUnits = ex.nextInt();        }        for (int a : cu)         {            sum += a;        }        unitsLeft = (sum - plannedUnits);        termsLeft = (sum / plannedUnits);        tuitionCost = (termsLeft * TUITION_RATE);        System.out.println(After this term there are  + unitsLeft +  credit units remaining.);        System.out.println(You will complete your degree in  + termsLeft +  terms.);        System.out.print(It will cost you  + tuitionCost +  to complete your degree.);    }}New code block/* Determines the length of time and cost of a degree program * based on user inputs. */import java.util.ArrayList;import java.util.Scanner;public class GraduationPlanner {    public static void main(String[] args) {        final double TUITION_RATE = 2890;        ArrayList<Integer> creditUnits = new ArrayList<Integer>();        Scanner unitsPerCourse = new Scanner(System.in);        GetCreditUnits(unitsPerCourse, creditUnits);        System.out.println(creditUnits);         System.out.print(Please enter the number of Credit Units you will complete per term: );        Scanner goalUnits = new Scanner(System.in);        int plannedUnits = GetPlannedUnits(goalUnits);        int creditUnitsSum = TotalOfCreditUnits(creditUnits);        double tuitionCost;        int termsLeft = CalculateTermsToComple(creditUnitsSum, plannedUnits);        int unitsLeft;        unitsLeft = CalculateUnitsLeft(creditUnitsSum, plannedUnits);        tuitionCost = CalculateTuition(termsLeft, TUITION_RATE);        System.out.println(After this term there are  + unitsLeft +  credit units remaining.);        System.out.println(You will complete your degree in  + termsLeft +  terms.);        System.out.print(It will cost you  + tuitionCost +  to complete your degree.);        unitsPerCourse.close();        goalUnits.close();    }    public static void GetCreditUnits(Scanner unitsPerCourse, ArrayList<Integer> creditUnits) {        System.out.println(Please input the Credit Units for each course. Press enter after each course. Press Q when finished:  );        while (unitsPerCourse.hasNextInt()) {            int currentUnit = (unitsPerCourse.nextInt());            if (currentUnit < 1 || currentUnit >= 10) {                System.out.print(ERROR! Please enter a number 1-9.: );            } else {                creditUnits.add(currentUnit);            }        }    }    public static int GetPlannedUnits(Scanner goalUnits) {        int plannedUnits = 0;        if (goalUnits.hasNextInt()) {            plannedUnits = goalUnits.nextInt();        } else {            System.out.print(ERROR! Please enter an integer!: );        }        return plannedUnits;    }    public static int CalculateTermsToComple(int creditUnitsSum, int plannedUnits) {        int termsLeft = (int) Math.ceil((double) creditUnitsSum / plannedUnits);        return termsLeft;    }    public static int CalculateUnitsLeft(int creditUnitsSum, int plannedUnits) {        int unitsLeft;        unitsLeft = creditUnitsSum - plannedUnits;        return unitsLeft;    }    public static double CalculateTuition(int termsLeft, final double TUITION_RATE) {        double tuitionCost;        tuitionCost = termsLeft * TUITION_RATE;        return tuitionCost;    }    public static int TotalOfCreditUnits(ArrayList<Integer> creditUnits) {        int creditUnitsSum = 0;        for (int unit : creditUnits) {            creditUnitsSum += unit;        }        return creditUnitsSum;    }}
Graduation planner
java;beginner
Your program is a good starting point. It's not perfect but it doesn't have to be (I've seen code much worse than yours written by people studying programming for longer than you have). Now, our goals when writing programs are:Make it workMake it readable.If your program works, then congratulations -- the first step is complete.Here goes the actual review.Many of the variables you used have decent names (plannedUnits, etc.), but we can do better:The variables cu and a: What are those? cu seems to be the list that stored course units, so I'm guessing that's what cu stands for. But characters are cheap, so let's rename cu to courseUnits and a to courseUnit!sum is reasonable -- it tells us that it is keeping track of the sum of something. But what exactly? It seems to be course units, so let's call it courseUnitSum or sumOfCourseUnits.You use two variables (in and ex). Rename them to courseUnitsScanner and plannedUnitsScanner.temp is not very clear either. Maybe newCourseUnit?creditUnits is not used anywhere, is it? If you don't need it, then delete it.In second place, I see you declaring tons of variables early but only using them late in the code. Try to declare variables as late as possible -- and let's see what we can come up withimport java.util.ArrayList;import java.util.Scanner;public class GraduationPlanner {    public static void main(String[] args) {        System.out.println(Please input the Credit Units for each course. Press enter after each course. Press Q when finished:  );        Scanner in = new Scanner(System.in);        ArrayList<Integer> courseUnits = new ArrayList<Integer>();        while (in.hasNextInt()) {            int newCourseUnit = (in.nextInt());            if (newCourseUnit < 0) {                System.out.print(ERROR! Please enter a number 1-9.: );            } else {                courseUnits.add(newCourseUnit);            }        }        System.out.println(courseUnits);        System.out.print(Please enter the number of Credit Units you will complete per term: );        Scanner ex = new Scanner(System.in);        int plannedUnits = 0;        if (ex.hasNextInt()) {            plannedUnits = ex.nextInt();        }        int sumOfCourseUnits = 0;        for (int courseUnit : courseUnits)         {            sum += courseUnit;        }        int unitsLeft = (sum - plannedUnits);        System.out.println(After this term there are  + unitsLeft +  credit units remaining.);        int termsLeft = (sumOfCourseUnits / plannedUnits);        System.out.println(You will complete your degree in  + termsLeft +  terms.);        final double TUITION_RATE = 2890;        double tuitionCost = (termsLeft * TUITION_RATE);        System.out.print(It will cost you  + tuitionCost +  to complete your degree.);    }}I see you writing int variableName = (something + someOtherThing);. Those parenthesis are not needed. Just write int variableName = something + someOtherThing;. Though of course having too many parenthesis doesn't hurt.System.out.print(ERROR! Please enter a number 1-9.: );Heh. You say 1-9 but you only check if it is negative. If 0 and 10 are not acceptable values, then use:if (temp < 1 || temp > 9) {sum / plannedUnits. This will round the result down. Is that what you want? For instance, if there are 20 units and you plan 6 units, you'll have 3 terms (not 4). My suggestion would be:int termsLeft = (int)Math.ceil((double)sum / plannedUnits);but I use explicit type casts here, and I suspect you might have not learned about those yet. So an alternative is:int termsLeft = sum / plannedUnits;if (sum % plannedUnits != 0) {   termsLeft++;}Aside from this, you have no comments and you are using just a single method -- but I don't know if you've learned what any of those words mean, so I'd rather not overwhelm you. It's okay for your work not to be perfect the first time.One warning, though:    if (ex.hasNextInt()) {        plannedUnits = ex.nextInt();    }What happens if the user does not input an integer (and instead writes regular text)? Will plannedUnits remain zero? If so, beware -- you'll be dividing by zero later on!UPDATE: You updated your code so it's only fair that I update my review.Your new version is much better than the first one.That said, you have missed one important piece of @Lstor's advice: Your Get functions have I/O.About unitsPerCourse: This is a weird name for a Scanner. I'd expect a number or maybe a Map for a variable with this name. This is not a variable that contains the unitsPerCourse, it's the variable that handles asking the user about unitsPerCourse.Also, in Java, it is common for method names to start with a lowercase letter, so GetPlannedUnits would be getPlannedUnits.The use of uppercase TUITION_RATE is very common for constants, but weird for function parameter names.final in parameters means the function is not allowed to change the value of the parameter -- but the code that uses the function can pass any value it wants. You never change the value of parameters anyway, so it doesn't make much sense to make TUITION_RATE one. I'd do one of the following:Change it to a normal parameter (tuitionRate in CalculateTuition, but keep it called TUITION_RATE in main);Remove the parameter and move TUITION_RATE to the CalculateTuition.Move CalculateTuition to the class level.This code could be simplifed:public static int CalculateUnitsLeft(int creditUnitsSum, int plannedUnits) {    int unitsLeft;    unitsLeft = creditUnitsSum - plannedUnits;    return unitsLeft;}Why separate the declaration of unitsLeft and its assignment? You can just do:int unitsLeft = creditUnitsSum - plannedUnits;In fact, we can do even better:public static int CalculateUnitsLeft(int creditUnitsSum, int plannedUnits) {    return creditUnitsSum - plannedUnits;}Finally, have you learned about exceptions yet? If not, then this won't make much sense to you, but if/when you do, the usual way to handle resources that must be closed is:Scanner unitsPerCourse = new Scanner(System.in);try {   //Your code here} finally {    unitsPerClose.close();}Newer versions of Java (Java 7) have a shorter version that does the same (called try-with-resources):try (Scanner unitsPerCourse = new Scanner(System.in) {    //Your code here}I hope this helps.