forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lenovo2512009/master
提交 第一次和第二次的java作业
- Loading branch information
Showing
15 changed files
with
603 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="lib" path="E:/code/编程群/dom4j-1.6.1.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>coding</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package coding.week01; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[2]; | ||
|
||
public void add(Object o){ | ||
int len = elementData.length; | ||
if(size >= len){ | ||
Object[] new_elmentData = new Object[len*2]; | ||
System.arraycopy(elementData, 0, new_elmentData, 0, size); | ||
elementData = new_elmentData; | ||
} | ||
elementData[size] = o; | ||
size ++; | ||
} | ||
public void add(int index, Object o){ | ||
if(index >= size){ | ||
throw new RuntimeException("下标越界"); | ||
} | ||
Object[] new_elementData = new Object[size+1]; | ||
System.arraycopy(elementData, 0, new_elementData, 0, index); | ||
System.arraycopy(elementData, index, new_elementData, index+1, size-index); | ||
new_elementData[index] = o; | ||
elementData = new_elementData; | ||
size++; | ||
} | ||
|
||
public Object get(int index){ | ||
if(index >= size){ | ||
throw new RuntimeException("下标越界"); | ||
} | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
if(index >= size){ | ||
throw new RuntimeException("下标越界"); | ||
} | ||
Object oldElement = elementData[index]; | ||
if((index+1) != size){ | ||
System.arraycopy(elementData, index+1, elementData, index, size-index-1); | ||
} | ||
elementData[size-1] = null; | ||
size --; | ||
return oldElement; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String s = "{"; | ||
for (int i = 0; i < size; i++) { | ||
if(i == (size -1)){ | ||
s += elementData[i] + "}"; | ||
}else{ | ||
s += elementData[i]+","; | ||
} | ||
} | ||
return s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package coding.week01; | ||
|
||
public class BinaryTreeNode { | ||
|
||
private Object data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
|
||
public Object getData() { | ||
return data; | ||
} | ||
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
public BinaryTreeNode getLeft() { | ||
return left; | ||
} | ||
public void setLeft(BinaryTreeNode left) { | ||
this.left = left; | ||
} | ||
public BinaryTreeNode getRight() { | ||
return right; | ||
} | ||
public void setRight(BinaryTreeNode right) { | ||
this.right = right; | ||
} | ||
|
||
public BinaryTreeNode insert(Object o){ | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package coding.week01; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package coding.week01; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private int size; | ||
|
||
public LinkedList(){ | ||
head = new Node(new Object(),null,null); | ||
} | ||
|
||
public void add(Object o){ | ||
Node last = head; | ||
for (int i = 0; i < size; i++) { | ||
last = last.next; | ||
} | ||
Node newNode = new Node(o,null,last); | ||
last.next = newNode; | ||
size++; | ||
} | ||
public void add(int index , Object o){ | ||
Node oldNode = getNode(index); | ||
Node newNode = new Node(o, oldNode, oldNode.prev); | ||
oldNode.prev.next = newNode; | ||
oldNode.prev = newNode; | ||
size ++; | ||
} | ||
public Object get(int index){ | ||
Node node = getNode(index); | ||
return node.data; | ||
} | ||
|
||
private Node getNode(int index){ | ||
Node n = head.next; | ||
for (int i = 0; i < index; i++) { | ||
n = n.next; | ||
} | ||
return n; | ||
} | ||
|
||
public Object remove(int index){ | ||
Node node = getNode(index); | ||
Object o =node.data; | ||
Node prevNode = node.prev; | ||
Node nextNode = node.next; | ||
prevNode.next = nextNode; | ||
nextNode.prev = prevNode; | ||
node.next = node.prev =null; | ||
node.data = null; | ||
size --; | ||
return o; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
add(0,o); | ||
} | ||
public void addLast(Object o){ | ||
add(o); | ||
} | ||
public Object removeFirst(){ | ||
Object o = remove(0); | ||
return o; | ||
} | ||
public Object removeLast(){ | ||
Object o = remove(size); | ||
return o; | ||
} | ||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
Node prev; | ||
|
||
public Node(Object o,Node next,Node prev){ | ||
this.data = o; | ||
this.next = next; | ||
this.prev = prev; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String s = "{"; | ||
Node n = head; | ||
for (int i = 0; i < size; i++) { | ||
n = n.next; | ||
if(i == (size -1)){ | ||
s += n.data; | ||
}else{ | ||
s += n.data + ","; | ||
} | ||
} | ||
s += "}"; | ||
return s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package coding.week01; | ||
|
||
public interface List { | ||
public void add(Object o); | ||
public void add(int index, Object o); | ||
public Object get(int index); | ||
public Object remove(int index); | ||
public int size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package coding.week01; | ||
|
||
public class Queue { | ||
private LinkedList list = new LinkedList(); | ||
|
||
public void enQueue(Object o){ | ||
list.add(o); | ||
} | ||
|
||
public Object deQueue(){ | ||
if(isEmpty()){ | ||
throw new RuntimeException("已为空"); | ||
} | ||
Object o = list.get(0); | ||
list.remove(0); | ||
return o; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
if(size() == 0){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
|
||
public int size(){ | ||
return list.size(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return list.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package coding.week01; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
public Object pop(){ | ||
if(isEmpty()){ | ||
throw new RuntimeException("已为空"); | ||
} | ||
Object o = elementData.get(elementData.size()-1); | ||
elementData.remove(elementData.size()-1); | ||
return o; | ||
} | ||
|
||
public Object peek(){ | ||
Object o = elementData.get(elementData.size()-1); | ||
return o; | ||
} | ||
public boolean isEmpty(){ | ||
int size = elementData.size(); | ||
if(size == 0){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
public int size(){ | ||
return elementData.size(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return elementData.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package coding.week02; | ||
|
||
public class LoginAction { | ||
|
||
private String name; | ||
private String passWord; | ||
private String message; | ||
public String getName() { | ||
return name; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public String getPassWord() { | ||
return passWord; | ||
} | ||
public void setPassWord(String passWord) { | ||
this.passWord = passWord; | ||
} | ||
public String getMessage() { | ||
return message; | ||
} | ||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
public String execute(){ | ||
if ("test".equals(name) && "1234".equals(passWord)) { | ||
this.message = "login successful"; | ||
return "success"; | ||
} | ||
this.message = "login failed,please check your user/pwd"; | ||
return "fail"; | ||
} | ||
} |
Oops, something went wrong.