2021-05-12

内容:
步骤:

  1. 算法分析
    设计函数随机类
    public class getrandom {
    public int getnum() {
    Random x = new Random();
    int data =0;
    data=x.nextInt(12)+1;
    return data;
    }

}获取随机数
函数转换类,将数字转换为卡牌
public class transform {
public int[] transform() {
int[] num = new int[4];
getrandom n = new getrandom();
getrandom t = new getrandom();
for(int i=0;i<4;i++) {
num[i] = t.getnum();
}
int x = 0;
ArrayList list1 = new ArrayList();
for(int i=0;i<4;i++)
{
x = n.getnum();
if(x1){
list1.add(‘A’);
}
else if(x
2) {
list1.add(2);
}
else if(x3) {
list1.add(3);
}
else if(x
4) {
list1.add(4);
}
else if(x5) {
list1.add(5);
}
else if(x
6) {
list1.add(6);
}
else if(x7) {
list1.add(7);
}
else if(x
8) {
list1.add(8);
}
else if(x9) {
list1.add(9);
}
else if(x
10) {
list1.add(10);
}
else if(x11) {
list1.add(‘J’);
}
else if(x
12) {
list1.add(‘Q’);
}
else if(x==13) {
list1.add(‘K’);
}
}
System.out.println(list1);
return num;
}
}
设计ca类,计算24
public static int calcute(int count1, int count2, char operator)
计算加减乘除
public static void calculate(int[] number)
排列组合加减乘除
public static void calculation(int num1, int num2, int num3, int num4)
输出表达式
2. 概要设计(包括数据结构及算法绘制流程图或伪代码表示)

  1. 测试(设计测试用例或测试代码的设计与实现,测试结果截屏))

测试随机类
测试转换类

  1. 调试(对测试出的问题进行调试,界面截屏,调试修正编码)
    无法将数据转换为卡牌,用arrylist来转换
    ArrayList list1 = new ArrayList();
    for(int i=0;i<4;i++)
    {
    x = n.getnum();
    if(x1){
    list1.add(‘A’);
    }
    else if(x
    2) {
    list1.add(2);
    }
    else if(x3) {
    list1.add(3);
    }
    else if(x
    4) {
    list1.add(4);
    }
    else if(x5) {
    list1.add(5);
    }
    else if(x
    6) {
    list1.add(6);
    }
    else if(x7) {
    list1.add(7);
    }
    else if(x
    8) {
    list1.add(8);
    }
    else if(x9) {
    list1.add(9);
    }
    else if(x
    10) {
    list1.add(10);
    }
    else if(x11) {
    list1.add(‘J’);
    }
    else if(x
    12) {
    list1.add(‘Q’);
    }
    else if(x==13) {
    list1.add(‘K’);
    }
    }
    在caculation函数种无法直接调取数组,将数组分别赋值在三个int 变量中,作为参数引入
    public static void calculation(int num1, int num2, int num3, int num4)
  2. 心得体会(关键问题的解决思路及步骤总结)
    在进行转换时要注意存储的数据结构,要转换数据结构,在设计此算法,将数据分类,分类对应不同的随机组合的加减乘除关系,最后将表达式输出,在判断时使用flag,通过flag来判断是否输出表达式。

java实现24点问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值