import java.util.Scanner; /** * Create the class Solution that is the controller of the programm */ public class Solution { /** * Gets data from standard input */ private Scanner input; /** *Reference to the current branch Office being processed */ private Sucursal sucursal = null; /** * 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); input.useDelimiter("/"); input.useDelimiter("\\s+"); // This code replicates the input to the standard output while ( this.readBranch() ) { /** * Generate the header of the table * */ System.out.println("TIENDA BAJA ALTA"); System.out.println("============== ============== ============== "); /** *Print every data for standard output */ this.sucursal.calculateSeason(); System.out.print("Carrillo "); System.out.printf(" %8.2f %8.2f %n" , this.sucursal.getbajaCarrillo() , this.sucursal.getaltaCarrillo() ); System.out.print("Liberia "); System.out.printf(" %8.2f %8.2f %n" , this.sucursal.getbajaLiberia() , this.sucursal.getaltaLiberia() ); System.out.print("Sardinal "); System.out.printf(" %8.2f %8.2f" , this.sucursal.getbajaSardinal() , this.sucursal.getaltaSardinal() ); } // Close the standard input input.close(); } /** *Read data from standard input and create a sucursal *@return true if a sucursal was read from standard input, false if there are no */ public boolean readBranch() { if ( this.input.hasNext() ) { /** *read the given data for the sucursal */ int days = input.nextInt(); int month = input.nextInt(); int year = input.nextInt(); String place = input.next(); double money = input.nextDouble(); Sucursal sucursal = new Sucursal(days, month, year, place, money); return true; } else { /** *no more data to create a sucursal in standard input */ return false; } } // leer las fechas de en que se produjeron los cierres de caja para determinar la temporada // leer el lugar en el que fue el cierre de caja // leer la cantidad de dinero que se generĂ³ en el lugar } /** * Create a class Sucursal to the model of the different places */ class Sucursal { /** *indicates the day in which the cash register was made */ private int days = 0; /** *indicates the month in which the cash register was made */ private int month = 0; /** *indicates the year in which the cash register was made */ private int year = 0; /** *Indicates the amount of money gain after the cash register */ private double money = 0.00; /** * read the attributes of the class */ private String place = null; /** * read the attributes of the class */ private double altaCarrillo = 0.00; /** * read the attributes of the class */ private double bajaCarrillo = 0.00; /** * read the attributes of the class */ private double altaLiberia = 0.00; /** * read the attributes of the class */ private double bajaLiberia = 0.00; /** * read the attributes of the class */ private double altaSardinal = 0.00; /** * read the attributes of the class */ private double bajaSardinal = 0.00; /** *Builds a Branch office with each of the data received, date in days, months, year; the place and the money gain for each places *in both seasons low and high *@param day of the month *@param month of the year *@param year *@param Name of the place where the branch office is located *@param money gain in each season in each place */ public Sucursal(int days, int month, int year, String place, double money) { this.days = days; this.month = month; this.year = year; this.money = money; this.place = place; } /** *calculate the money gain for each season and place */ public void calculateSeason() { /** *calculate the money gain in the high season Carrillo, Liberia, Sardinal */ if ( (month <= 4 || month == 7 || month == 12)) { if (this.place.equals("Carrillo")) { this.altaCarrillo += this.money; } if (place.equals("Liberia")) { this.altaLiberia += this.money; } if (place.equals("Sardinal")) { this.altaSardinal += this.money; } } /** *caculate the money gain in the low season in Carrillo, Liberia, Sardinal */ else { if (place.equals("Carrillo")) { this.bajaCarrillo += this.money; } if (place.equals("Liberia")) { this.bajaLiberia += this.money; } if (place.equals("Sardinal")) { this.bajaSardinal += this.money; } } } /** *Get the money gain the different places Carrillo, Liberia, Sardinal; and seasons low and High *@ Return a copy of each of the money gain in each place and in each season */ public double getbajaCarrillo() { return this.bajaCarrillo; } public double getaltaCarrillo() { return this.altaCarrillo; } public double getbajaLiberia() { return this.bajaLiberia; } public double getaltaLiberia() { return this.altaLiberia; } public double getbajaSardinal() { return this.bajaSardinal; } public double getaltaSardinal() { return this.altaSardinal; } }