一、合同管理系统详细设计说明内容
系统管理模块
(1)分配合同管理:
●输入项目:
状态为“起草”的待分配合同信息,会签、审批和签订的人员信息。
(2)角色管理
●输入项目:
新增角色名称、角色权限信息。
查询统计模块
(1)合同信息查询管理:
●性能:提供快速准确的查询合同功能,查询条件为合同编号,响应时间在合理范围内,最终能能清晰展示查询结果。
●输入项日:合同编号
(2)合同流程查询管理:
●性能:提供快速准确的查询合同功能,查询条件为合同状态,响应时间在合理范围,且能清晰准确的展示合同列表
二、调色板程序功能调试
class Palette {
public int number; // 颜色数
private ColorX[] palette; // 颜色表
public Palette(ColorX[] palette,int number) {
this.number = number;
this.palette = palette;
}
// 新增下方的同名无参数构造函数,初始化颜色表数组
public Palette() {
this.number = 0;
this.palette = new ColorX[256]; // 假设最多256种颜色
}
public void addColor(ColorX color) {
this.palette[this.number] = color;
}
// 将上面红色的部分修改为完善addColor方法
public void addColor(ColorX color) {
if (number < palette.length) {
this.palette[this.number] = color;
this.number++; // 增加颜色计数
} else {
System.out.println("调色板已满,无法添加更多颜色");
}
}
2.请写出修正后的程序运行效果
运行结果:
0DDF20DB26D5D980BB44BEC639D6322996FA9B95CAFBB0C7DFEAA6D04611328556CB6464BDFAB8CD
写出改程序的运行结果:
这个程序定义了两个类:ColorX(颜色类)和 Palette(调色板类),并在 Draw 类的 main 方法中创建了一个调色板,并向其中添加了13种颜色,最后输出调色板的字符串表示
最终结果是一个颜色数量(2位十六进制) + 13种颜色的十六进制值(每个6位)的拼接字符串
三、股票买卖跟踪调试。
class Stock {
...
public Stock(String name, int quantity) {
name = name;
quantity = quantity;
this.name = name; // 修正:添加this
this.quantity = quantity; // 修正:添加this
}...
}
interface Order {
private void execute();
void execute(); // 修正:添加void,移除private
}
class BuyStock implements Order {
...
public void execute() {
buy();
stock.buy(); // 调用stock对象的buy方法
}
}
四、密码PasswordCheck单元测试。
考核内容:现PasswordCheck 类中有check函数,用来验证密码的有效性和其强弱。代码如下:
public class PasswordCheck {
public String check(String password) {
if (password.isEmpty()) {
return "错误";
}
int length = password.length();
if (length < 6) {
return "错误";
}
if (password.matches("[0-9a-z+]")){
return "弱密码";
}else {
return "强密码";
}
}
}
请针对check函数功能编写测试用例。
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class PasswordCheckTest {
private PasswordCheck checker = new PasswordCheck();
// 测试空密码
@Test
void testEmptyPassword() {
assertEquals("错误", checker.check(""));
}
// 测试长度不足的密码
@ParameterizedTest
@ValueSource(strings = {"", "a", "abcde"})
void testShortPasswords(String password) {
assertEquals("错误", checker.check(password));
}
// 测试弱密码(只包含小写字母和数字)
@ParameterizedTest
@ValueSource(strings = {"abcdef", "12345678", "abc123"})
void testWeakPasswords(String password) {
assertEquals("弱密码", checker.check(password));
}
// 测试强密码(包含大写字母或特殊字符)
@ParameterizedTest
@ValueSource(strings = {"Abcdef", "abc@123", "ABC123", "a1B2c3"})
void testStrongPasswords(String password) {
assertEquals("强密码", checker.check(password));
}
// 测试边界长度(刚好6个字符)
@Test
void testMinimumLength() {
assertEquals("弱密码", checker.check("abcdef"));
assertEquals("强密码", checker.check("Abc123"));
}
// 测试包含特殊字符的密码
@Test
void testWithSpecialCharacters() {
assertEquals("强密码", checker.check("abc@123"));
assertEquals("强密码", checker.check("!@#$%^&*"));
}
}
五、商品Casher单元测试。
考核内容:现Casher 类中有 compute 函数用来计算商品价格并根据情况打折和优惠。代码
如下:
public class Casher {
public double compute(int count, double price) {
double totalPrice = 0.0;
// 根据数量分级计算总价
if (count <= 10) {
totalPrice = count * price; // 基础价格
} else if (count <= 20) {
totalPrice = count * price * 0.9; // 10%折扣
} else {
totalPrice = count * price * 0.8; // 20%折扣
}
// 满300减30的优惠
totalPrice -= Math.floor(totalPrice / 300) * 30;
return totalPrice;
}
}
请针对compute 函数功能编写测试用例。
答案:备注:中文字是帮助你记忆的。
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class CasherTest {
private Casher casher = new Casher();
// 测试无折扣情况
@Test
void testNoDiscount() {
double result = casher.compute(5, 10.0);
assertEquals(50.0, result);
}
// 测试10%折扣
@Test
void test10PercentDiscount() {
double result = casher.compute(15, 20.0);
assertEquals(270.0, result);
}
// 测试20%折扣
@Test
void test20PercentDiscount() {
double result = casher.compute(25, 12.0);
assertEquals(240.0, result);
}
// 测试满减优惠
@Test
void testReduction() {
double result = casher.compute(20, 15.0); // 总价300元
assertEquals(270.0, result); // 满300减30
}
// 测试边界条件
@Test
void testBoundary() {
double result = casher.compute(10, 30.0); // 总价300元但数量触发10%折扣
assertEquals(240.0, result); // 折后270元,满减后240元
}
}
六、多线程售卖火车票。
public class TicketSalesSimulation {
private static final int TOTAL_TICKETS = 200;
private static int remainingTickets = TOTAL_TICKETS;
private static final Object lock = new Object();
public static void main(String[] args) {
// 创建3个售票窗口线程
Thread window1 = new Thread(new TicketWindow("窗口1"), "Window1");
Thread window2 = new Thread(new TicketWindow("窗口2"), "Window2");
Thread window3 = new Thread(new TicketWindow("窗口3"), "Window3");
// 启动线程
window1.start();
window2.start();
window3.start();
}
static class TicketWindow implements Runnable {
private final String windowName;
public TicketWindow(String name) {
this.windowName = name;
}
@Override
public void run() {
while (true) {
synchronized (lock) {
if (remainingTickets <= 0) {
break; // 票已售完
}
// 模拟售票时间
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 售票
int soldTicket = TOTAL_TICKETS - remainingTickets + 1;
System.out.printf("%s:\t已出售第%d张票%n", windowName, soldTicket);
remainingTickets--;
}
// 添加一点随机性,模拟现实中的处理时间差异
try {
Thread.sleep((long) (Math.random() * 50));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}