Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Budgeter {
- public static final int DAYS_MONTH = 31;
- public static void main(String[] args) {
- beginningPart();
- double totalIncome = income();
- expenses(totalIncome);
- }
- public static void beginningPart() {
- System.out.println("This program asks for your monthly income and");
- System.out.println("expenses, then tells you your net monthly income.");
- System.out.println();
- }
- public static double income() {
- Scanner input = new Scanner(System.in);
- System.out.print("How many categories of income? ");
- int categories = input.nextInt();
- double sum = 0;
- for(int i = 1; i <= categories; i++) {
- System.out.print("Next income amount? ");
- Scanner x = new Scanner(System.in);
- double test = x.nextDouble();
- sum += test;
- }
- return sum;
- }
- public static void expenses(double x) {
- System.out.print("Enter 1) monthly or 2) daily expenses? ");
- Scanner y = new Scanner(System.in);
- int expenses = y.nextInt();
- System.out.print("How many categories of expense? ");
- Scanner d = new Scanner(System.in);
- int categories = d.nextInt();
- double sumMonthly = 0;
- double sumDaily = 0;
- if (expenses == 1) {
- for(int i = 1; i <= categories; i++) {
- System.out.print("Next income amount? ");
- Scanner z = new Scanner(System.in);
- double monthly = z.nextDouble();
- sumMonthly += monthly;
- }
- calcMonth(sumMonthly, x);
- } else {
- for(int i = 1; i <= categories; i++) {
- System.out.print("Next income amount? ");
- Scanner j = new Scanner(System.in);
- double daily = j.nextDouble();
- sumDaily += daily;
- }
- calcDaily(sumDaily, x);
- }
- }
- public static void calcDaily(double expensesDaily, double income) {
- double sumDaily = expensesDaily;
- double newSum = 0;
- newSum = sumDaily * DAYS_MONTH;
- System.out.printf("Total income = $%.2f", income);
- System.out.printf(" ($%.2f/day) \n", (income / DAYS_MONTH));
- System.out.printf("Total expenses = $%.2f ($%.2f/day)", newSum, expensesDaily);
- double totalEarned = income - newSum;
- if (totalEarned >= 250) {
- System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
- System.out.println("Big Saver");
- } else if (totalEarned < 0 && totalEarned >= 250) {
- System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
- System.out.println("Saver");
- } else if (totalEarned <= 0 && totalEarned > -250) {
- totalEarned *= -1;
- System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
- System.out.println("Spender!!");
- } else if (totalEarned < -250) {
- totalEarned *= -1;
- System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
- System.out.println("Big Spender!!");
- }
- }
- public static void calcMonth(double expensesMonthly, double income) {
- double sumMonthly = expensesMonthly;
- double newSum = 0;
- newSum = sumMonthly / DAYS_MONTH;
- System.out.printf("Total income = $%.2f", income);
- System.out.printf(" ($%.2f/day) \n", (income / DAYS_MONTH));
- System.out.printf("Total expenses = $%.2f ($%.2f/day)", expensesMonthly, newSum);
- double totalEarned = income - expensesMonthly;
- if (totalEarned >= 250) {
- System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
- System.out.println("Big Saver");
- } else if (totalEarned < 0 && totalEarned >= 250) {
- System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
- System.out.println("Saver");
- } else if (totalEarned <= 0 && totalEarned > -250) {
- totalEarned *= -1;
- System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
- System.out.println("Spender!!");
- } else if (totalEarned < -250) {
- totalEarned *= -1;
- System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
- System.out.println("Big Spender!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement