Java开发问题 [英] Java development question

查看:89
本文介绍了Java开发问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据以下规范开发公共类MyCircles:



1.该类有一个私有实例ArrayList< circle2d>,它代表Circle2D的集合。



2.该类有一个零参数构造函数,用于创建和初始化ArrayList< circle2d>实例对象。



3.该类有一个公共方法void addCircle2D(Object,String),用于将Circle2D的实例对象添加到ArrayList中。 String表示将填充circle2D对象的颜色的名称。



4.该类的方法为readFromFile(String)。它从文本文件中读取,其名称作为方法的字符串参数给出。然后使用circle2D实例对象的值填充ArrayList集合。提示:文件中的每一行都有4个值,表示x,y和double类型的半径,后跟一个字符串值代表颜色。



5. class有printAll()方法。它显示一个字符串,表示ArrayList中的每个元素(每行一个)或字符串消息NO Shapes are available。



6.班级有方法check_Overlaps_Contains(),它显示ArrayList的哪些圆相互重叠或相互包含。该方法应打印如下消息格式:



检查重叠并包含******************** **********圆圈:0表示红色:圆圈重叠:1表示黄色。 ............... ..包含圆形:2具有蓝色。 ................圆圈:1,黄色:圆圈重叠:0,红色。包含圆:0表示红色。圆形重叠:2具有蓝色。 ........................ ..提示:0和1表示ArrayList中对象的索引。



7.该类的方法为check_contains_point(double x,double y),它显示ArrayList的哪些圆包含点(x,y)。该方法应打印如下消息格式:以下包含Point(...,...)的圆圈**************************** ******************圆圈:0红色。 ....................................................



我的尝试:



我试图开发这个代码,所以我不知道如何开始编码。

Develop a public class MyCircles to the following specifications:

1. The class has a private instance ArrayList<circle2d>, which represent a collection of Circle2D.

2. The class has a zero-argument constructor that creates and initializes the ArrayList<circle2d> instance object.

3. The class has a public method void addCircle2D (Object, String) which is used to add an instance object of Circle2D into the ArrayList. The String represents the name of the color that will fill the circle2D object.

4. The class has the method readFromFile (String). It reads from a text file which its name given as a string argument of the method. Then fills the ArrayList collection with the values of the circle2D instance objects. Hint: Each line in the file has 4 values representing x, y, and radius of type double consequently, followed by a string value represent the color.

5. The class has the method printAll(). It displays either a string representing each element in the ArrayList (one per line) or a string message that "NO Shapes are available".

6. The class has the method check_Overlaps_Contains(), which displays which circles of the ArrayList are overlapped with each other, or contained in each other. The method should print a message format as follows:

Checking Overlaps and Contains ****************************** Circle: 0 with red color: Overlaps with Circle:1 that has yellow color. …………….. Contains Circle:2 that has blue color. …………….. Circle: 1 with yellow color: Overlaps with Circle:0 that has red color. Contains Circle:0 that has red color. Overlaps with Circle:2 that has blue color. …………………….. Hint: 0 and 1 represent the index of the objects in the ArrayList.

7. The class has the method check_contains_point(double x, double y), which displays which circles of the ArrayList contains point(x,y). The method should print a message format as follows: The following circles containing the Point (…, ….) ********************************************** Circle: 0 with red color. …………………………………………….

What I have tried:

I have tried to develop this code, so I have no idea how to start coding this.

推荐答案

参见< a href =http://download.oracle.com/javase/tutorial/index.html> Java™教程 [ ^ ]。


这篇关于Java开发问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆