第一次试验 :
判断输入的三个数是什么三角形
#include<iostream>
using namespace std;
int main()
{ int a,b,c;
cin>>a>>b>>c;
if(a>0&&b>0&&c>0){
if((a<b+c)&&(b<a+c)&&(c<a+b)){
if(a==b&&b==c&&a==c){
cout<<"等边三角形";
return 0;
}
if(a==b||b==c||a==c){
cout<<"等腰三角形";
return 0;
} else{
cout<<"三角形" ;
return 0;
}
}else{
cout<<"不滿足";
}
}else{
cout<<"不滿足";
}
return 0;
}
package com.ruowei;
import java.util.Scanner;
/**
* @Auther: 隋全通
* @Date: 2019/3/12 13:02
* @Description:
* @param:
* @return:
*/
public class a {
public static void main(String[] args) {
int a, b, c;
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
if (a > 0 && b > 0 && c > 0) {
if (a < b + c && b < a + c && c < a + b) {
if (a == b || b == c || c == a) {
if (a == b && b == c && c == a) {
System.out.println("等边三角形");
}else {
System.out.println("等腰三角形");
}
} else {
System.out.println("是三角形");
}
} else {
System.out.println("不满足三角形");
}
} else {
System.out.println("不满足三角形");
}
}
}
实验二 等级类划分
package com.ruowei;
import java.util.Scanner;
/**
* @Auther: 隋全通
* @Date: 2019/3/12 13:02
* @Description:
* @param:
* @return:
*/
public class a {
public static void main(String[] args) {
int a;
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
a = scanner.nextInt();
System.out.println(a);
String a1 = String.valueOf(a);
int length = a1.length();
if (length == 6) {
String str= a1.substring(length-6,length-2);
Integer year = Integer.valueOf(str);
if(year>2000&&year<2006){
String str1= a1.substring(length-2,length);
Integer month = Integer.valueOf(str1);
if(month>1&&month<12){
System.out.println("在范围内");
}else {
System.out.println("输入月份有误");
}
}else {
System.out.println("输入的年份不在2001-2005之间");
}
} else {
System.out.println("请输入6位数字");
}
}
}
}
编写一个程序,输入某雇员的工作时间(以小时计)和每小时的工资数,计算并输出工资。具体如下:
(1)若雇员周工作小时小于40小时(0,40),则按原小时工资0.7来计算薪水。
(2)若雇员周工作小时等于40小时,则按原小时工资计算薪水。
(3)若雇员周工作小时介于40到50(40,50)小时的,超过40的部分按原小时工资的1.5倍计算薪水。
(4)若雇员周工作小时超过50小时(50,60),则超过50的部分按原小时工资的3倍来计算薪水;
(5)超出60小时或小于0小时,表示输入有误,需重新输入。
首先编写程序,然后结合黑盒测试方法中等价类划分和边界值方法设计测试用例,并给出相应的测试结果。
package javawebv;
import org.junit.Test;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Demo1 {
@Test
public void top1() throws IOException {
System.out.println("hello world");
Scanner scanner = new Scanner(System.in);
double i = scanner.nextDouble(); // 工时
double j = scanner.nextDouble();// 工资
System.out.println("工时:"+i + "工资:" + j);
if (i>=0&&i<=60) {
if (i >= 0 && i < 40) {
double sum = i * j * 0.7;
String sumdouble = formatDouble4(sum);
System.out.println(sumdouble);
}
if(i==40.0){
double sum = i * j;
String sumdouble = formatDouble4(sum);
System.out.println(sumdouble);
}
if (i > 40 && i <= 50) {
double sum = 40 * j + (i - 40) * j * 1.5;
System.out.println(sum);
}
if (i > 50 && i <= 60) {
double sum = 40 * j + 10 * j * 1.5 + (i - 50) * j * 3;
System.out.println(sum);
}
} else {
System.out.println("输入有误,请重新输入");
}
}
public static String formatDouble4(double d) {
DecimalFormat df = new DecimalFormat("#.00");
return df.format(d);
}
}