⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buc3.java

📁 BUC testing for data aggregation
💻 JAVA
字号:
import java.io.*;import java.util.*;//import java.lang.String;public class buc3{        static int salesArrayIndex = 0;        static int yearArrayIndex = 0;        static int subcatArrayIndex = 0;	        static int cityArrayIndex = 0;        static int countryArrayIndex = 0;                static double[] sales = new double[65000];        static String year[] = new String[5];        static String subcat[] = new String[20];        static String city[] = new String[300];        static String country[] = new String[10];        static int record[][] = new int[65000][5];
	static int cardinality [] = new int [4];                        static double salesTemp;        static String yearTemp;        static String subcatTemp;        static String cityTemp;        static String countryTemp;            public static void main(String[]args)    {                try        {            BufferedReader Input = new BufferedReader(new FileReader("data.txt"));            PrintWriter Output = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));            String temp; //store the input read from the file            int recordNum = 0;            int cubes = 0;            while((temp=Input.readLine())!=null)            {                StringTokenizer tempTokenizer;                tempTokenizer = new StringTokenizer(temp);                                             salesTemp = Double.parseDouble(tempTokenizer.nextToken("|"));                createSalesArray(salesTemp,recordNum);
		//System.out.println(salesTemp);                                yearTemp = tempTokenizer.nextToken("|");                createYearArray(yearTemp,recordNum);
		//System.out.println(yearTemp);                                subcatTemp = tempTokenizer.nextToken("|");                createSubcatArray(subcatTemp,recordNum);		//System.out.println(subcatTemp);                                cityTemp = tempTokenizer.nextToken("|");                createCityArray(cityTemp,recordNum);                //System.out.println(cityTemp);                                countryTemp = tempTokenizer.nextToken("|");                createCountryArray(countryTemp,recordNum);                //System.out.println(countryTemp);                                //System.out.println(record[recordNum][0] + " " + record[recordNum][1] + " " + record[recordNum][2] + " " + record[recordNum][3] + " " + record[recordNum][4]);                //System.out.println(salesArrayIndex + " " + yearArrayIndex + " " + subcatArrayIndex + " " + countryArrayIndex + " " + cityArrayIndex);                                recordNum++;            }                        System.out.println(salesArrayIndex + " sales tuples");            System.out.println(yearArrayIndex + " years");            System.out.println(subcatArrayIndex + " subcategories" );            System.out.println(countryArrayIndex + " countries");            System.out.println(cityArrayIndex + " cities\n");            
	    
	    cardinality[0] = cityArrayIndex;
	    
	    
	    for (int w = 0 ; w < cityArrayIndex ; w++)            {                double totalSum = 0;
		//int [] temp1 = new int [65000];                                for (int recordId = 0 ; recordId < recordNum ; recordId++)                {                      if (record[recordId][4] == w)                    {                        totalSum += sales[record[recordId][0]];                    }                    }                                if (totalSum >= 100000)                {                    System.out.println("City = " + city[w] + ": total sales = " + (int)totalSum/1000 + "K");                    cubes++;                                        for (int x = 0 ; x < subcatArrayIndex ; x++)                    {                        totalSum = 0;                                                for (int recordId = 0 ; recordId < recordNum ; recordId++)                        {                              if ((record[recordId][4] == w) && (record[recordId][2] == x))                            {                                totalSum += sales[record[recordId][0]];                            }                            }                                                 if (totalSum >= 100000)                         {                            System.out.println("City= " + city[w] + ", Subcategory = " + subcat[x] + ": total sales = " + (int)totalSum/1000 + "K");                            cubes++;                                                        for (int y = 0 ; y < countryArrayIndex ; y++)                            {                                totalSum = 0;                                                        for (int recordId = 0 ; recordId < recordNum ; recordId++)                                {                                      if ((record[recordId][4] == w) && (record[recordId][2] == x) && (record[recordId][3] == y))                                    {                                        totalSum += sales[record[recordId][0]];                                    }                                    }                                                        if (totalSum >= 100000)                                {                                    System.out.println("City = " + city[w] + ", Subcategory = " + subcat[x] + ", Country = " + country[y] + ": total sales = " + (int)totalSum/1000 + "K");                                    cubes++;                                                                        for (int z = 0 ; z < yearArrayIndex ; z++)                                    {                                        totalSum = 0;                                                                for (int recordId = 0 ; recordId < recordNum ; recordId++)                                        {                                              if ((record[recordId][4] == w) && (record[recordId][2] == x) && (record[recordId][3] == y) && (record[recordId][1] == z))                                            {                                                totalSum += sales[record[recordId][0]];                                            }                                            }                                                                if (totalSum >= 100000)                                        {                                            System.out.println("City = " + city[w] + ", Subcategory = " + subcat[x] + ", Country = " + country[y] + ", Year = " + year[z] + ": total sales = " + (int)totalSum/1000 + "K");                                            cubes++;                                        }                                        }                                    }                             }                            }                    }                    }                               }                        System.out.println("Total number of cubes satisfying iceberg condition: " + cubes);                        //close all the files            Input.close();	    Output.close();        }                catch (FileNotFoundException e){            System.out.println("Error openning input file " + e.getMessage());            System.exit(0);        }        catch (IOException e){            System.out.println("Error: IO Error! "+ e.getMessage());            System.exit(0);        }    }        public static void createSalesArray(double salesTemp, int recordIndex)    { 	        if (salesArrayIndex == 0)	{            sales[0] = salesTemp;            record[recordIndex][0] = 0;            salesArrayIndex++;	} 	else        {            sales[salesArrayIndex] = salesTemp;            record[recordIndex][0] = salesArrayIndex;            salesArrayIndex++;        }    }
    
    public static void createDimArray(String temp, int recordIndex, int [] cardinality, int x)
    {
	if (cardinality[x] ==0)
	{
	    
	}
    }    public static void createYearArray(String yearTemp, int recordIndex)    { 	        if (yearArrayIndex == 0)	{            year[0] = yearTemp;            record[recordIndex][1] = 0;            yearArrayIndex++;	} 	else	{            boolean found = false;                        for (int i = 0 ; i < yearArrayIndex ; i++)            {		if (yearTemp.compareTo(year[i]) == 0)		{                    record[recordIndex][1] = i;                    found = true;                    break;		}            }     		            if (!found)            {                year[yearArrayIndex] = yearTemp;                record[recordIndex][1] = yearArrayIndex;                yearArrayIndex++;            }                    }    }        public static void createSubcatArray(String subcatTemp, int recordIndex)    { 	        if (subcatArrayIndex == 0)	{            subcat[0] = subcatTemp;            record[recordIndex][2] = 0;            subcatArrayIndex++;	} 	else	{            boolean found = false;                        for (int i = 0 ; i < subcatArrayIndex ; i++)            {		if (subcatTemp.compareTo(subcat[i]) == 0)		{                    record[recordIndex][2] = i;                    found = true;                    break;		}            }     		            if (!found)            {                subcat[subcatArrayIndex] = subcatTemp;                record[recordIndex][2] = subcatArrayIndex;                subcatArrayIndex++;            }                    }    }        public static void createCountryArray(String countryTemp, int recordIndex)    { 	        if (countryArrayIndex == 0)	{            country[0] = countryTemp;            record[recordIndex][3] = 0;            countryArrayIndex++;	} 	else	{            boolean found = false;                        for (int i = 0 ; i < countryArrayIndex ; i++)            {		if (countryTemp.compareTo(country[i]) == 0)		{                    record[recordIndex][3] = i;                    found = true;                    break;		}            }     		            if (!found)            {                country[countryArrayIndex] = countryTemp;                record[recordIndex][3] = countryArrayIndex;                countryArrayIndex++;            }                    }    }        public static void createCityArray(String cityTemp, int recordIndex)    { 	        if (cityArrayIndex == 0)	{            city[0] = cityTemp;            record[recordIndex][4] = 0;            cityArrayIndex++;	} 	else	{            boolean found = false;                        for (int i = 0 ; i < cityArrayIndex ; i++)            {		if (cityTemp.compareTo(city[i]) == 0)		{                    record[recordIndex][4] = i;                    found = true;                    break;		}            }     		            if (!found)            {                city[cityArrayIndex] = cityTemp;                record[recordIndex][4] = cityArrayIndex;                cityArrayIndex++;            }                    }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -