Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Lab 13 Lab 13: Object Composition In this lab, we will build a couple of classes, where one will be composed into the other. Work in pairs if you wish. Problem We saw Point.java in class last week. Do the following, one step at a time, making sure it works before you go on to the next step. Be sure to get help if you have any difficulties. You may use Point.java from last week or build a new one of your own. If you are not confident that you can build one of your own, try to build one anyway rather than using the one from last week. Build a class called Circle which uses a Point object as its center. This is where object composition is used. In this lab, you will be using three classes: Point, Circle, and UseCircle. You will not need UsePoint unless you want to test your Point using UsePoint. To compile your overall program, you can issue the javac command only once with UseCircle.java, right? In the Circle class, add the usual things such as constructor(s), getter(s), setter(s), and other methods. You should add only what is necessary for the class to work properly. Don't blindly add constructors, getters, and setters. Other methods that you will add is partly determined by what is used in UseCircle.java. Why did I say partly instead of entirely? Well, the fact that some things are not used in UseCircle.java does not necessarily mean that they should not be added to Circle. Think about it! If UseCircle is written to test all possible things that Circle should provide, then yes, but it may not be written that way. In other words, the person who designs Circle should think about what should be included in it. Think about what would be useful in different cases for someone else who will use Circle. In most cases for us, the person who designs the class X and the the person who writes UseX are the same person. But, in general that is not the case, e.g., we did not write java.util.Random but we use it. In UseCircle though, I want you to include a call to do each of the following at a minimum: Use a constructor that takes two parameters: one Point object and the radius of the circle object that you are creating. Use a getter to get the radius and then print it. Use a getter to get the center of the circle, which would be a Point object. The fact that you passed a Point object when you called the constructor naturally matches the fact that the getter should be returning a Point object. Once you get the point object, print the x and y values in it with two separate calls to the getters in Point. Use a setter to set the radius to a new value. How many parameters would the setter take? After you change the radius, get it again and print it to see if the change was done as expected. Use a method called area that computes the area of the circle and print it. Use a method called scale to enlarge or shrink the circle by a scale_factor. You will have to pass a scale factor as an argument into the method scale. How many parameters will the scale method have? If you said 2, you would be wrong. If you said 1, you would be right. Think about it! After you scale it, make sure your scale method did the right thing by reexamining the radius of the circle (use the getter method and then print the value). Write a method called translate to move the circle to a new location by passing a delta_x and delta_y to move in both x- and y-directions by that much. Use the method to translate the circle by some distance along the x and y axis. Again make sure your changes were done correctly by using getters in Point to fetch the x- and y-values of the new location. Here again you will be getting a Point object and look inside to get the x- and y-values, right? Use a method that computes the distance from the center of the circle to the origin and print it. Create a second circle object. Use a method that computes the distance between two circle objects and print the distance. Add other functionalities if you wish. Use your imagination!!! When you are done, When you are done with these, feel free to leave the meeting.