2018-2019 Fall Semester Lab Exercise A1Assignment4Design a class named Rectangle. The class contains:a. Five private data fields [10 points] x (double) : The x position of the center. In a valid rectangle, the range ofx is in (-10, 10) y (double) : The y position of the center. In a valid rectangle, the range ofy is in (-10, 10) width (double) : The width of the rectangle. In a valid rectangle, the rangeof width is in [0, 5] height(double) : The height of the rectangle. In a valid rectangle, the rangeof height is in [0, 5] color (java.awt.Color): The color of rectangle.b. Design three constructors: [10 points]1. A constructor with two parameters including x and y2. A constructor with four parameters including x, y, width and height.3. A constructor with seven parameters, the first four parameters are doubletype, which represent the x, y, width and height of current rectangle,and the last three parameters are integers, which represent the red, greenand blue value of current color respectively. If a rectangle has no width and height, in constructor method we need toset width=1 and height=1 as default value. If a rectangle has no color, in constructor method we need to set a defaultcolor whose red, green and blue value are all 100. For the third constructor, if the value of red green and blue are largerthan 255 or smaller than 0, we need to set it as its closest boundaryvalue.c. Design the getter and setter method for each private field of Rectangle. [10points]d. Design a toString() method, which can return a String value as followingoutput format. [10 points]The first test:public class Test1 {public static void main(String[] args) {Rectangle r1=new Rectangle(0,1,2,2,100,150,100);Rectangle r2=new Rectangle(3,1,3,1,-1,350,100);Rectangle r3=new Rectangle(2,2);Rectangle r4=new Rectangle(3,-1,2,2);System.out.println(r1);2018-2019 Fall Semester Lab Exercise A2System.out.println(r2);System.out.println(r3);System.out.println(r4);}}e. Design a public method named intersect() with a Rectangle parameter and areturn value (boolean). If the current rectangle is intersected with theparameter rectangle, it will return true, otherwise it will return false. [10points]f. Design a public static method named intersect() with two Rectangleparameters and a return value (boolean). If two rectangles are intersected, itwill return true, otherwise it will return false. [10 points]The Second Test:public class Test2 {public static void main(String[] args) {Rectangle r1=new Rectangle(0,0,2,2,100,50,100);Rectangle r2=new Rectangle(1.5,2,3,1,-1,350,100);Rectangle r3=new Rectangle(1.6,-1,1,3,50,100,200);Rectangle r4=new Rectangle(1,1,1,2,180,100,40);System.out.println(r1.intersect(r2));System.out.println(r1.intersect(r3));System.out.println(r1.intersect(r4));System.out.println(Rectangle.intersect(r3, r4));}}g. Design a public method named isValid() with a return value (boolean). Onlywhen the range of its width and height are in [0, 5] (0 and 5 are included) andCentre[0.0,1.0] Shape[2.0,2.0] Color[100,150,100]Centre[3.0,1.0] Shape[3.0,1.0] Color[0,255,100]Centre[2.0,2.0] Shape[1.0,1.0] Color[100,100,100]Centre[3.0,-1.0] Shape[2.0,2.0] Color[100,100,100]falsefalsetruetrue2018-2019 Fall Semester Lab Exercise A3the range of it x and y position are in (-10,10) (-10 and 10 are not included)代寫Fall Semester作業(yè)此再、代做Java編程語言作業(yè)、代寫Rectangle留學(xué)生作業(yè)劳吠、代做Java作業(yè) 幫做J, itwill return true, otherwise it will return false. [10 points]h. Design a public method named isInBoundary() with a return value (boolean).If the whole rectangle can be drawn in the screen (-10,10), it will return true,otherwise it will return false. [10 points]The third Test:Rectangle r1=new Rectangle(-2,1,5,5,100,150,200);Rectangle r2=new Rectangle(9,1,5,5,250,100,40);System.out.println(r1.isInBoundary());System.out.println(r2.isInBoundary()); ‘(The whole rectangle of the blue one can be drawn in the screen, so it is in boundary,but the orange one is not.)i. In same package, we create a class named RectangleTest, in which there is amain method. In main method, we will read several lines as following format.For each line, we need create an object of Rectangle according to the data inline. After that, we need to output all valid rectangles, which are not intersectwith the first valid rectangle in the line order. [10 points]The fourth Test:Sample input:2018-2019 Fall Semester Lab Exercise A49.27,6.61,3,7.18,209,144,2473.4,4.0,4.5,4.5,100,100,100-2.89,7.61,5.57,5.068.43,6.667.42,0.68,2.07,2.93,78,39,1656.70,1.54,3.52,3.121.14,0.76,2.37,3.07,236,105,1371.06,-0.80,3.03,2.66,132,120,2733.01,-9.08,2.76,2.36,138,148,119-0.51,-4.99,6.42,5.65-4.36,8.70,3.03,2.63,16,138,2219.40,2.41,6.47,4.90Sample output:j. Design a public method named draw() , in which we need to draw the currentrectangle in screen. We need to make sure that: [10 points] Only draw the valid rectangle. The rectangle in screen needs to have its color.In main method, adding following two statements, just before you using drawmethod.StdDraw.setXscale(-10,10);StdDraw.setYscale(-10,10);The fifth Test:Sample input:-4.98,-8.00,3.29,1.660.17,-8.00,2.37,3.434.04,-8.00,1.67,1.776.84,-8.00,3.35,3.30,87,9,2606.84,-4.03,2.20,2.83,200,139,786.84,-0.89,3.04,1.97,122,195,146.84,2.636.84,6.09,2.04,1.804.36,6.09Centre[8.4,6.7] Shape[1.0,1.0] Color[100,100,100]Centre[7.4,0.7] Shape[2.1,2.9] Color[78,39,165]Centre[1.1,-0.8] Shape[3.0,2.7] Color[132,120,255]Centre[3.0,-9.1] Shape[2.8,2.4] Color[138,148,119]Centre[-4.4,8.7] Shape[3.0,2.6] Color[16,138,221]2018-2019 Fall Semester Lab Exercise A50.64,6.09,3.07,3.25,-10,299,288-2.28,6.09,2.56,3.22-5.19,6.09,1.68,2.37,-20,-30,184-5.19,3.68,3.11,2.34-5.19,-0.82-5.19,-4.86,2.67,2.99,129,7,49Sample output:Sample input:-1.96,-8.00,2.99,-2.39,230,119,1482.80,-8.007.23,-8.00,2.44,3.207.23,-4.07,2.63,2.04,241,27,2677.23,0.57,8.84,1.987.23,5.917.23,9.18,-2.15,2.263.26,9.181.15,9.18,1.86,2.16,69,204,101-2.51,9.18,2.52,3.41-5.18,9.18,-1.02,3.172018-2019 Fall Semester Lab Exercise A6-6.18,6.75,-2.51,2.22,81,26,176-7.18,2.01,2.43,2.88,116,85,169-8.18,-1.42Sample output:What to submit1. Please submit three “.java” files including “Rectangle.java”“RectangleTest.java” and “StdDraw.java”, and make sure thatthose “.java” files have no package information included. Rectangle.java: It is for you to create and edit all questions. RectangleTest.java: It is for you to add necessary code to finish question i, and do not remove other code in this file. StdDraw.java: You can do no change about this file, but do not forget to remove package information if you added it.2. Please submit those three files into sakai website before deadline轉(zhuǎn)自:http://ass.3daixie.com/2018112013362282.html
講解:Fall Semester、Java、Rectangle殷勘、JavaJava|R
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門洽糟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人堕战,你說我怎么就攤上這事坤溃。” “怎么了嘱丢?”我有些...
- 文/不壞的土叔 我叫張陵薪介,是天一觀的道長。 經(jīng)常有香客問我越驻,道長汁政,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任缀旁,我火速辦了婚禮记劈,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘并巍。我一直安慰自己目木,他們只是感情好,可當(dāng)我...
- 文/花漫 我一把揭開白布懊渡。 她就那樣靜靜地躺著嘶窄,像睡著了一般。 火紅的嫁衣襯著肌膚如雪距贷。 梳的紋絲不亂的頭發(fā)上柄冲,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼姜盈!你這毒婦竟也來了低千?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布秆吵,位于F島的核電站,受9級特大地震影響岖是,放射性物質(zhì)發(fā)生泄漏帮毁。R本人自食惡果不足惜实苞,卻給世界環(huán)境...
- 文/蒙蒙 一豺撑、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧黔牵,春花似錦聪轿、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至金赦,卻和暖如春音瓷,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背夹抗。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 標(biāo)簽(空格分隔): 編程 Go官方文檔 Using the tour 1.1 Hello, 世界 Welcome...
- 選擇通殃,團(tuán)隊 1.超領(lǐng)課程 6小時! 2.團(tuán)隊開會厕宗,分享 2.5小時画舌! 3.微信平臺搭建討論 40min! *你...
- 6月18日轻专,由新醫(yī)美藝術(shù)節(jié)組委會主辦、廣州遠(yuǎn)想生物科技有限公司和翊品學(xué)院聯(lián)合承辦的新醫(yī)美藝術(shù)節(jié)臨床技術(shù)全明星賽·線...