正在回答 回答被采纳积分+1
10回答
chrismorgen
2019-03-14 14:50:00
你好同学,针对了你的代码进行了修改,同学只要在Calculator 类中添加如下代码来返回result值就可以了。
1 2 3 | public int getResult(){ return result; } |
老师是在Calculator类中写了getResult方法的哦,通过下图窗口可以看出Calculator类中是有getResult方法的哦,祝学习愉快~
chrismorgen
2019-03-13 18:01:41
你好同学,老师的代码中没有getResult方法哦,请问同学的getResult方法是要干什么用的呢?是模仿老师在代码中的那部分呢?建议同学详细的说明一下,这样我才能知道你该怎么写哦,祝学习愉快~
chrismorgen
2019-03-12 18:25:09
你好同学,你这个是参考那个视频的哪分钟案例写的呀?其实同学可以参考一下老师提供的源码,通过老师的源码来看自己的思路哪里不足,这是一个很不错的学习方法,如下标记的是老师的案例源码,祝学习愉快~
chrismorgen
2019-03-12 15:39:52
你好同学,看一下下图的报错提示,你的Calculator类中没有getResult方法,所以无法调用,建议你在Calculator类中创建getResult方法后,在进行调用。祝学习愉快~
慕羲
2019-03-12 11:22:52
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package com.imooc.test; import static org.junit.Assert.*; import org.junit.Ignore; import org.junit.Test; public class CalculatorTest1 { public static Calculator c= new Calculator(); @Test public void testAdd() { c.add( 2 ); c.add( 2 ); assertEquals( 4 ,c.getResult()); } @Test public void testSubstract() { c.substract( 2 ); assertEquals( 2 ,getResult()); } @Ignore public void testMultiply() { c.multiply( 10 ); } @Test (expected=Exception. class ) public void testDivide() throws Exception { c.divide( 0 ); } @Test (timeout= 1000 ) public void testSquareRoot() { c.squareRoot( 9 ); } } |
************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package com.imooc.test; public class Calculator { private static int result; //静态变量,用于存储运行结果 public void add( int n) { result=result+n; } public void substract( int n) { result=result- 1 ; //Bug:正确的应该是result=result-n; } public void multiply( int n) { //此方法尚未写好 } public void divide( int n) throws Exception{ if (n== 0 ) { throw new Exception( "除数不能为0" ); } result=result/n; } public void square( int n) { result=n*n; } public void squareRoot( int n) { for (;;); //Bug:死循环 } public void clear() { result= 0 ; } } |
Java数据库开发与实战应用2018版
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧