Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java language Description According to reports, the water usage rate of Saudi Arabia is twice the world average. To deal with this alarming situation, the

java language
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Description According to reports, the water usage rate of Saudi Arabia is twice the world average. To deal with this alarming situation, the Department of Statistics has collected the total water usage data from various cities in different regions for the recent years along with the population details during these years. You are required to develop an application that can use this data as input and provide insight details of the water usage from different perspective such as the per year percentage increase or decrease in water usage over time in a specific city, the per capita water usage, the lowest and highest water usage cities etc. All this information will be helpful to help in reducing the water usage per capita. Table 1 shows the data of regions, cities, population and the annual total water usage in cubic meter (cb.m). Region City Year Population Water Usage cb.m Riyadh Ar-Riyad 2019 4503744 638347384 4564633 Al-Kharj 2018 5516374 635495744 Ad-Dawadmi Makkah Makkah-al- Mukarramah 2020 2018 2019 2020 2018 2019 2020 2018 2019 2020 2018 2019 2020 2018 2019 2020 2020 2020 415865 418636 425330 263847 269038 271947 2119393 2124848 2042047 3516374 3503744 3564633 527834 525437 543823 419383 119383 650736422 43593433 42957485 44326383 28453343 29504583 30129347 533563432 545564533 535765756 345675764 356006874 335834763 21565633 22300454 22506565 23594575 9557786 Jeddah Taif Qassim Buraidah Unaizah Table 1 Water Usage Data From the given Table 1, you need to make different arrays to store all the data used in the program. For example, you need a one-dimension array to store region. Each region contains one or more cities, so you need a two-dimension array to store the city. Similarly, each city has records of several previous years. The program stores the year, population, and water usage in different column. Therefore, you need 3 three-dimension arrays: (first one to store the year, second one to store the population, and third one to store the water usage). Basic Requirements The program must read the data from a text file called "input.txt" that follows a specific pattern. If the file doesn't exist, print a message to let the user know what happened. - see Input File Pattern section for more details. The program must generate a text file as the output called "output.txt" that contains the results of the commands written in the input file - see Output File Pattern section for more details. The program must load and deal with data dynamically. This means you should never write the data as hard codes. You should use loops to deal with the arrays. The program must follow the format of the output file as possible. Input File Pattern The input file called 'input.txt' is attached with this document. The pattern, which the input file follows, is explained in the following input file example: 3 //The first line in the input file: the number of the region stored in this file. In other words, the size of region array. 3 3 2 //The second line in the input file: the number of cities in each region. It is separated with a space. Ex: the first region has 3 cities, the second region has 3 cities, and the third region type has 2 cities. In other words, cities[0] = new String(3); cities[1] = new String[3]; cities[2] = new String(2); add_regions Riyadh Makkah Qassim //The add_regions command registers the names of the region. It takes a list of the region names separated by a space. Ex: regions[0] = "Riyadh"; regions[1] = "Makkah"; regions[2] = "Qassim"; add_cities Riyadh Ar-Riyad Al-Kharj Ad-Dawadmi //The add_cities command is used to registers the names of the cities. It takes the name of the region as the first argument, and then the list of the city names separated by a space. "Riyadh" region has three cities, so three names are defined (Ar-Riyad, Al- Kharj, Ad-Dawadmi). Note: you have to find the index of the region and the index of the city to set the names. add_cities Makkah Makkah-al-Mukarramah Jeddah Taif // "Makkah" region has three cities, so three names are defined in the command (Makkah-al- Mukarramah, Jeddah, Taif). add_cities Qassim Buraidah Unaizah // "Qassim region has two cities, so two names are defined in the command (Buraidah, Unaizah). add_populations Riyadh Ar-Riyad 3 //"add_populations" command registers the population details of the city for a region. It takes the name of the region as the first argument, the name of the city as the second argument, the number of the years as the third argument. All these arguments are separated by a space. This command is the followed by list of details including year, population, and Water usage - all separated by a space. Ex: For "Riyadh" region and "Ar-Riyad" city, there are 3 records containing the year, population and water usage. As mentioned earlier, you need 3 three- dimension arrays; the first one to store the year as a string, the second one to store the population as an int, and the third one to store water usage as long. 2018 5516374 635495744 2019 4503744 638347384 2020 4564633 650736422 add_populations Riyadh Al-Kharj 3 //In the "Riyadh" region and "Al- Kharj" city, 3 years of record is available, and the information is listed below. 2018 415865 43593433 2019 418636 42957485 2020 425330 44326383 add_populations Riyadh Ad-Dawadmi 3 //In the "Riyadh" region and "Ad- Dawadmi" city, 3 years of record is available, and the information is listed below. 2018 263847 28453343 2019 269038 29504583 2020 271947 30129347 add_populations Makkah Makkah-al-Mukarramah 3 //In the "Makkah" region and "Makkah-al-Mukarramah" city, 3 years of record is available, and the information is listed below. 2018 2119393 533563432 2019 2124848 545564533 2020 2042047 535765756 add_populations Makkah Jeddah 3 //In the "Makkah region and "Jeddah" city, 3 years of record is available, and the information is listed below. 2018 3516374 345675764 2019 3503744 356006874 2020 3564633 335834763 add_populations Makkah Taif 3 //In the "Makkah" region and "Taif" city, 3 years of record is available, and the information is listed below. 2018 527834 21565633 2019 525437 22300454 2020 543823 22506565 add_populations Qassim Buraidah 1 l/In the "Qassim" region and "Buraidah" city, only 1 year of record is available, and the information is listed below. 2020 419383 23594575 add_populations Qassim Unaizah 1 //In the "Qassim" region and "Unaizah" city, only 1 year of record is available, and the information is listed below. 2020 119383 3989786 print_result Riyadh Ar-Riyad /l"print_result" is a command that prints details about the per capita water usage and the change in percentage with respect to the previous year. It takes the name of the region as the first argument, the name of the city as the second argument. All these arguments are separated with a space. Ex: prints the details of the city "Ar-Riyad" in the "Riyadh" region. Hints: Percentage change of per capita = [(This Year - Last Year) / Last Year] x 100 Do not calculate percentage change for the first year of available record and simply print "NA" (for Not Applicable) Per capita daily usage (liters) = Total water usage in liters/ (total population X 365) 1 cb.m = 1000 liters print_result Riyadh Al-Kharj l/Prints the details of the "Al-Kharj" city in the "Riyadh" region. print_result Riyadh Ad-Dawadmi //Prints the details of the Al-Dawadmi" city in the "Riyadh" region. print_result Makkah Makkah-al-Mukarramah //Prints the details of the "Makkah-al-Mukarramah" city in the "Makkah" region. print_result Makkah Jeddah //Prints the details of the "Jeddah" city in the "Makkah" region. print_result Makkah Taif //Prints the details of the "Taif" city in the "Makkah" region. print_result Qassim Buraidah //Prints the details of the "Buraidah" city in the "Qassim" region. print_result Qassim Unaizah //Prints the details of the "Unaizah" city in the "Qassim" region. find_lowest_usage // "find_lowest_usage" is a command that finds and prints the record of lowest per capita water usage. find_highest_usage // "find_highest_usage" is a command that finds and prints the record of highest per capita water usage. about_developer // "about_developer" is a command that prints the information about the programmer who created this program (Your information). exit ll" exit" is a command that ends the program. After this command, the output file called "output.txt" must be generated in the same directory of the program. Also, the date and time of the generation should be printed in the output file. 5 1 3 3 3 2 3 add_regions Riyadh Makkah Qassim 4 add_cities Riyadh Ar-Riyad Al-Kharj Ad-Dawadmi 5 add_cities Makkah Makkah-al-Mukarramah Jeddah Taif 6 add_cities Qassim Buraidah Unaizah 7 add_populations Riyadh Ar-Riyad 3 8 2018 5516374 635495744 9 2019 4503744 638347384 10 2020 4564633 656736422 11 add_populations Riyadh Al-Kharj 3 12 2018 415865 43593433 13 2019 418636 42957485 14 2020 425330 44326383 15 add_populations Riyadh Ad-Dawadmi 3 16 2018 263847 28453343 17 2019 269038 29504583 18 2020 271947 30129347 19 add_populations Makkah Makkah-al-Mukarramah 3 20 2018 2119393 533563432 21 2019 2124848 545564533 22 2020 2042047 535765756 23 add_populations Makkah Jeddah 3 24 2018 3516374 345675764 25 2019 3503744 356006874 26 2020 3564633 335834763 27 add_populations Makkah Taif 3 28 2018 527834 21565633 29 2019 525437 22300454 30 2020 543823 22506565 31 add_populations Qassim Buraidah 1 32 2020 419383 23594575 33 add_populations Qassim Unaizah 1 34 2020 119383 3989786 35 print_result Riyadh Ar-Riyad 36 print_result Riyadh Al-Kharj 37 print_result Riyadh Ad-Dawadi 38 print_result Makkah Makkah-al-Mukarramah 39 print result Makkah Jeddah 40 print_result Makkah Taif 41 print_result Qassim Buraidah 42 print_result Qassim Unaizah 43 find lowest_usage find_higest_usage 45 about_developer 46 exit Figure 1. Input file (input.txt) Output File Pattern The output file should include all the results of the commands that have been read from the input file "input.txt". The format of the output file is provided as separate file "output.txt". Commands You Have to Implement As you see in the input and output files, there are some commands that you have to implement: Command #1 Command add regions Description It registers the names of the region. It takes a list of the region names separated by a space Example add_regions Riyadh Makkah Qassin Output of Cormand) add_regions the Example + Riyadh Makkah Qassin Command Description Example Output of the Example Command #2 add cities it registers the names of the cities. It takes the name of the region as the first argument, and then the list of the cities separated by a space. add_cities Riyadh Ar-Riyad Al-Khary Ad-Dawada Connand) add_cities -> City: Riyadh Ar-Riyad Al-Kharj Ad-Dawadni Command Description Command #3 add populations It registers the year, population, and water usage details of the city. It takes the name of the region as the first argument, the name of the city as the second argument, the number of year as the third argument. All these arguments are separated with a space. Then it lists the year, population and water usage separated with a space. add populations Riyadh Ar-Riyad 3 2018 5516374 635495744 2019 4503744 638347384 2020 4564633 650736422 Example Output of the Example [Command) add_population Region: Riyadh City: Ar-Riyad Year 2018 2019 2020 Population 5,516,374 4,583,744 4,564,633 Annual Water Usage (cb.a) 635, 495,744 638,347,384 650,736,422 Command Description Command #14 print_result It prints details about the year, population, annual water usage, per capita daily usage and change (in percentage) of the specific city in a region. It takes the name of the region as the first argument, the name of the city as the second argument. All these arguments are separated with a space. print_result Riyadh Ar-Riyad Command print_result Region: Riyadh - City Ar-Riyad Per capita daily Example Output of the Example Antwerpen Change Year 2010 2019 2030 Population 5,516,314 4,503,744 4,564.633 315 6, 7,1 23.1N 3.5 Command Description Example Output of the Example Command #5 find lowest_usage It is a command that finds and prints the lowest water usage per capita record. find_lowest_mileage Commandl find lovestsage The city with lowest per capita water usage in all regions Year Population Annual Water Usage (cb.a) 2020 119,383 3,989,786 In Region: Cassis, City: Unairah Per capita daily usage 9 Command Description Example Output of the Example Command #6 find_highest_usage It is a command that finds and prints the highest water usage per capita record. find_highest_mileage Con and find_Nigest_usage The city with highest per capita water usage in all regions Year Population Annual Water Usage (cm Per capita daily usage 1) 2820 2,042,047 335.765,756 718 Is Region Makkah, City Makkah-al-Mukarrah Command #7 Command about_developer Description It prints the information about the developer of the guide (student info). Example about_developer Output of - Command: about_developer the Example -> Developed By: Ali Alqahtai -> University ID: 2004832 -> Section: DA Command #8 Command exit Description It ends the program. After this command, the output file called "output.txt" must be generated in the same directory of the program. Also, the date and time of the generation should be printed in the output file. Example exit Output of Thank You! :) the Example Report generated on Sun Feb 07 17:18:32 AST 2021

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions