183
社区成员




The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ?category=0 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/600546911 |
The Aim of This Assignment | Git/GitHub Using & Keywords Capturing |
MU STU ID and FZU STU ID | <19105584_831902124> |
https://github.com/WuDiancong/MU_EE308_lab2 |
---|
Personal Software Process Stages | Estimated Time/minutes | Completed Time/minutes |
---|---|---|
Planning | 30 | 30 |
Estimate | 15 | 15 |
Development | 15 | 15 |
Analysis | 60 | 100 |
Design Spec | 30 | 35 |
Design Review | 10 | 15 |
Coding Standard | 15 | 20 |
Design | 60 | 50 |
Coding | 720 | 1000 |
Code Review | 60 | 30 |
Test | 120 | 150 |
Reporting | 300 | 300 |
Test Report | 30 | 45 |
Size Measurement | 10 | 10 |
Postmortem&Process Improvement | 90 | 120 |
total | 1565 | 1935 |
After seeing the request for this lab, a few of us friends chose to meet up in the evening to discuss our individual ideas. It was not a team assignment though. But each person's unique thinking can ignite inspiration in others. Indeed!!! Our meeting of minds helped me gain a deeper understanding of how I should complete it.
I have chosen JAVA as my programming language for this lab. In fact, my friends have suggested that it would be much easier to use Python for this problem. But I'm not too good at Python yet. Between JAVA and C I chose JAVA.
I want to divide this task into sections and I can complete these sections separately and eventually compose them into a complete code.
Count the number of keywords.
Count the number of "switch case" structures and the number of "case" in each group.
Count the number of "if else" structures.
Count the number of "if, else if, else" structures.
By thinking about this and breaking it down, our task becomes much simpler and clearer. The rest is up to us to solve each of these problems individually.
First of all, I read the content of the text and preprocessed the data. All symbols and numbers were replaced by blank "".
Then create a new array and split the string into the array with "". After that, we started to solve problems according to different levels.
For Level_1, I just set up a keyword count and counted the number of keywords.
For Level_2, I first count the number of keywords "switch ". Then, for "case", I used a vector object and solved it.
For Level_3, I'm using nested for and while loops here. The basic logic is to find an "if" first, and from there, continue searching until an "else" appears. (This "else" cannot be "else if".)
Mark the two positions and search the two positions to determine if there is an "if else" or "if else-if else" on the two positions. Finally, it is divided into two cases for data processing.
For Level_4, we count the number of "if else "structures in Level_3 and find the relationship between the number of "if else" structures and the number of "if else-if else "structures.
And from this relationship, we get the number of if else-if else structures.
//Function of Level 1:count the number of all the keywords
public static int Level_1(String arr[],String key[]) {
int num_keyWords = 0;
for(int i=0;i < arr.length;i++){
for(int j=0;j < key.length;j++) {
if(arr[i].equals(key[j])) {
num_keyWords ++;
}
}
}
System.out.println("total num: " + num_keyWords);
return num_keyWords;
}
//Level 2: count the number of keywords switch and cases
public static int Level_2(String arr[],String key[]) {
int num_switch = 0;
for(int i=0;i < arr.length;i++) {
if(arr[i].equals("switch")) {
num_switch ++;
}
}
System.out.println("switch num: " + num_switch);
//count the number of "switch case" structures
Vector vec_case = new Vector(4);
int num_case = 0;
int index = -1;
for(int i=0;i < arr.length;i++) {
if(arr[i].equals("switch")) {
index++;
num_case=0;
}
if(arr[i].equals("case")) {
num_case++;
vec_case.add(index,num_case);
}
}
System.out.print("case num: ");
if(num_switch == 0) {
System.out.println(0);
}else {
for(int t=0;t <= index;t++) {
System.out.print(vec_case.get(t)+" ");
}
System.out.println();
}
return num_switch;
}
//Level 3: count the number of if-else structure
public static int Level_3(String arr[],String key[]) {
int num_if_else = 0;
for(int i=0;i<arr.length;i++) {
if(i!=0) {
if(arr[i].equals("if")&&!arr[i-1].equals("else")) {
int init = i + 1;
if(i<arr.length-2) {
while((!(arr[i+1].equals("else")&&!arr[i+2].equals("if")))&&i<arr.length-3) {
i++;
}
}else{
break;
}
int tmp = i;
boolean flag = false;
boolean flag2 = true;
for(int t = init;t<tmp;t++) {
if(arr[t].equals("if")&&!arr[t-1].equals("else")) {
for(int k = t;k<tmp;k++) {
if(arr[k].equals("else")) {
flag2 = false;
break;
}
}
if(flag2) num_if_else ++ ;
flag = true;
break;
}
}
if(flag) {
if(i<arr.length-2) {
while(!(arr[i+1].equals("else")&&!arr[i+2].equals("if"))) {
i++;
}
}else {
break;
}
num_if_else ++;
}
}
}
}
System.out.println("if-else num: "+num_if_else);
return num_if_else;
}
//Level 4:count the number of if-else if-else structure
public static int Level_4(String arr[],String key[]) {
int num_else = 0;
int num_if_else_if_else = 0;
int num_if_else = Level_3(arr,key);
for(int i=0;i<arr.length;i++) {
if(i < arr.length - 1) {
if(arr[i].equals("else")&&!arr[i+1].equals("if")) {
num_else ++;
}
}
if(i == arr.length-1) {
if(arr[i].equals("else")) {
num_else ++;
}
}
}
num_if_else_if_else = num_else - num_if_else;
System.out.println("if -else if- else num: "+num_if_else_if_else);
return num_if_else_if_else;
}
#include <stdio.h>
int main(){
int i = 1;
double j = 0;
long f;
switch(i){
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
switch(i){
case 0:
break;
case 1:
break;
default:
break;
}
if(i<0){
if(i<-1){}
else{}
}
else if(i>0){
if(i>2){}
else if(i==2){}
else if(i>1){}
else{}
}
else{
if(j!=0){}
else{}
}
return 0;
}
Input Data:
Please enter the path of the file:
C:\Users\wdclovemm\Desktop\EE308-软件工程\实验\lab2\test.txt
Please enter the completion level what we want:
4
Output Data:
total num: 35
switch num: 2
case num: 3 2
if-else num: 2
if -else if- else num: 2
Based on the results of our tests, we obtained a relatively high test coverage of the code, which clearly shows that the security of the code can be guaranteed.
During this experiment, I learned a lot of new things on my own through self-learning, and I was able to think outside the box and get inspired by sharing good ideas with friends.
I learned how to use GitHub, and how to upload code from local to GitHub.
I learnt how to think about the perspective and time frame of a formal software program.
I learned how to use Unit test coverage optimization and performance testing.
I learned a lot and received a lot through this experiment, and I thank my teacher for giving us this opportunity. Maybe my homework wasn't perfect, but I did it!
Special Thanks: Thanks to my friends Jian Lang for helping me with some technical stuff!