Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Budgeter {
  4.  
  5. public static final int DAYS_MONTH = 31;
  6.  
  7. public static void main(String[] args) {
  8. beginningPart();
  9. double totalIncome = income();
  10. expenses(totalIncome);
  11.  
  12. }
  13. public static void beginningPart() {
  14. System.out.println("This program asks for your monthly income and");
  15. System.out.println("expenses, then tells you your net monthly income.");
  16. System.out.println();
  17.  
  18. }
  19. public static double income() {
  20. Scanner input = new Scanner(System.in);
  21. System.out.print("How many categories of income? ");
  22. int categories = input.nextInt();
  23. double sum = 0;
  24. for(int i = 1; i <= categories; i++) {
  25. System.out.print("Next income amount? ");
  26. Scanner x = new Scanner(System.in);
  27. double test = x.nextDouble();
  28. sum += test;
  29. }
  30. return sum;
  31. }
  32. public static void expenses(double x) {
  33. System.out.print("Enter 1) monthly or 2) daily expenses? ");
  34. Scanner y = new Scanner(System.in);
  35. int expenses = y.nextInt();
  36. System.out.print("How many categories of expense? ");
  37. Scanner d = new Scanner(System.in);
  38. int categories = d.nextInt();
  39. double sumMonthly = 0;
  40. double sumDaily = 0;
  41. if (expenses == 1) {
  42. for(int i = 1; i <= categories; i++) {
  43. System.out.print("Next income amount? ");
  44. Scanner z = new Scanner(System.in);
  45. double monthly = z.nextDouble();
  46. sumMonthly += monthly;
  47. }
  48. calcMonth(sumMonthly, x);
  49. } else {
  50. for(int i = 1; i <= categories; i++) {
  51. System.out.print("Next income amount? ");
  52. Scanner j = new Scanner(System.in);
  53. double daily = j.nextDouble();
  54. sumDaily += daily;
  55. }
  56. calcDaily(sumDaily, x);
  57. }
  58. }
  59. public static void calcDaily(double expensesDaily, double income) {
  60. double sumDaily = expensesDaily;
  61. double newSum = 0;
  62. newSum = sumDaily * DAYS_MONTH;
  63. System.out.printf("Total income = $%.2f", income);
  64. System.out.printf(" ($%.2f/day) \n", (income / DAYS_MONTH));
  65. System.out.printf("Total expenses = $%.2f ($%.2f/day)", newSum, expensesDaily);
  66.  
  67. double totalEarned = income - newSum;
  68. if (totalEarned >= 250) {
  69. System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
  70. System.out.println("Big Saver");
  71. } else if (totalEarned < 0 && totalEarned >= 250) {
  72. System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
  73. System.out.println("Saver");
  74. } else if (totalEarned <= 0 && totalEarned > -250) {
  75. totalEarned *= -1;
  76. System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
  77. System.out.println("Spender!!");
  78. } else if (totalEarned < -250) {
  79. totalEarned *= -1;
  80. System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
  81. System.out.println("Big Spender!!");
  82. }
  83. }
  84. public static void calcMonth(double expensesMonthly, double income) {
  85. double sumMonthly = expensesMonthly;
  86. double newSum = 0;
  87. newSum = sumMonthly / DAYS_MONTH;
  88. System.out.printf("Total income = $%.2f", income);
  89. System.out.printf(" ($%.2f/day) \n", (income / DAYS_MONTH));
  90. System.out.printf("Total expenses = $%.2f ($%.2f/day)", expensesMonthly, newSum);
  91.  
  92. double totalEarned = income - expensesMonthly;
  93. if (totalEarned >= 250) {
  94. System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
  95. System.out.println("Big Saver");
  96. } else if (totalEarned < 0 && totalEarned >= 250) {
  97. System.out.printf("You earned $%.2f more than you spent this month.", totalEarned);
  98. System.out.println("Saver");
  99. } else if (totalEarned <= 0 && totalEarned > -250) {
  100. totalEarned *= -1;
  101. System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
  102. System.out.println("Spender!!");
  103. } else if (totalEarned < -250) {
  104. totalEarned *= -1;
  105. System.out.printf("You spent $%.2f more than you earned this month.", totalEarned);
  106. System.out.println("Big Spender!!");
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement