Last active
September 5, 2017 12:42
-
-
Save rbrady/b40706883df366d11be9ec4b12df6efd to your computer and use it in GitHub Desktop.
Example java class for Mike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.Scanner; | |
public class Unit3 { | |
private static final String FILENAME = "energyProduced.txt"; | |
private static final double ELECTRICITY_COST = 0.85; | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
System.out.print("Total System Cost: "); | |
double num1 = scan.nextDouble(); | |
BufferedReader br = null; | |
FileReader fr = null; | |
try { | |
//br = new BufferedReader(new FileReader(FILENAME)); | |
fr = new FileReader(FILENAME); | |
br = new BufferedReader(fr); | |
String sCurrentLine; | |
while ((sCurrentLine = br.readLine()) != null) { | |
// process data from the file, one line at a time | |
System.out.println(sCurrentLine); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
if (br != null) | |
br.close(); | |
if (fr != null) | |
fr.close(); | |
} catch (IOException ex) { | |
ex.printStackTrace(); | |
} | |
} | |
System.out.println("Total System Cost: " + num1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment