Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program SpendingLog.java that performs the following. Ask user to enter

ID: 3802433 • Letter: W

Question

Write a program SpendingLog.java that performs the following. Ask user to enter daily spending amount for the week. (Day 1, Monday, through day 7, Sunday). Save the numbers in an array. Calculate the total, the average spending for the week. Print the results of total and average spending. Count the number of days that the spending is less than the average. Print it out. Print out the highest spending day. Sample output: Enter spending on day 1:12.0 Enter spending on day 2: 65.0 Enter spending on day 3: 8.0 Enter spending on day 4: 5.0 Enter spending on day 5:15.0 Enter spending on day 6: 80.0 Enter spending on day 7: 20.0 Total spending: $205 Average: $29.29/day #of days below average spending: 5 Highest spending day: Saturday

Explanation / Answer


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Surya
*/
public class SpendingLog {
  
    public static void main(String argv[])
    {
      
        int i,max=0;//varible declarations
        String week[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
        double spendings[]=new double[7],total=0,average=0;
      
      
        Scanner sc = new Scanner(System.in);
        i=1;
        //taking user input..
        while(i<=7)
        {
            System.out.print("Enter speneding on day"+i+" :");//prompting input
            spendings[i-1]=sc.nextDouble();//reading input...
            if(spendings[max]<spendings[i-1])max=i-1;//updating max spendings
            total =total+spendings[i-1];//calculating total spendings
            i++;
          
        }
        average =total/7;//calculating average spendings
      
      
      
        int count=0;//variable to count number of days below spending average
        i=0;
        while(i<7)
        {
            if(spendings[i]<average)
                count++;
            i++;
        }
  
        //printing output...
        System.out.println("Total spending:"+total);
         System.out.println("Average spending:"+Math.round(average*100.0)/100.0+"/day");
          System.out.println("#of days below average spending:"+count);
           System.out.println("Highest spending day:"+week[max]);
      
    }
  
}

output:-

run:
Enter speneding on day1 :12
Enter speneding on day2 :65
Enter speneding on day3 :8
Enter speneding on day4 :5
Enter speneding on day5 :15
Enter speneding on day6 :80
Enter speneding on day7 :20
Total spending:205.0
Average spending:29.29/day
#of days below average spending:5
Highest spending day:Saturday
BUILD SUCCESSFUL (total time: 17 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote