CS 261 Assignment #0 (Optional)

Try to finish by January 23rd

Introduction:

This first assignment will give you a chance to refresh your Java programming fundamentals, and get more practice writing clean, correct, well-documented code. Your task, to be completed individually, is to write a program that analyzes power-usage patterns of a freezer, based on a file containing power-consumption data points. The specifics are spelled out in the next section.

The Assignment

I've got a freezer that's been behaving mysteriously of late. It works just fine most the time, but every few months it trips the breaker and loses power. If we don't notice it in time, the freezer thaws out and we lose a bunch of food. I considered buying a new freezer, but they're expensive and I'm cheap, so I came up with a high-tech warning system instead: I have a program watching the power usage, and it sends me a text message if it doesn't see the freezer using power for a while.

Before coming up with the warning system, I needed to know if it was even feasible to tell if the freezer was working based on the power data I had available. How often does it run? How long does it run once it comes on? Could I tell the freezer's power consumption from other items on the same circuit? The graph below shows the power usage on the freezer's circuit on a recent afternoon as an example.

The tall spikes show when the freezer's using power. (The Y axis shows power in Watts, and it draws about 100 Watts when it's running.) It turns out there's only one other item on that circuit — some lights that, when turned on, use about 25 Watts. That's good news! Whether the lights are on or not, it's possible to detect the freezer running. (During the second peak the lights got turned on about 10 minutes after the freezer started running, and the lights were on already before the last two freezer runs shown.)

I've saved some data from the monitoring system, at one-minute intervals, and your job is to write a program that will report some basic stats on the freezer's power usage: How many minutes (on average) does it run each time it comes on? How many minutes are there between runs on average? And how much total power does it use over the monitored period?

Start by downloading and unzipping FreezerAsmt.zip. The project has a bit of starter code to help you get started. This project is short enough that it's fine with me if all of the code ends up in the main method, though you should feel free to break it into smaller pieces if you prefer. Note that the project folder also contains a file called data.txt holding a sample power-usage data file. Your finished program should prompt the user for the name of a data file, analyze the data in the file, then print a report. The output from my solution is shown below:

Please enter the filename to be analyzed 
data.txt
Thanks. Analyzing data in data.txt
Analyzed 2432 minutes of power data:
The freezer ran 36 times, for a total of 1.0466966716666664 kWh
The average run lasted 16.666666666666668 minutes
The average interval between runs was 50.888888888888886

Here are some more specific requirements:

The requirements ask that you report total power consumption in kiloWatt-hours. That's the standard unit for power consumption (the amount of power a 1000 Watt load would use in an hour), but will require a bit of math in our case. If the freezer ran for 15 minutes, and used 100 Watts during each of those minutes, that would be a total of 1500 Watt-minutes. You'll need to adjust that to convert from minutes to hours, then divide by 1000 to turn Watt-hours into kiloWatt-hours. I'll trust you can get the units to come out right, but feel free to ask for help if you're not sure what to do there.

Style Guide

Before you submit your assignment, go through the checklist below and make sure your code conforms to the style requirements. Feel free to define additional classes to help organize the project if you see fit. At the very least, you should define one or more methods to help with the computations, and call those methods from the body of the main method.

Grading

If it were being graded, this assignment would be graded out of a total of 60 points:

Extras

Looking for an extra challenge? Consider one or more of these optional extras. There's no extra credit, but they'd be good practice:

Submitting

If you want feedback, email me your FreezerAnalysis.java file and I'll take a look at it.


Brad Richards, 2023