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

This Intellij JAVA A heating utility company allows customers to spread the cost

ID: 3781709 • Letter: T

Question

This Intellij JAVA

A heating utility company allows customers to spread the cost of bills through the year by charging them an average payment every month.

The utility company averages all of the last year's bills, and uses that to estimate the average payment for next year.

Ask the user for each month's bill for last year.

Store this data in an array.

Store January's bill in element 0, February's in element 1…

Then, add up all of the bills and figure out the average; the average of all of the bills in one year will become next year’s monthly payment.

Also, display the user's data in a table of months and bill amount, so they can review it for accuracy.

Tip: use another array with the names of the months to help ask for data/display data. You can copy/paste this:

String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };

Explanation / Answer

package snippet;

import java.util.Scanner;

public class Bill {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
       int[] bill=new int[12];//Array to hold bill of each month
       Scanner sc=new Scanner(System.in);//create scanner object
      
       int sum=0;
       float avg=0;
      
       for(int i=0;i<12;i++)
       {
           System.out.println("Enter payment for month "+months[i]);
           bill[i]=sc.nextInt();//accept payment
           sum+=bill[i];//add it to sum
       }
      
       //display table
       System.out.println("Month Payment");
       for(int i=0;i<12;i++)
       {
           System.out.println(months[i]+" "+bill[i]);
          
       }
       //calculate average
       avg=sum/12;
       System.out.println("Total Payment "+sum);
       System.out.println("Average Payment "+avg);
      

   }

}

======================================================

Output:

Enter payment for month January
10
Enter payment for month February
20
Enter payment for month March
30
Enter payment for month April
40
Enter payment for month May
50
Enter payment for month June
60
Enter payment for month July
70
Enter payment for month August
80
Enter payment for month September
90
Enter payment for month October
100
Enter payment for month November
110
Enter payment for month December
120
Month   Payment
January   10
February   20
March   30
April   40
May   50
June   60
July   70
August   80
September   90
October   100
November   110
December   120
Total Payment   780
Average Payment   65.0

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