Skip to content

Instantly share code, notes, and snippets.

@rbrady
Last active September 5, 2017 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbrady/b40706883df366d11be9ec4b12df6efd to your computer and use it in GitHub Desktop.
Save rbrady/b40706883df366d11be9ec4b12df6efd to your computer and use it in GitHub Desktop.
Example java class for Mike
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