CS 11 – Homework #1 – due 3pm Wednesday October 15, 2008 Climate Classification In this assignment you will write a Java program that reads monthly average temperature and precipitation data from input, and then gives the climate classification for this particular place. This is a more thorough version of the climate program you worked on during lab #4. The purpose of this assignment is to become acquainted to using arrays (of numbers) and further practice with loops and if-then situations. The input will come from a file. This file contains 3 lines of information. The first line the user will type in will be the name of a city. Note that the city name may consist of multiple words. The second line will contain twelve numbers representing the average temperature (in degrees Fahrenheit) of the months from January to December. The third line, also containing 12 numbers, represents the precipitation (in inches) of each of the months. You may assume all numbers are of the “double” type. Basic Features (60% of marks) The output from your program will inform the user of the average annual temperature of the city, counting each month equally, and the total annual precipitation. In addition, your program will determine which type of climate the city has, based on the criteria1 listed below. There are 13 possible cases. 1. Tropical wet: The average temperature for the coldest month is at least 64.4, and the driest month has at least 2.4 inches of precipitation. 2. Tropical wet and dry: Like tropical wet, but the driest month has less than 2.4 inches of precipitation. 3. Hot desert: The coldest month is 32 degrees or warmer, and the annual precipitation is less than one-fifth the value of the average annual temperature. 4. Cold desert: Like the hot desert, but the coldest month is less than 32 degrees. 5. Hot steppe: Like the hot desert, but the annual precipitation is at least one-fifth, but less than one-third of the value of the average annual temperature. 6. Cold steppe: Like the hot steppe, but the coldest month is less than 32 degrees. 7. Subtropical: The warmest month is at least 71.6 degrees, and the coldest month is at least 32 degrees but less than 64.4 degrees. 8. Temperate: Like subtropical, but the warmest month is less than 71.6 degrees 9. Humid Continental: like subtropical, but the coldest month is less than 32 degrees. 10. Cool continental: The warmest month is less than 71.6 degrees and at least 4 months have an average temperature of at least 50, and the coldest month is less than 32. 11. Subarctic: Like cool continental, but only 1-3 months have an average temperature at least 50. 12. Tundra: The warmest month is at least 32 but less than 50. 13. Icecap: The warmest month is less than 32. To test your program with real data, you can find actual climate information on http://www.worldclimate.com or many other sites. The definitions given here are a simplified version of the scheme given in Glenn Trewartha’s An Introduction to Climate, McGraw-Hill, 1954, p. 235. 1 Implementation You will need to create two files: City.java and Climate.java. The Climate.java file will be the driver that calls the City constructor and prints the necessary output. The City.java file will perform the input and calculations. Inside City.java you need to have the following information: Attributes for the city name, an array of double to contain the temperature data, and another for precipitation data. A default constructor, similar to the one for the shopping list program, that reads the input and initializes the City object’s information. getName() that returns the name of the city as a String. Functions that determine the values for the warmest, coldest, wettest and driest months. These functions will be useful later. Instance functions that implement the 13 climate definitions above – these should return boolean. A function that returns how many months are at least 50 degrees. Functions that compute the average annual temperature, and the total precipitation. When you are finished, send your 2 source files electronically, either by sending them via e-mail, or by uploading them to the file server. To do this, create a folder with just your 2 Java source files in it, and copy this folder to \\Csserver03.furman.edu\Fall2008\CSC121-01\In Example I/O: What is the name of the input file? pitt.txt The average temperature of Pittsburgh is 50.2 degrees. Pittsburgh has 36.6 inches of precipitation annually. Pittsburgh has a humid continental climate. Note that the above I/O assumes that the contents of pitt.txt looks like this: Pittsburgh 26 29 39 50 59 68 72 70 64 52 42 32 2.6 2.3 3.3 3.2 3.6 3.6 3.9 3.3 2.9 2.4 2.7 2.8 Advanced Features (20% of marks) It is probably a good idea not to work on advanced features until you have the basic features working. In general, problems are more manageable if we break them into stages. In climate cases 7-11, your program should also comment on whether the city has a dry summer or dry winter. If it has neither, then the program should say the city has no dry season. A dry summer means that the driest month has less than 1.2 inches of precipitation, and there is at least 3 times as much precipitation in the wettest month of winter than in the driest month of summer. A dry winter means that at least 10 times as much precipitation falls in the wettest month of summer as in the driest month of winter. For the purposes of the above definitions of dry summer and winter, you may assume that if July is warmer than January, then “summer” refers to the half-year from May through October (inclusive), and the winter half is November through April (inclusive). If January is warmer than July, then these roles of summer and winter months are reversed. You should therefore have functions to determine if the city has a dry summer or winter. You may also find it useful to have a function to determine which hemisphere the city is in. Design (10% of marks) By 3pm, Tuesday, October 7, I would like you to turn in a short document which shows an outline of your solution. An e-mail submission will be fine. This should not be written in Java code, but may be in the form of paragraph-style comments. You don’t need to spell out every detail, but you need to show me that you have thought about the problem considerably and have a reasonable approach to solving the problem. You will receive full credit for a reasonable effort, even if your design is wrong. The reason why I’m asking for this early document is so that if there are major problems with your approach, you can correct them early. Style (10% of marks) In your final submission, make sure that your code looks good and is structured properly. It should be documented well, indented properly and use meaningful variable names. There should be enough documentation (comments) in the code so that it would not be necessary to read the Java statements to figure out what is going on. Good style also means following directions regarding the format of the I/O.