Meteorological offices keep records of average monthly rainfalls over a number of cities. The
record for each city consists of the name of the city, the year the data refers to, and a list of
twelve numbers describing respectively the average rainfall in each of the twelve months
of the year. We want to write a Java class system that handles such records. The intended use
includes the setting up of a number of such records, and the printing (on request) of all
available information to the screen. To this end, you need to
1. Create a simple class system meeting the stated requirements. Provide a method that
calculates the average rainfall over a specified number of months for a given city and a
given year.
Hint: You may want to use the decomposition (seen many times in this module) into a
Driver class and another class of your choice, e.g., RainFallRecord, but
~2~
CSE105 Introduction to Programming in Java
remember that the constructor of the latter should carefully validate any data that is to
be assigned to the class attributes. Think about Exception handling.
2. Provide implementations for the following operations (please stick to the given
method signature (i.e. name, parameter list and return value)) for a given year and a
given city:
· double rainfall(String month) searches for the value of the rainfall
in the given month of the year, and city.
· void delete(String month) deletes the rainfall value associated with
the given month, year, and city.
· void insert(String month, double value) inserts the given
rainfall value for the given year, month and city. For simplicity assume that any
value that was there before will be lost.
· void insert(String quarter, double[] value) inserts in the list
the given rainfall values for the given quarter and city. Also, assume that any
value that was there before will be lost.
· String wettest() returns the month with the highest rainfall value over
the given year and city.
Hint: Don’t forget that your code must be robust, i.e. return some answer (e.g., an
error message) even if the particular operation cannot be completed successfully.
3. Define a class Archive, which will be able to store information about a collection of
rainfall records. Provide implementations for the following operations:
a. An appropriate constructor initializing any object of the class type.
b. A method insert to add a rainfall record to the database.
c. A method delete to delete a rainfall record from the database.
d. A method print that prints the whole “database”.
Hint: Remember that combinations “city name + year” should be unique, no two
records in the database should have the same pair of values for the two attributes
mentioned above. Again your code must be robust.
这个是小弟这次的作业。因为要占学分,所以挺纠结的。
依据题目所说是不是需要建立一个database system
希望各位大神能帮帮忙。谢谢啦。
record for each city consists of the name of the city, the year the data refers to, and a list of
twelve numbers describing respectively the average rainfall in each of the twelve months
of the year. We want to write a Java class system that handles such records. The intended use
includes the setting up of a number of such records, and the printing (on request) of all
available information to the screen. To this end, you need to
1. Create a simple class system meeting the stated requirements. Provide a method that
calculates the average rainfall over a specified number of months for a given city and a
given year.
Hint: You may want to use the decomposition (seen many times in this module) into a
Driver class and another class of your choice, e.g., RainFallRecord, but
~2~
CSE105 Introduction to Programming in Java
remember that the constructor of the latter should carefully validate any data that is to
be assigned to the class attributes. Think about Exception handling.
2. Provide implementations for the following operations (please stick to the given
method signature (i.e. name, parameter list and return value)) for a given year and a
given city:
· double rainfall(String month) searches for the value of the rainfall
in the given month of the year, and city.
· void delete(String month) deletes the rainfall value associated with
the given month, year, and city.
· void insert(String month, double value) inserts the given
rainfall value for the given year, month and city. For simplicity assume that any
value that was there before will be lost.
· void insert(String quarter, double[] value) inserts in the list
the given rainfall values for the given quarter and city. Also, assume that any
value that was there before will be lost.
· String wettest() returns the month with the highest rainfall value over
the given year and city.
Hint: Don’t forget that your code must be robust, i.e. return some answer (e.g., an
error message) even if the particular operation cannot be completed successfully.
3. Define a class Archive, which will be able to store information about a collection of
rainfall records. Provide implementations for the following operations:
a. An appropriate constructor initializing any object of the class type.
b. A method insert to add a rainfall record to the database.
c. A method delete to delete a rainfall record from the database.
d. A method print that prints the whole “database”.
Hint: Remember that combinations “city name + year” should be unique, no two
records in the database should have the same pair of values for the two attributes
mentioned above. Again your code must be robust.
这个是小弟这次的作业。因为要占学分,所以挺纠结的。
依据题目所说是不是需要建立一个database system
希望各位大神能帮帮忙。谢谢啦。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货