Sahil-Pattni
10/17/2016 - 6:36 AM

FAFSA GUI

FAFSA GUI

import jdk.nashorn.internal.scripts.JO;

import javax.swing.*;

/**
 * Created by Sahil Pattni on 16-Oct-16.
 */
public class FAFSAGUI {

    public static void main(String[] args) {
        // Three basic requirements
        boolean isAcceptedStudent;
        boolean isSSregistered;
        boolean hasSSN;

        // One of four required
        boolean hasValidResidency;

        // Student demographics
        boolean isDependent;
        int age = -1;
        int creditHours = 1;
        double studentIncome = 1;
        double parentIncome = 1;
        String classStanding = "x";

        //While loop boolean list
        boolean isOld = false;
        boolean isCredible = false;
        boolean isWorthSomething = false;
        boolean parentsWorthSomething = false;

        //While not done, keep running
        boolean isDone = false;

        while (!isDone) {
            JOptionPane.showMessageDialog(null, "Welcome to FAFSA!", "Welcome", JOptionPane.INFORMATION_MESSAGE);

            //Basic Requirements
            int collegeAccept = JOptionPane.showConfirmDialog(null, "Have you been accepted into a degree or certificate program", "Program Acceptace", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            isAcceptedStudent = collegeAccept != 1;

            int SS= JOptionPane.showConfirmDialog(null, "Are you registered for the selective service?", "Program Acceptance", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            isSSregistered = SS != 1;

            int SSN = JOptionPane.showConfirmDialog(null, "Do yuo have a social security number?", "Social Security Number", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            hasSSN = SSN != 1;

            int residency = JOptionPane.showConfirmDialog(null, "Do you have valid residency status?", "Residency Status", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            hasValidResidency = residency != 1;

            while (!isOld) {
                age = Integer.parseInt(JOptionPane.showInputDialog(null, "How old are you?", "Age", JOptionPane.QUESTION_MESSAGE));
                if (age < 0) {
                    JOptionPane.showMessageDialog(null, "Age cannot be a negative number", "Error: Age", JOptionPane.ERROR_MESSAGE);
                }
                else {
                    isOld = true;
                }
            }

            isOld = false;

            while (!isCredible) {
                creditHours = Integer.parseInt(JOptionPane.showInputDialog(null, "How many credit hours do you plan on taking", "Credit Hours", JOptionPane.QUESTION_MESSAGE));
                if (creditHours < 1 || creditHours > 24) {
                    JOptionPane.showMessageDialog(null, "Credit hours must be between 1 and 24, inclusive", "Error: Credit Hours", JOptionPane.ERROR_MESSAGE);
                }

                else isCredible = true;
            }

            isCredible = false;

            while (!isWorthSomething) {
                studentIncome = Integer.parseInt(JOptionPane.showInputDialog(null, "What is your total yearly income", "Student Income", JOptionPane.QUESTION_MESSAGE));
                if (studentIncome < 0) {
                    JOptionPane.showMessageDialog(null, "Income cannot be a negative number", "Error: Student Income", JOptionPane.ERROR_MESSAGE);
                }

                else isWorthSomething = true;
            }

            isWorthSomething = false;

            while (!parentsWorthSomething) {
                parentIncome = Integer.parseInt(JOptionPane.showInputDialog(null, "What is your parent's total yearly income?", "Parents Income", JOptionPane.QUESTION_MESSAGE));
                if (parentIncome < 0) {
                    JOptionPane.showMessageDialog(null, "Income cannot be a negative number", "Error: Parents Income", JOptionPane.ERROR_MESSAGE);
                }

                else parentsWorthSomething = true;
            }

            parentsWorthSomething = false;

            int indie = JOptionPane.showConfirmDialog(null, "Are you a dependant", "Dependancy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            isDependent = indie != 1;

            String [] classChoice = {"Freshman", "Sophomore", "Junior", "Senior", "Graduate"};
            Object collegeYear = JOptionPane.showInputDialog(null, "What is your current class standing", "Class Standing", JOptionPane.PLAIN_MESSAGE, null, classChoice, classChoice[1]);
            if (!(collegeYear.equals("Graduate"))) {
                classStanding = "Undergraduate";
            }
            else if (collegeYear.equals("Graduate")){
                classStanding = "Graduate";
            }

            FAFSA student = new FAFSA(isAcceptedStudent, isSSregistered, hasSSN, hasValidResidency, isDependent, age, creditHours, studentIncome, parentIncome, classStanding);

            String family_contribution = "" + student.calcEFC();
            String loan = "Stafford Loan amount : $" + student.calcStaffordLoan();
            String grant = "Federal Grant: $" + student.calcFederalGrant();
            String work_study = "Work/Study: $" + student.calcWorkStudy();
            String eligible = "Not initialized";
            if (student.isFederalAidEligible()) {
                eligible = "Federal Aid: $" + student.calcFederalAidAmount();
            }
            else eligible = "Federal Aid: Ineligible";

            double total_aid = student.calcFederalAidAmount() + student.calcWorkStudy() + student.calcStaffordLoan() + student.calcFederalGrant();

            String lines = "--------------------------------";

            String results = eligible + "\n" + loan + "\n" + grant + "\n" + work_study + "\n" + lines + "\n" +
                    "Total Aid: $" + total_aid + "\n" + "Your contribution: $" + family_contribution;

            JOptionPane.showMessageDialog(null, results, "FAFSA Results", JOptionPane.INFORMATION_MESSAGE);

            int done = JOptionPane.showConfirmDialog(null, "Would you like to complete another Application?", "Continue", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

            if (done == 1) {
                isDone = true;
            }

        }
    }
}