From 67f880fe4426efa370aa57535eb5d666aa84270f Mon Sep 17 00:00:00 2001 From: Deathsbreed Date: Sat, 15 Nov 2014 15:21:38 -0600 Subject: [PATCH] CoffeeBreak will read a file and print its contents every 2 seconds. --- src/coffeebreak/CoffeeBreak.java | 94 +++++++++++++++++++------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/src/coffeebreak/CoffeeBreak.java b/src/coffeebreak/CoffeeBreak.java index 94f97c0..8a0834f 100644 --- a/src/coffeebreak/CoffeeBreak.java +++ b/src/coffeebreak/CoffeeBreak.java @@ -1,5 +1,10 @@ package coffeebreak; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.FileNotFoundException; +import java.io.FileReader; + /** * @author Nicolás A. Ortega * @copyright Nicolás A. Ortega @@ -10,50 +15,65 @@ package coffeebreak; * */ public class CoffeeBreak { - public static final String usage = "Usage: coffeebreak [compiler]"; - public String[] compilers = {"gcc", "g++", "clang++", "javac", "ant"}; + private static final String version = "v0.1"; + private static final String usage = "Usage: coffeebreak [-h | --help | -v | -c | -w | -f ]"; - public CoffeeBreak(String compiler) { - int compid = -1; - compilerLoop: - for(int i = 0; i < compilers.length; i++) { - if(compiler.equals(compilers[i])) { - compid = i; - break compilerLoop; + // Constructor: + public CoffeeBreak(String filepath) { + String line; + while(true) { + try { + BufferedReader br = new BufferedReader(new FileReader(filepath)); + try { + while((line = br.readLine()) != null) { + System.out.println(line); + try { + Thread.sleep(2000); + } catch(InterruptedException e) { System.out.println("Error waiting."); } + } + br.close(); + } catch(IOException e) { + System.out.println("Error with reading from file."); + System.exit(1); + } + } catch(FileNotFoundException e) { + System.out.println("Cannot find file."); + System.exit(1); } } - if(compid == -1) { - System.out.println("This compiler is not supported. Add it!!!"); - return; - } - System.out.println("You chose compiler " + compiler); - } - - public void compileGCC() { - - } - - public void compileGXX() { - - } - - public void compileCLANGXX() { - - } - - public void compileJAVAC() { - - } - - public void compileANT() { - } + // Main: public static void main(String[] args) { - if(args.length != 1) { - System.out.println("Invalid number of arguments.\n" + usage); + if(args.length == 2) { + if(args[0].equals("-f")) new CoffeeBreak(args[1]); + else System.out.println("Invalid argument '" + args[0] + "'.\n" + usage); + } else if(args.length == 1) { + if(args[0].equals("-h") || args[0].equals("--help")) printHelpInfo(); + else if(args[0].equals("-v")) System.out.println("CoffeeBreak " + version); + else if(args[0].equals("-c")) printCopyrightInfo(); + else if(args[0].equals("-w")) printWarrantyInfo(); + else System.out.println("Invalid argument '" + args[0] + "'.\n" + usage); + } else { + System.out.println("Invalid number of arguments."); return; } - new CoffeeBreak(args[0]); + } + + private static void printHelpInfo() { + System.out.println(usage + + "\n -h or --help -- Print this help information." + + "\n -v -- Print version." + + "\n -c -- Print copyright information." + + "\n -w -- Print warranty information." + + "\n -f -- File to read from."); + } + + private static void printCopyrightInfo() { + // TODO + } + + private static void printWarrantyInfo() { + // TODO } }