Annual Fuel Use
- Yahvin Gali
- Jan 11, 2021
- 3 min read
To display fill-up data recorded for a car, as well as the annual projected fuel use calculated from several variables.
The past few decades have been riddled with debates and environmental resolutions over the use of fossil fuels. This project serves the purpose of learning about arrays of objects, all while understanding a person's Carbon Footprint.
By learning about your CO2 footprint, you take steps to minimize your production of GHGs, thus saving the environment. And what better way to do so, than learning with CS?
The Nature of Fossil Fuels
Fossil Fuels are products of a process that began in Archean Eon (4 billion to 2.5 billion years ago) that involve geological processes acting upon organic matter from photosynthesis. They include coal, petroleum, natural gas, oil shales (sedimentary rock rich in kerogen), bitumens (produced from distillation of crude oil; asphalt) , tar sands (mixture of sand, clay, water, and bitumens), and heavy oils. All of these substances, when ignited, produce greenhouse gases (GHGs) that contribute to the "Greenhouse Effect" of the Earth's atmosphere, a phenomenon that results in the rise of global temperatures. The consequences of rising global temperatures, if the production of GHGs continues, will endanger all life on Earth, let alone just humanity. Now that the nature of fossil fuels has been addressed, it's time to dive into the code!
Monitoring Fuel Use
In order to design a program that would calculate the Annual Fuel Usage of a gasoline consuming automobile, I utilized automobile data collected by my Computer Science teacher. The data, collected over a period of 10 days, included the miles at the beginning and end of each day, the total gallons of fossil fuels consumed, and the price per gallon.
Methods and Arrays
This projects contains two files, the method class, AnnualFuelUse, and the Tester class, AnnualFuelUseTester. From now on, I will be to the files as method class and tester class, respectively.
The method class contains several core methods inherent to objects of type AnnualFuelUse. In layman's terms, anytime that I want to calculate something concerning an automobile, I will be using a method, which contains certain "formulae" for calculations, from the method class. For example, one such method is the calcDistance() method, which calculates the distance traveled by the automobile.
public int calcDistance()
{
dist1 = eMiles1 - sMiles1;
return dist1;
}
Other methods include getter and setter methods, which
Getter: get already present values of start/end miles, gallons used, and price per gallon.
Setter: set values to the variables in the program.
and even methods that calculate Miles per Gallon (mpg), Gallons per Mile (gpm), and the total cost (ppg * gallonsUsed).
All of these methods are utilized in the tester class, which inputs the collected automobile data as arguments for the methods. When the code is run, the methods produce values that can be stored, printed, or used for other calculations. The tester class also contains the unique feature of parsing through the entire dataset (via an array of objects) in order to display the minimum and maximum number of driven miles in a day, as well as the min and max mpg and min and max prices of gallons. The entire dataset is stored within the array of type AnnualFuelUse simply called "data". The entire project can be accessed here, on the Github page.
Final Thoughts
While this project was not particularly entertaining, it was fun learning about how to simplify performing calculations on a dataset - an array of objects. I did have quite a few difficulties utilizing the print format inherent java method, as the configuration of the method takes some getting used to. Nontheless, the project was a success!
Comments