09-04-02 Class
2015-04-09 14:53
260 查看
BJP3 Exercise 8.5: slopePoint
Status:You
have solved this problem; good work!
Added by:Will Beebe on 2013/04/01
Language:Java
Keywords:classes
Popularity:14 likes
Like
Add the following method to the
Pointclass:
public double slope(Point other)
Returns the slope of the line drawn between this
Pointand the given other
Point. Use
the formula (y2 - y1) / (x2 - x1) to determine the slope between two points (x1, y1) and (x2, y2). Note that this formula fails for points with identical x-coordinates, so throw an
IllegalArgumentExceptionin
this case.
public class Point { private int x; private int y; // your code goes here }
我的答案:
public double slope(Point other){
if (other.x == x) {
throw new IllegalArgumentException();
}else{
return (double)(other.y - y)/(other.x - x);
}
}
这样也能最后得到诸如0.5的结果
相关文章推荐
- 黑马程序员--09.动态与代理AOP--02【Class.forName方法扩展】【Proxy类I】
- Java语言介绍(04)开源项目(09)门户网站(02)JetSpeed
- 04面向对象编程-02-原型继承 和 ES6的class继承
- 01/09/2007---04/02/2007的笔记
- 04/02/09
- spark内核揭秘-09-RDD的count操作 触发Job全生命周期-02
- 初学cpp<classl类02>
- titanium开发教程-02-04创建开关
- D04 02-15
- 导入项目后 出现Unbound classpath container: 'JRE System Library [jdk1.6.0_04]' in project '项目名'这样的错误
- [bbk2192] 第33集 - Chapter 09-Optimizing Sore Perations(02)
- IFE_02_dynamicDataBinding_04
- R1 Lecture 09 Class Notes
- 09-给NSString增加一个对象方法(分类练习02)
- (原创)c#学习笔记08--面向对象编程简介02--OOP技术04--对象之间的关系
- 关于百度坐标系 (BD-09)与火星坐标系 (GCJ-02)以及WGS84坐标之间的互相转换
- 02-IO流(输入输出!字节流&字符流) 03-IO流(字符流-FileWriter). 04-IO流(字符流-FileWriter-细节(换行和续写)) 05-IO流(异常处理)12
- 04/08/09
- Oracle数据库创建与安装_超越OCP精通Oracle视频教程培训02~04
- 04/27/09