第一周
1. Bowling Game 计分程序
2. TDD Bowling Game 接口向
3. Bowling Game 接口向编程、递归及Junit
package traing.bowling.impl;
/*
*
* if--else 可改三元表达式
*/
import java.util.*;
public class Bowling{
public static int calculate(int[][] turns) { //calculate scores
if(!(isTurnValid(turns))&&!(isGameValid(turns))) { //when it is valid data
int score=0;
for(int i=0;i<10;i++) {
if(!isStrike(turns[i])&&isMiss(turns[i])) { //when it is Miss(Against not found pointer)
score=score+turns[i][0]+turns[i][1];
}else if(!isStrike(turns[i])&&isSpare(turns[i])) { //when it is Spare
score=score+10+turns[i+1][0];
}else if(isStrike(turns[i])&&!isStrike(turns[i+1])) { //when it is Strike and the next is not Strike
score=score+10+turns[i+1][0]+turns[i+1][1];
}else if(isStrike(turns[i])&&isStrike(turns[i+1])) { //when it is Strike and the next is Strike
score=score+20+turns[i+2][0];
}
}
return score;
}else { //when it is invalid data
System.out.println("invalid");
return -1;
}
}
private static boolean isStrike(int[] turn) { //isStrike
if(turn[0]==10) {
return true;
}
return false;
}
private static boolean isSpare(int[] turn) { //isSpare
if(turn[0]+turn[1]==10) {
return true;
}
return false;
}
private static boolean isMiss(int[] turn) { //isMiss
if(turn[0]+turn[1]<10) {
return true;
}
return false;
}
private static boolean isTurnValid(int[][] turns) { //invalid turns
int turns_row=turns.length;
if((turns_row>12)||(turns_row<10)) { //the length of turns is not lower than 10 or higher than 12
return true;
}
return false;
}
private static boolean isGameValid(int[][] turns) { //invalid data
int turns_row=turns.length; //the length of turns
for(int i=0;i<turns_row;i++) {
int turns_line=turns[i].length;
if((turns_line<=2)&&(turns_line>0)) { //it is only twice for one round
for(int j=0;j<turns_line;j++) {
if((turns[i][j]<0)||(turns[i][j]>10)) { //the score for once is not lower than 0 or higher than 10
return true;
}
}
if(turns_line==1) {
if((turns[i][0]!=10)&&(i!=turns_row-1)) {//only one data of a round for two conditions:
//10 or the last time
return true;
}
}
if(turns_line==2) { //when the sum of two data for one round is higher than 10
if(turns[i][0]+turns[i][1]>10) {
return true;
}
}
}else { //when more than twice for one round
return true;
}
}
//the conditions for the tenth round
if((isStrike(turns[9]))&&(turns_row==10)) { //the ten round is Strike
//and the length of turns is mistake
return true;
}
if((isStrike(turns[9]))&&(isStrike(turns[10]))&&(turns_row!=12)) {//the tenth round is Strike
//and the eleventh round is Strike
//and the length of turns is mistake
return true;
}
if((isStrike(turns[9]))&&(!isStrike(turns[9]))&&(turns_row!=11)) {//the tenth round is Strike
//and the eleventh round is not Strike
//and the length of turns is mistake
return true;
}
if((!isStrike(turns[9]))&&(isSpare(turns[9]))&&(turns_row!=11)) {//the tenth round is Spare
//and the length of turns is mistake
return true;
}
if((!isStrike(turns[9]))&&(isMiss(turns[9]))&&(turns_row!=10)) {//the tenth round is Miss
//and the length of turns is mistake
return true;
}
return false;
}
public static void main(String[] args) {
//test
int[][] turns1= {{10},{10},{10},{10},{10},{10},{10},{10},{10},{10},{10},{10}};
int[][] turns2= {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
int[][] turns3= {{10},{10},{10},{10},{10},{10},{10},{10},{10},{10},{3,7}};
int[][] turns4= {{10},{10},{10},{10},{10},{10},{10},{10},{10},{1,9},{10}};
int[][] turns5= {{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5,5},{5}};
int[][] turns6= {{-1,-4},{11,-1}};
int[][] turns7= {{10},{10},{10},{10},{10},{10},{10},{10},{10},{10},{3,8}};
int[][] turns8= {{10},{10},{10},{10},{10},{10},{10},{10},{10},{10},{10},{7}};
System.out.println(calculate(turns1));
System.out.println(calculate(turns2));
System.out.println(calculate(turns3));
System.out.println(calculate(turns4));
System.out.println(calculate(turns5));
System.out.println(calculate(turns6));
System.out.println(calculate(turns7));
System.out.println(calculate(turns8));
}
}
https://github.com/carolyyyy/bowling
https://github.com/carolyyyy/adv-bowling
第二周
IBM Robocode
-
此链接为原始battlecity源码,下载后推荐使用IDEA build 项目,当出现out文件夹后,运行battlecity/libs/robocode.jar即可
-
此链接为我参考的论文,及根据这个论文写出的源码
第三周
Trading System Web Demo
以上为题目描述,总结下来就是做一个基于WEB的交易系统,trader可以创建trade,user也可以创建trade,若后台判定是同一条trade,则会自动匹配,trade涉及更删改查操作。trader可更改trade价格以匹配用户,但是有一定范围,若超出范围,后台会自动判定reject,否则为accept。
前端我们采用的是vue,后台是java。由于时间有限,只是完成了项目基础功能,仅供学习使用。
https://github.com/carolyyyy/Trading-System