Student Budget Calculator – Java Program

What it does:

A program which asks a list of questions to allow it to calculate how much money the student will have to spend each week. It begins by asking the user to enter how many weeks they will be attending university to allow it to see how long the funds are meant to last. The user will then enter the funds they are expected to receive for the year.  The program will give them a print out of approximately they have to spend each week. It will then ask the user how much they attend to spend on essential items. Once the essential items have been taken off if there if anything left it will ask the user to enter how much they would like to spend on other costs. At the end of the program it will print out how much the user has left at the end of the week from their budget.

Code:

 

public class CalculatingStudentBudget
{
    private static Scanner keyboard = new Scanner(System.in);
    private static DecimalFormat df = new DecimalFormat("##.#");
    private static double weeksInAttendance;
    private static double income()
    {
        double studentLoan, grantsETC, parentsGuardians, job, savings, anyOther,totalIncome;

        System.out.println("INCOME section");

        System.out.println("Please enter your student loan amount, if any.");
        studentLoan = keyboard.nextDouble();

        System.out.println("Please enter the amount you expect to receive in grants, bursaries or sponsorship");
        grantsETC = keyboard.nextDouble();

        System.out.println("Please enter the amount, if any you expect to receive for parents/guardians");
        parentsGuardians = keyboard.nextDouble();

        System.out.println("Please enter the of income you receive from your job, if you have one");
        job = keyboard.nextDouble();

        System.out.println("Please enter the amount of savings you wish to spend, if any");
        savings = keyboard.nextDouble();

        System.out.println("Please enter any other income you may have");
        anyOther = keyboard.nextDouble();

        //totalling up the income
        totalIncome = studentLoan+grantsETC+parentsGuardians+job+savings+anyOther;

        return totalIncome;
    }//income

    private static double essentialOutgoing()
    {
        double totalEssentialOutgoing, rent, travel, insurance, carBills, utilityBills, mobilePhone, tvLicence, food;

        System.out.println("ESSENTIAL COSTS");

        System.out.print(" ");

        System.out.println("Please enter the amount of rent you will pay per week");
        rent = keyboard.nextDouble();

        System.out.println("Please enter the amount of travel costs per week");
        travel = keyboard.nextDouble();

        System.out.println("If you have insurance, please enter the total cost per week");
        insurance =keyboard.nextDouble();

        System.out.println("If a car, please enter the total expected cost for fuel, repairs etc, per week");
        carBills = keyboard.nextDouble();

        System.out.println("Please enter the amount you expect to spend on utility bills per week. This would include " +
                           "gas, electric, oil, etc. Per week");
        utilityBills = keyboard.nextDouble();

        System.out.println("Please enter the amount you expect to spend on you mobile phone per week");
        mobilePhone = keyboard.nextDouble();

        System.out.println("If you have a TV licence, please enter the total amount per week");
        tvLicence = keyboard.nextDouble();

        System.out.println("Please enter how much you expect to spend on groceries per week");
        food = keyboard.nextDouble();

        //calculation
        totalEssentialOutgoing = rent + travel +  food +
        utilityBills + mobilePhone + tvLicence + insurance
        + carBills;

        return totalEssentialOutgoing;
    }//essentialOutgoing()

    private static double otherCosts()
    {
        double totalOtherCosts, courseMaterial, clothing, socialActivities;

        System.out.println("OTHER COSTS");

        System.out.print(" ");

        System.out.println("Please enter how much your would like to spend on course material per week");
        courseMaterial = keyboard.nextDouble();

        System.out.println("Please enter how much you would like to spend on clothing per week");
        clothing = keyboard.nextDouble();

        System.out.println("Please enter how much you would like to spend on social activities per week");
        socialActivities = keyboard.nextDouble();

        totalOtherCosts = socialActivities + courseMaterial + clothing;

        return totalOtherCosts;
    }//otherCosts()


    public static void main(String[] args)
    {
        double theTotalIncome=0, theTotalEssentialOutgoing, theTotalOtherCosts, budget1, budget2, totalEachWeek;

        System.out.println("Welcome to the Student budget calculator!");
        System.out.println("If any of the questions you do not receive anything, please enter 0");

        System.out.println("Please enter the amount of weeks you expect to attend university");
        System.out.println("For example, the average university the autumn and spring semesters run for 36 weeks " +
                "including holidays");
        weeksInAttendance = keyboard.nextDouble();

        //calling income method
        theTotalIncome = income();

        System.out.println("Your income for the year is £" + df.format(theTotalIncome));
        totalEachWeek = theTotalIncome/weeksInAttendance;

        System.out.println("You have £" + df.format(totalEachWeek) + " to spend");

        //calling ess outgoing method
        theTotalEssentialOutgoing = essentialOutgoing();

        //calculation
        budget1 = totalEachWeek-theTotalEssentialOutgoing;
        System.out.println("You have spent £" + df.format(theTotalEssentialOutgoing));
        System.out.println("The amount left after the essentials £" + df.format(budget1));

        //calling other costs method
        theTotalOtherCosts = otherCosts();

        budget2 = budget1 - theTotalOtherCosts;

        System.out.println("You have spent £" + df.format(theTotalOtherCosts) + " for other costs");

        System.out.println("You have £" + df.format(budget2) + " at the end of the week");

    }//main
}//class

3 thoughts on “Student Budget Calculator – Java Program

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s