Skip to content
Permalink
Browse files
initial code
  • Loading branch information
esteves2 committed Apr 7, 2021
0 parents commit 1da64b1c06f72ed92ee8d4cd699d82231ed9910e
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 0 deletions.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
@@ -0,0 +1,100 @@
package project;

import javax.swing.*;
import java.io.*;
import java.util.Scanner;

public class Data {

protected String year;
protected String totalEnergySupply;
protected String business;
protected String transport;
protected String pub;
protected String residential;
protected String agriculture;
protected String industrial;
protected String waste;
protected String totalCO2;
protected String otherGases;
protected String totalGHG;

//constructor
public Data(String year, String totalEnergySupply, String business, String transport,
String pub, String residential, String agriculture, String industrial,
String waste, String totalCO2, String otherGases, String totalGHG) {

this.year = year;
this.totalEnergySupply = totalEnergySupply;
this.business = business;
this.transport = transport;
this.pub = pub;
this.residential = residential;
this.agriculture = agriculture;
this.industrial = industrial;
this.waste = waste;
this.totalCO2 = totalCO2;
this.otherGases = otherGases;
this.totalGHG = totalGHG;
}

//method for reading info on .txt file
public static void readData(String searchTerm, String filepath) {

boolean found = false;
String year = "";
String totalEnergySupply = "";
String business = "";
String transport = "";
String pub = "";
String residential = "";
String agriculture = "";
String industrial = "";
String waste = "";
String totalCO2 = "";
String otherGases = "";
String totalGHG = "";

try {

Scanner x = new Scanner(new File(filepath));
x.useDelimiter("[,\n]");

while (x.hasNextLine() && !found) {
year = x.next();
totalEnergySupply = x.next();
business = x.next();
transport = x.next();
pub = x.next();
residential = x.next();
agriculture = x.next();
industrial = x.next();
waste = x.next();
totalCO2 = x.next();
otherGases = x.next();
totalGHG = x.next();

if (year.equals(searchTerm)) {

found = true;
}
}

if (found) { //if date equals name on .txt line print info from that line on the pop-up window

JOptionPane.showMessageDialog(null, "Year: " + year + ", " + "Energy Supply: " + totalEnergySupply + ", " + "Business: " +
business + ", " + "Transport: " + transport + ", " + "Public Sector: " + pub + ", " + "Residential: " + residential + ", " + "Agriculture: " + agriculture + ", " +
"Industrial: " + industrial + ", " + "Waste: " + waste + ", " + "Total CO2: " + totalCO2 + ", " + "Other Gases: " + otherGases + ", " + "Total GHG: " + totalGHG);

} else { //if no name equals search term

JOptionPane.showMessageDialog(null, "Not found");

}

} catch (Exception e) {

JOptionPane.showMessageDialog(null, "Operation Failed");
}
}
}

0 comments on commit 1da64b1

Please sign in to comment.