20155316 实验一《Java开发环境的熟悉》实验报告
一、命令行下Java程序的开发
按照老师提供的步骤,运行程序如下:
二、IDEA下Java程序开发、调试
设置条件断点如下:
三、练习题
实现四则运算,并进行测试
- 实现效果:实现任意两个整数的加减乘除,用户能自己选择。
- 编写的代码:
import java.io.*;
import java.util.*;
class FourCal {
static int plus(int num1, int num2) {
return num1 + num2;
}
static int substract(int num1, int num2) {
return num1 - num2;
}
static int multiply(int num1, int num2) {
return num1*num2;
}
static double divide(int num1, int num2) {
return (double)num1/num2;
}
}
public class Calculate {
public static void main(String[] args) {
int num1, num2;
String op;
Scanner scanner = new Scanner(System.in);
System.out.println("What do you want to caculate?(+ - * /)");
op = scanner.next();
System.out.print("num1:");
num1 = scanner.nextInt();
do {
System.out.print("num2:");
num2 = scanner.nextInt();
if (op.equals("/") && num2 == 0) System.out.println("Error! num2>0");
else break;
}while(true);
System.out.print("Result: ");
switch(op) {
case "+" :
System.out.printf("%d", FourCal.plus(num1, num2)); break;
case "-" :
System.out.printf("%d", FourCal.substract(num1, num2)); break;
case "*" :
System.out.printf("%d", FourCal.multiply(num1, num2)); break;
case "/" :
System.out.printf("%f", FourCal.divide(num1, num2)); break;
}
System.out.println();
}
}
- 实例展示(运行截图)
PSP时间估计
步骤 | 耗时 | 百分比 |
---|---|---|
需求分析 | 5 | 10% |
设计 | 5 | 10% |
代码实现 | 30 | 60% |
测试 | 5 | 10% |
分析总结 | 5 | 10% |