首页 > 其他分享 >Object-Oriented Programming

Object-Oriented Programming

时间:2024-08-09 12:39:19浏览次数:11  
标签:object Object Programming should Oriented earthquake Quake data method

Object-Oriented Programming

Resit Coursework

This assignment involves the development of Java classes and a program to support analysis of earthquake

data compiled by the United States Geological Survey. We have provided three example datasets that you

can use to test your solution.

1 Preparation

A Zip archive containing the files for the assignment is provided in Minerva. When you unzip it, you should

see three files of earthquake data, along with four .java files. One of these, QuakeException.java, is

complete and ready for you to use; the other three files containing empty Java classes.

There are ‘To Do’ comments inside the classes that summarise the code that you need to write, and detailed

step-by-step instructions are provided below.

Before you begin programming, take some time to study the sample data. You can use a spreadsheet

application to do this. Each row in the dataset represents a single earthquake. The different columns

represent various parameters measured for an earthquake. You don’t need to know what most of these are,

although further details can be found at the USGS Earthquake Hazards Program website if you are interested.

The only columns relevant to this assignment are: latitude, longitude, depth and magnitude.

Note that filenames consist of two parts: a severity level (often expressed in terms of earthquake magnitude)

and a time period. The two parts are separated by the underscore character. Thus, 2.5_day.csv contains

details of earthquakes of magnitude 2.5 or greater, recorded over a single day; 4.5_week.csv records

earthquakes of magnitude 4.5 or greater, over a one-week period; and significant_month.csv records

‘significant’ earthquakes recorded during a one-month period.

2

Quake Class

This class encapsulates the details a single earthquake.

  1. Edit Quake.java in a text editor. Add to the class fields that represent the latitude, longitude, depth

and magnitude of an earthquake.

  1. Create a constructor for Quake that takes a single String parameter. This string represents all of the

data provided by the USGS for a single earthquake, with each value separated from the others by

commas. To see real examples of what this string looks like, open one of the data files in a text editor

(not in a spreadsheet), and examine any of the lines after the first.

Note: you can use a method of the String class to help you implement this.

Your constructor should perform some basic validation, checking that latitude is within the allowed

range of −90.0 ◦ to 90.0 ◦ , and that longitude is within the allowed range of −180.0 ◦ to 180.0 ◦ . You

should throw an instance of QuakeException, containing an appropriate error message, if latitude or

longitude are invalid.

  1. Write simple ‘getter’ methods for each of the fields. These methods should simply return the values

of the fields.

  1. Write a toString method for Quake. This should generate and return a string representation of

the Quake object. The string should contain magnitude, depth, latitude and longitude, in that order,

formatted like this example:

M5.0, 12.6 km, (35.4975°, 141.0217°)

Note: the ‘degrees’ symbol can be generated with the Unicode escape sequence \u00b0.

As you complete each step of implementing this class, remove the corresponding ‘To Do’ comment and

check that your code compiles.

Once you’ve written the constructor and getter methods, you can test them by writing a small program that

creates a Quake object from a string. You can use one of the lines from the given data files as the string.

1IMPORTANT: You should make sure that the Quake class is working as expected before moving on to

the other class or the program that uses the classes.

3

QuakeDataset Class

This class represents an entire dataset containing the details of multiple earthquakes.

  1. Edit QuakeDataset.java. Add to the class a field that can represent a collection of Quake objects.

There are various options open to you here, some of which will be easier to use and more flexible than

others. Make sure that the field is initialized properly—either at the point of definition or by writing

a constructor.

Note that when a QuakeDataset object is created, it should represent an ‘empty’ dataset—ready to

accept data, but not yet containing any data.

  1. Now write a method named readData in QuakeDataset. This method should accept two String

parameters, representing the severity level and time period for a file of earthquake data.

Note that the allowed values for severity level are significant, 4.5, 2.5, 1.0 and all. The

allowed values for time period are hour, day, week and month. You should throw an instance of

QuakeException if the supplied parameter values do not meet these requirements.

The readData method should

  • Read earthquake data from the relevant data file
  • Turn each line of data into a Quake object
  • Store this Quake object in the field provided for this purpose

The name of the data file should be determined from the severity level and time period parameters:

e.g., if severity is "4.5" and period is "week", then 4.5_week.csv should be used.

The readData method should NOT intercept any exceptions that might occur during the process of

reading from the CSV file.

  1. Write a method named size that returns the number of Quake objects currently stored.
  2. Write a method named get that returns the Quake object at a specific position. Position should be

supplied as an int parameter and should be zero-based: i.e., calling get with an argument of 0 should

return the first Quake object in the dataset.

  1. Write a method to find and return the Quake object representing the strongest (maximum magnitude)

earthquake in the dataset. If there are multiple candidates, the first one should be returned by the

method.

  1. Write a method to find and return the Quake object representing the shallowest (minimum depth)

earthquake in the dataset. Again, in the case of multiple candidates, the first one should be returned

by the method.

  1. Finally, write a method that prints out details of each Quake object, one quake per line. You should

exploit the toString method defined in Quake for this.

As with Quake, you should remove the relevant ‘To Do’ comments as you implement each method, and you

should fix any compilation errors before moving on to the next step.

You will need to make sure that your QuakeDataset class is reasonably robust. The get method and the

methods to find the strongest, weakest, deepest and shallowest earthquakes should all throw an instance

of QuakeException if there are no Quake objects currently stored in the QuakeDataset object. The get

method should throw an instance of QuakeException if the supplied position parameter is invalid.

4

QuakeInfo Program

Edit QuakeInfo.java. Inside the main method of the class, write the code indicated by the ‘To Do’

comments, removing the comments as you go. The finished program should print this and then terminate if

it is run without two command line arguments:

Usage: java QuakeInfo <level> <period>

2If the program is run with two arguments but one or both are invalid, it should catch the resulting exception

and display the associated error message, then terminate.

If the program is run with two valid arguments, and if a valid CSV file corresponding to these arguments

exists, the program should generate output like this:

7 quakes in dataset

M6.1, 54.0 km, (-21.9342°, -70.3404°)

M6.2, 96.8 km, (-22.1960°, -68.4984°)

M7.0, 10.0 km, (17.5601°, 120.8011°)

M5.4, 10.0 km, (26.9092°, 55.2149°)

M6.4, 10.0 km, (-44.5986°, -79.7623°)

M6.8, 10.0 km, (-22.6455°, -114.2227°)

M4.7, 51.1 km, (60.9805°, -150.9365°)

Shallowest : M7.0, 10.0 km, (17.5601°, 120.8011°)

Strongest : M7.0, 10.0 km, (17.5601°, 120.8011°)

5 Submission

Create a Zip archive containing all of .java and .csv files. Submit this Zip archive via the link provided

in Minerva.

The deadline for submission will be advertised in Minerva.

3

标签:object,Object,Programming,should,Oriented,earthquake,Quake,data,method
From: https://www.cnblogs.com/vx-codehelp/p/18350089

相关文章

  • Objective-C学习笔记(Block用法)
    Blocks(块)block以插入字符(^)为标识。可以作为函数参数,返回值,或直接调用返回类型(^block命名)(参数类型1,参数类型2)NSString*(^stringBlock)(int,int)=^NSString*(inta,intb){return[NSStringstringWithFormat:@"%d%d",a,b];};当使用block作为函数的参......
  • [Paper Reading] DEFORMABLE DETR: DEFORMABLE TRANSFORMERS FOR END-TO-END OBJECT D
    DEFORMABLEDETR:DEFORMABLETRANSFORMERSFOREND-TO-ENDOBJECTDETECTIONlink时间:2021(ICLR)机构:Sensetime&USTC&CUHKTL;DR参考2DDeformableConv,通过在ReferencePoint附近增加samplepoints,将DETR的收敛速度提升10倍,对于小目标效果也更好。Method背景知识:参考......
  • com.alibaba.fastjson 将object装jsonObject两次字段顺序会出现不一致
    Objectentity=params.get("entity");JSONObjectjsonObject=(JSONObject)JSONObject.toJSON(entity);//遍历JSONObjectfor(Map.Entry<String,Object>entry:jsonObject.entrySet())以上代码,在同一个object,两次经过的到时候,遍历J......
  • [Typescript] Typing Functions with Object Params
    import{expect,it,vitest}from'vitest';constlogId=(obj:{id:string})=>{console.log(obj.id);};constlogName=(obj:{name:string})=>{console.log(obj.name);};constloggers=[logId,logName];constlogAll=(o......
  • JSON parse error: Cannot deserialize instance of `java.lang.Long` out of START_O
    这个问题的实际原因就是:    后端id(Long类型)用的雪花算法生成主键id    后端生成id位:1820397662671867904    前端查询id的结果为:1820397662671868000产生的原因:    后端生成为19位,前端接受并展示,使用的类型是number类型是16位   ......
  • The 2022 ICPC Asia Taoyuan Regional Programming Contest
    Preface由于今天HDU多校是自己学校出的题,因此像我这种没出题的就可以白兰一天爽歪歪然后和祁神找了场Ucup来VP,这场傻逼题巨多,不那么傻逼的题后面发现被搬到去年暑假前集训了,然后直接3h10题下班后期徐神全力冲刺他最喜欢的造计算机题,反观某人已经在Celeste启动了,怎么......
  • const objectUtil = require('../../utils/object'); const toolUtil = require('../.
    //模态框functionshowModal(title,content,confirm,cancel){wx.showModal({title:title,content:content,showCancel:true,success(res){if(res.confirm){confirm(confirm)}elseif(res.canc......
  • 多态,抽象,接口,Object,Equals
    1.多态1.1编译时多态:在编译时就能够确定调用哪个方法​方法重载是编译时多态,在编译期根据参数的数据类型,个数以及次序来确定调用方法1.2运行时多态:只有在运行时才能确定调用哪个方法,主要指动态绑定来实现,动态绑定是程序运行时确定调用哪个方法的过程,他依赖于对......
  • TypeError: ‘float’ object is not iterable 深度解析
    TypeError:‘float’objectisnotiterable深度解析与实战指南在Python编程中,TypeError:'float'objectisnotiterable是一个常见的错误,通常发生在尝试对浮点数(float)进行迭代操作时。这个错误表明代码中存在类型使用不当的问题,因为浮点数不是可迭代对象。本文将深入......
  • TypeError: ‘dict’ object is not callable 深度解析
    TypeError:‘dict’objectisnotcallable深度解析在Python编程中,TypeError:'dict'objectisnotcallable是一个常见的错误,通常发生在尝试调用一个字典对象时。这个错误表明代码中存在逻辑错误,可能是将字典误用为函数或方法。本文将深入探讨这一错误的常见原因,并提......