import java.util.Scanner; /** * Replace this JavaDoc comment for the purpose of this class */ public class Solution { /** * Gets data from standard input */ private Scanner input; /** * Start the execution of the solution * @param args Command line arguments */ public static void main(String args[]) { Solution solution = new Solution(); solution.run(); } /** * Run the solution. This method is called from main() */ public void run() { // Create object to read data from standard input input = new Scanner(System.in); // Create a controller object Reader reader = new Reader(); // Create shop objects Shop carrillo = new Shop(); Shop liberia = new Shop(); Shop sardinal = new Shop(); while ( input.hasNextLine() ) { // Extract the date, shop and clash closs reader.read(input); // Check for high or low season reader.checkSeason(); // Give the season and the cash close to the shop object reader.giveData(); } // Calculates the averages for every shop carrillo.calculateAverages(); liberia.calculateAverages(); sardinal.calculateAverages(); // Print the cash closes average table System.out.println("TIENDA BAJA ALTA"); System.out.println("=============== =============== ============="); carrillo.printData(); liberia.printData(); sardinal.printData(); // Close the standard input input.close(); } } /** * Reads the date, name of the sucursal and the day cash close for every entrance */ class Reader { /** * The shop name */ private String shop = null; /** * The day cash close */ private double cashClose = 0.0; /** * Day and month of the entrance */ private int day = 0; private int month = 0; /** * High or low season * 0 for low season and 1 for high season */ private int season = 0; /** * Read dates, shop and cash close */ public void read(Scanner input) { input.useDelimiter("/| "); // Read day and month day = input.nextInt(); month = input.nextInt(); // Skip the year input.nextInt(); // Read the sucursal shop = input.next(); input.useDelimiter("\n"); // Read the day cash close cashClose = input.nextDouble(); } /** * Check for high or low season * If month < 4 and month == 12 or month ==7, change season from 0 to 1 (1 is the high season identifyer) */ public void checkSeason() { if (( this.month <= 4 || this.month == 12 ) || this.month == 7 ) { this.season = 1; } } /** * Give the recovered data to a single shop object */ public void giveData() { Shop carrillo = new Shop(); Shop liberia = new Shop(); Shop sardinal = new Shop(); switch (shop) { case "Carrillo": carrillo.getData(cashClose, season); break; case "Liberia": liberia.getData(cashClose, season); break; case "Sardinal": sardinal.getData(cashClose, season); break; } } } /** * Stores the cash closes average for a shop */ class Shop { /** * High and low season averages */ private double highAverage = 0.0; private double lowAverage = 0.0; /** * Counters for every cash close */ private int highCloses = 0; private int lowCloses = 0; /** * Recover the cash close and season in low and high season averages * @see Class Reader giveData(); */ public void getData(double cash, int season) { if (season == 1) { this.highAverage = this.highAverage + cash; this.highCloses = this.highCloses++; } else { this.lowAverage = this.lowAverage + cash; this.lowCloses = this.lowCloses++; } } /** * Calculates the high and low season averages */ public void calculateAverages() { highAverage = highAverage / highCloses; lowAverage = lowAverage / lowCloses; } /** * Prints a line with the low and high season averages */ public void printData() { System.out.printf("%15,.2f %15,.2f%n", lowAverage, highAverage); } }