import java.util.Scanner; /** * Read de dates and sales from the standard input, print a report in a table for each branch *for high season (December to April), middle year vacations (July) and low season (other moths). */ public class LibroRegistro { /** * Gets data from standard input */ private Scanner input; /** * Start the execution of the LibroRegistro * @param args Command line arguments */ public static void main(String args[]) { LibroRegistro libroregistro = new LibroRegistro(); libroregistro.run(); } /** * Run the LibroRegistro. This method is called from main() */ public void run() { // Create object to read data from standard input input = new Scanner(System.in); //Declaration of counter variables int counterhc=0; int counterlc=0; int counterhs=0; int counterls=0; int counterhl=0; int counterll=0; //Declaration of Sales for Season variables double HighMounthSalesS=0.0; double LowMounthSalesS=0.0; double HighMounthSalesC=0.0; double LowMounthSalesC=0.0; double HighMounthSalesL=0.0; double LowMounthSalesL=0.0; // Print de header. System.out.println("TIENDA BAJA ALTA"); System.out.println("=============== =============== ==============="); // Read the data (Dates, branch and mount of sales) while ( input.hasNextLine() ) { //Read data (Dates, branch and mount of sales) String data=input.nextLine(); String data1[]=data.split("\\s+"); String date[]=data1[0].split("/"); String month=date[1]; String branch=data1[1]; String sales=data1[2]; //Calculate mount of sales by branch int months=Integer.parseInt(month); double sale=Double.parseDouble(sales); //Calculate mount of sales for Carillo if (branch.equals("Carrillo")) { //Calculate Mount of sales for High Season if (months==12 ||months==1||months==2||months==3||months==4 ||months==7) { HighMounthSalesC=HighMounthSalesC+sale; counterhc=counterhc+1; } //Calculate Mount of sales for Low Season if (months==5 ||months==6||months==8||months==9||months==10 ||months==11) { LowMounthSalesC=LowMounthSalesC+sale; counterlc=counterlc+1; } } //Calculate mount of sales for Sardinal if (branch.equals("Sardinal")) { //Calculate Mount of sales for High Season if (months==12 ||months==1||months==2||months==3||months==4 ||months==7) { HighMounthSalesS=HighMounthSalesS+sale; counterhs=counterhs+1; } //Calculate Mount of sales for Low Season if (months==5 ||months==6||months==8||months==9||months==10 ||months==11) { LowMounthSalesS=LowMounthSalesS+sale; counterls=counterls+1; } } //Calculate mount of sales for Liberia if (branch.equals("Liberia")) { //Calculate Mount of sales for High Season if (months==12 ||months==1||months==2||months==3||months==4 ||months==7) { HighMounthSalesL=HighMounthSalesL+sale; counterhl=counterhl+1; } //Calculate Mount of sales for Low Season if (months==5 ||months==6||months==8||months==9||months==10 ||months==11) { LowMounthSalesL=LowMounthSalesL+sale; counterll=counterll+1; } } } //Print average of mounth of sales for Carrillo branch System.out.printf("%-15s","Carrillo"); //if counter is euals to zero remplace for 1 and calculate average. if (counterlc==0) { counterlc=1; System.out.printf("%,16.2f", LowMounthSalesC/counterlc); } else //Else keept the original value of counter and calculate average { System.out.printf("%,16.2f", LowMounthSalesC/counterlc); } //if counter is euals to zero remplace for 1 and calculate average. if(counterhc==0) { counterhc=1; System.out.printf("%,16.2f%n",HighMounthSalesC/counterhc); } else //Else keept the original value of counter and calculate average { System.out.printf("%,16.2f%n",HighMounthSalesC/counterhc); } //Print average of mounth of sales for Liberia branch System.out.printf("%-15s","Liberia"); //if counter is euals to zero remplace for 1 and calculate average. if (counterll==0) { counterll=1; System.out.printf("%,16.2f",LowMounthSalesL/counterll); } else //Else keept the original value of counter and calculate average { System.out.printf("%,16.2f",LowMounthSalesL/counterll); } //if counter is euals to zero remplace for 1 and calculate average. if (counterhl==0) { counterhl=1; System.out.printf("%,16.2f%n",HighMounthSalesL/counterhl); } else //Else keept the original value of counter and calculate average { System.out.printf("%,16.2f%n",HighMounthSalesL/counterhl); } //Print average of mounth of sales for Sardinal branch System.out.printf("%-15s","Sardinal"); //if counter is euals to zero remplace for 1 and calculate average. if (counterls==0) { counterls=1; System.out.printf("%,16.2f",LowMounthSalesS/counterls); } else //Else keept the original value of counter and calculate average { System.out.printf("%,16.2f",LowMounthSalesS/counterls); } //if counter is euals to zero remplace for 1 and calculate average. if (counterhs==0) { counterhs=1; System.out.printf("%,16.2f%n",HighMounthSalesS/counterhs); } else //Else keept the original value of counter and calculate average { System.out.printf("%,16.2f%n",HighMounthSalesS/counterhs); } // Close the standard input input.close(); } }