diff --git a/src/lab15_oop/15-oop-online-reportFR.pdf b/src/lab15_oop/15-oop-online-reportFR.pdf deleted file mode 100644 index f87f962..0000000 Binary files a/src/lab15_oop/15-oop-online-reportFR.pdf and /dev/null differ diff --git a/src/lab15_oop/BankController.java b/src/lab15_oop/BankController.java deleted file mode 100644 index cffb0ef..0000000 --- a/src/lab15_oop/BankController.java +++ /dev/null @@ -1,81 +0,0 @@ -package labs.lab15_oop.bank; - -import hevs.utils.DateUtils; - -/** - * Simple bank account control class for lab 15 - * @author @author Pierre-André Mudry - */ -public class BankController { - - public BankController() { - /** - * Verify that checks are done correctly - * in constructor - */ - Checking c1; - - System.out.print("3 Should trigger error : minbalance positive\n\t"); - c1 = new Checking("Toto", 1000, 1000); - - System.out.print("4 Should trigger error : Amount < min and min < 0\n\t"); - c1 = new Checking("Toto", -2000, -1000); - - /** - * Functional tests that are asserted - */ - // Set a positive limit (impossible) - System.out.print("6 Should trigger error : minbalance positive\n\t"); - c1 = new Checking("Test", 1000, -1000); - c1.setMinBalance(10000.0); - - /** - * Savings account checks - */ - Savings s1; - - System.out.print("9 Should trigger error : abnormal init of savings\n\t"); - s1 = new Savings("Toto", 1000, -3.0); - - // Deposit of negative value - System.out.print("11 Should trigger error : negative deposit \n\t"); - s1 = new Savings("Test", 1000, 1.0); - s1.deposit(-100.0); - assert s1.getBalance() == 1000.0; - - // Withdrawing more than possible - System.out.print("12 Should trigger error : taking more than available\n\t"); - s1 = new Savings("Test", 1000, 1.0); - s1.withdraw(3000); - assert s1.balance == 1000 : s1.balance; - - // Interest computation check and normal operations checks - System.out.println("13 Should not trigger error : interest check and normal operations"); - s1 = new Savings("Test", 1000, 0.032); - s1.withdraw(20.0); - assert s1.balance == (1000 - 20.0); - s1.withdraw(100.0); - assert s1.balance == 1000 - 20.0 - 100.0; - s1.deposit(120.0); - assert s1.balance == 1000.0; - double interest = s1.calcInterest(DateUtils.createDate("1/1/2011"), DateUtils.createDate("11/1/2011")); - - // Manual check of interest - assert interest == ((1000.0 * 10 * 3.2 / 100) / 360.0); - } - - /** - * @param args - */ - public static void main(String[] args) throws RuntimeException{ - boolean assertionsAreEnabled = false; - assert (assertionsAreEnabled = true); - - if (!assertionsAreEnabled) { - throw new RuntimeException( "Assertions must be enabled ! Add -ea to the VM arguments " + - "(Run Configuration menu in Eclipse)" ); - } - - new BankController(); - } -} diff --git a/src/lab15_oop/GarageManager.java b/src/lab15_oop/GarageManager.java deleted file mode 100644 index 8be113c..0000000 --- a/src/lab15_oop/GarageManager.java +++ /dev/null @@ -1,191 +0,0 @@ -package labs.lab15_oop.BillGUI; - -import java.io.FileOutputStream; -import java.io.PrintWriter; -import java.util.LinkedHashMap; -import java.util.Vector; - - -/** - * A sample garage application - * @author Pierre-André Mudry, HES-SO Valais 2010-2016 - */ -public class GarageManager { - private LinkedHashMap services = new LinkedHashMap(); - - - GarageManager() { - // The various services provided in this garage - services.put("Oil level control", 20); - services.put("Tire replacement ", 50); - services.put("Windshield exchange", 60); - services.put("Oil filter change", 210); - services.put("Battery replacement", 320); - services.put("Pollution control", 200); - services.put("Brake revision", 400); - } - - - String[] getServices() { - return services.keySet().toArray(new String[services.size()]); - } - - - int[] vectorToArray(Vector prestations) { - Integer[] v = prestations.toArray(new Integer[prestations.size()]); - int[] array = new int[v.length]; - - - for (int i = 0; i < v.length; i++) - array[i] = v[i].intValue(); - - - return array; - } - - - String generateBill(Vector prestations) { - return generateBill(vectorToArray(prestations)); - } - - - String generateHTMLBill(Vector prestations) { - return generateHTMLBill(vectorToArray(prestations)); - } - - - /** - * Generates an HTML formatted string with the bill - * - * @param prestations - * An array containing all the prestations - * @return The HTML formatted string - */ - String generateHTMLBill(int[] prestations) { - int total_sum = 0; - Object[] keys = services.keySet().toArray(); - - - String result = ""; - result += ""; - result += "Super Auto 20000 bill"; - result += "Version 1.0"; - result += ""; - - - // Create an HTML table - result += ""; - result += ""; - result += "Prestation"; - result += "Price"; - result += ""; - - - for (int i = 0; i < prestations.length; i++) { - if (prestations[i] > services.size()) { - System.out.println("Error, non existing prestation !"); - System.exit(-1); - } - - - String cKey = (String) keys[prestations[i]]; - - - // HTML row - result += ""; - result += "" + cKey + "" + services.get(cKey) + ""; - result += ""; - total_sum += services.get(cKey); - } - - - result += ""; - result += "Total price"; - result += "" + total_sum + ""; - result += ""; - - - // End of the HTML table - result += ""; - - - result += ""; // Horizontal line - - - result += "Lab 15 generator"; - result += ""; - return result; - } - - - /** - * Generates a text bill - * - * @param prestations - * An array containing all the prestations - * @return The generated text bill - */ - String generateBill(int[] prestations) { - int total_sum = 0; - Object[] keys = services.keySet().toArray(); - - - String result = ""; - result += "*************************\n"; - result += "* Super Auto 20000 bill ****\n"; - result += "*******************************\n\n"; - - - for (int i = 0; i < prestations.length; i++) { - if (prestations[i] > services.size()) { - System.out.println("Error, non existing prestation !"); - System.exit(-1); - } - - - String cKey = (String) keys[prestations[i]]; - result += "- " + cKey + " \t" + services.get(cKey) + "\n"; - total_sum += services.get(cKey); - } - - - result += "\n----------------------------------\n"; - result += " Bill total \t\t" + total_sum + "\n"; - result += "----------------------------------\n"; - result += "\nPayment in 30 days. Thank you !"; - return result; - } - - - public static void main(String[] args) { - GarageManager gm = new GarageManager(); - - - // Prestation 0 is "Oil level control" - // Prestation 1 is "Tire replacement " - // Prestation 2 is "Windshield exchange" - // Prestation 3 is "Oil filter change" - // Prestation 4 is "Battery replacement" - // Prestation 5 is "Pollution control" - // Prestation 6 is "Brake revision" - - - int[] client1 = { 1, 1, 1, 1, 4, 6, 0 }; - String bill1 = gm.generateBill(client1); - System.out.println(bill1); - - - PrintWriter outputStreamName; - - - try { - outputStreamName = new PrintWriter(new FileOutputStream("bill.txt")); - outputStreamName.print(bill1); - outputStreamName.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - -} \ No newline at end of file diff --git a/src/lab15_oop/hevs/utils/DateUtils.java b/src/lab15_oop/hevs/utils/DateUtils.java deleted file mode 100644 index 5a5a8d7..0000000 --- a/src/lab15_oop/hevs/utils/DateUtils.java +++ /dev/null @@ -1,83 +0,0 @@ -package hevs.utils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * @author Pierre-André Mudry, HES-SO Valais 2010 - * @version 1.0 - */ -public class DateUtils { - - private static final long msPerHour = 60 * 60 * 1000; - private static final long msPerDay = 24 * msPerHour; - - /** - * Creates a date from a text representation of this date - * @param s The text representation, formatted as "dd/MM/yyyy" - * @return The corresponding date - */ - static public Date createDate(String s){ - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - - Date theDate = null; - - try { - theDate = sdf.parse(s); - } - catch(ParseException ex) { - System.err.println("Invalid date format specified !"); - ex.printStackTrace(); - } - - return theDate; - } - - static private long nMsec(Date a, Date b){ - if(b.after(a)){ - return b.getTime() - a.getTime(); - } - else - { - return a.getTime() - b.getTime(); - } - } - - /** - * Computes the number of hours between two dates - * @param a The first date - * @param b The second date - * @return The number of hours between the two dates - */ - static public int nHours(Date a, Date b){ - int n= Math.round(nMsec(a, b)/ msPerHour); - return n; - } - - /** - * Computes the number of day between two dates - * @param a The first date - * @param b The second date - * @return The number of days between the two dates - */ - static public int nDays(Date a, Date b){ - int nDays= Math.round(nMsec(a, b)/ msPerDay); - return nDays; - } - - // Some samples - public static void main(String args[]){ - Date first = DateUtils.createDate("1/1/2000"); - Date second = DateUtils.createDate("1/1/2001"); - - // It also takes into account leap years (2000) - System.out.println("There were " + DateUtils.nDays(first, second) + " days in 2000"); - - // How old are you in days ? - Date birthdate = DateUtils.createDate("12/10/1977"); - Date now = new Date(); - System.out.println("You are " + DateUtils.nDays(now, birthdate) + " days old"); - } - -} diff --git a/src/lab15_oop/hevs/utils/Input.java b/src/lab15_oop/hevs/utils/Input.java deleted file mode 100644 index 801afcc..0000000 --- a/src/lab15_oop/hevs/utils/Input.java +++ /dev/null @@ -1,135 +0,0 @@ -package hevs.utils; -import java.io.*; - -/** - * * The Class Input is here to enter data with the keyboard. - * The types below are supported by the Input class. - * - * - String - * - Integer (int) - * - Double (double) - Boolean (boolean) - * - Character (char) - * - * - * - * @author Patrice Rudaz (patrice.rudaz@hevs.ch) - * @author Cathy Berthouzoz (cathy.berthouzoz@hevs.ch) - * @modified Pierre-André Mudry - * @version 3.0 - 6-10-2008 - * @see #readString() - * @see #readLong() - * @see #readLong() - * @see #readDouble() - * @see #readBoolean() - * @see #readChar() - */ -public class Input { - /** - * * Reads a valid char value from the console. - * - * @return The typed char - * @see java.lang.Character - */ - public static char readChar() { - boolean ok = false; - int res = -1; - while (!ok) { - try { - BufferedReader stdin = new BufferedReader( - new InputStreamReader(System.in)); - res = stdin.read(); - ok = Character.isDefined(res); - } catch (Exception ex) { - System.out.println("This is not a valid character. Try again"); - } - } - return (char) res; - } - - /** - * * Reads a String from the console. - * - * @return The typed string - * @see java.lang.String - */ - public static String readString() { - BufferedReader stdin = new BufferedReader(new InputStreamReader( - System.in)); - try { - return stdin.readLine(); - } catch (Exception ex) { - return "There is a problem. Try again."; - } - } - - /** - * * Reads a valid integer value from the console. - * - * @return The typed value - * @see java.lang.Integer - */ - public static int readInt() { - boolean ok = false; - int res = -1; - while (!ok) { - try { - BufferedReader stdin = new BufferedReader( - new InputStreamReader(System.in)); - String s = stdin.readLine(); - if (s.startsWith("0x") || s.startsWith("0X")) { - res = Integer.parseInt(s.substring(2), 16); - } else { - res = Integer.parseInt(s, 10); - } - ok = true; - } catch (Exception ex) { - System.out.println("This is not a valid number. Try again"); - } - } - return res; - } - - /** - * * Reads a valid double value from the console. - * - * @return The typed double value - * @see java.lang.Double - */ - public static double readDouble() { - boolean ok = false; - double res = -1; - while (!ok) { - try { - BufferedReader stdin = new BufferedReader( - new InputStreamReader(System.in)); - res = Double.parseDouble(stdin.readLine()); - ok = true; - } catch (Exception ex) { - System.out.println("This is not a valid number. Try again"); - } - } - return res; - } - - /** - * * Reads a valid boolean value from the console. - * - * @return the value true if the typed value is true, false otherwise. - * @see java.lang.Boolean - */ - public static boolean readBoolean() { - boolean ok = false; - boolean res = false; - while (!ok) { - try { - BufferedReader stdin = new BufferedReader( - new InputStreamReader(System.in)); - res = Boolean.parseBoolean(stdin.readLine()); - ok = true; - } catch (Exception ex) { - System.out.println("This is not a valid boolean. Try again"); - } - } - return res; - } -} \ No newline at end of file diff --git a/src/lab15_oop/logo_garage.png b/src/lab15_oop/logo_garage.png deleted file mode 100644 index 2f179f8..0000000 Binary files a/src/lab15_oop/logo_garage.png and /dev/null differ