Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help. Access starter source file Billsummary . java and data file energy . txt . The file framework is started for you but the

Please help. Access starter source file Billsummary . java and data file energy . txt. The file
framework is started for you but the file loop, array processing, calculations, and output are
yet to go.
Write a program that summarizes the energy bill for this home. You are provided a data file
containing the month, year, and energy usage for a given month for a three-year period. The
information is randomized. Some example data in the file:
12,2021,1200
7,2023,1490
10,2021,862
,:
Use the method created above to calculate the energy cost for a given month. Then,
summarize the average energy cost per month for that three-year period. Your output could
looks something like:
Be sure to format the resulting dollar amounts to two decimal places.
import java.io.*;
import java.util.Scanner;
public class BillSummary
{
static final String FILENAME = "energy.txt";
public static void main(String[] args)
{
// Start file processing
try
{
String filename = FILENAME;
File dataFileRef = new File(filename);
// Check for file existence. If not found, display error and crash
if (!dataFileRef.exists())
{
System.out.println("File not found");
System.exit(0);
}
Scanner inputFile = new Scanner(dataFileRef);
// File processing loop.
}
catch (IOException e)// If file error, display message and crash
{
System.out.println("File error");
System.exit(0);
}
}
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is an impairment test? What is its purpose?

Answered: 1 week ago