Restore
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question1</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>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
|
||||
public class Assignment {
|
||||
//instance variables
|
||||
private Code myCode;
|
||||
private int score;
|
||||
private boolean submitted;
|
||||
private String name;
|
||||
|
||||
//constructor
|
||||
public Assignment(Code myCode, boolean submitted, String name) {
|
||||
this.myCode = myCode;
|
||||
this.submitted = submitted;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//methods
|
||||
public void submit() {this.submitted = true;}
|
||||
|
||||
public boolean isSubmitted() {return this.submitted;}
|
||||
|
||||
public int getScore() {return this.score;}
|
||||
|
||||
public void setScore(int score) {this.score = score;}
|
||||
|
||||
public String getName() {return this.name;}
|
||||
|
||||
public Code getCode() {return this.myCode;}
|
||||
|
||||
//test
|
||||
public static void testAssignment() {
|
||||
// Test for the constructor
|
||||
Code code0=new Code();
|
||||
Assignment a0=new Assignment(code0,false,"xiaoyu");
|
||||
System.out.println(a0.getName()=="xiaoyu");
|
||||
System.out.println(a0.isSubmitted()==false);
|
||||
//Test for code
|
||||
//the default code can not be run
|
||||
System.out.println(a0.getCode().run()==false);
|
||||
//Test for submit
|
||||
a0.submit();
|
||||
System.out.println(a0.isSubmitted()==true);
|
||||
//Test for score
|
||||
a0.setScore(15);
|
||||
System.out.println(a0.getScore()==15);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
public class Code {
|
||||
//instance variables
|
||||
private boolean canRun;
|
||||
private boolean canCompile;
|
||||
private int lines;
|
||||
|
||||
//constructors
|
||||
public Code() {
|
||||
this.canRun = false;
|
||||
this.canCompile = false;
|
||||
this.lines = 0;
|
||||
}
|
||||
|
||||
public Code(boolean canCompile, boolean canRun, int lines) {
|
||||
this.canRun = canRun;
|
||||
this.canCompile = canCompile;
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
//methods
|
||||
public boolean compile() {return this.canCompile;}
|
||||
|
||||
public boolean run() {return this.canRun;}
|
||||
|
||||
public void debug() {
|
||||
this.canRun = true;
|
||||
this.canCompile = true;
|
||||
}
|
||||
|
||||
public void coding(int lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
public int countLines() {return this.lines;}
|
||||
|
||||
//test
|
||||
public static void testCode() {
|
||||
// Test for the first constructor,the default values both should be false.
|
||||
Code code1=new Code();
|
||||
System.out.println(code1.compile()==false );
|
||||
System.out.println(code1.run()==false );
|
||||
//Test for the second constructor,set the values
|
||||
Code code2=new Code(true,false, 100);
|
||||
System.out.println(code2.compile()==true );
|
||||
System.out.println(code2.run()==false );
|
||||
System.out.println(code2.countLines()==100);
|
||||
// Test Debug.
|
||||
code2.debug();
|
||||
//Then code should can both compile and run.
|
||||
System.out.println(code2.compile()==true );
|
||||
System.out.println(code2.run()==true );
|
||||
// Test Coding & countLines
|
||||
code2.coding(15);
|
||||
System.out.println(code2.countLines()==15);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Code.testCode();
|
||||
Assignment.testAssignment();
|
||||
Student.testStudent();
|
||||
Teacher.testTeacher();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
public class Student {
|
||||
//instance variables
|
||||
private Assignment myAssignment = null;
|
||||
private boolean honest = true;
|
||||
private String name;
|
||||
|
||||
//constructor
|
||||
public Student(String name, boolean honest) {
|
||||
this.name = name;
|
||||
this.honest = honest;
|
||||
}
|
||||
|
||||
//methods
|
||||
public Assignment getAssignment(){return this.myAssignment;}
|
||||
|
||||
public void writeAssignment(Assignment a) {this.myAssignment = a;}
|
||||
|
||||
public void copyAssignment(Assignment a) {
|
||||
//if the names are different
|
||||
if(a.getName() != this.name) {this.myAssignment = a;}
|
||||
}
|
||||
|
||||
public String getName() {return this.name;}
|
||||
|
||||
//test
|
||||
public static void testStudent() {
|
||||
Assignment a1=new Assignment(null,true,"xiaoxue");
|
||||
//create 2 students to test
|
||||
Student stu1=new Student("xiaoxue",true);
|
||||
Student stu2=new Student("xiaoyu",false);
|
||||
System.out.println(stu1.getName()=="xiaoxue");
|
||||
System.out.println(stu2.getName()=="xiaoyu");
|
||||
//Student1 Write assignment
|
||||
stu1.writeAssignment(a1);
|
||||
//get Student1's assignment
|
||||
Assignment assignment1=stu1.getAssignment();
|
||||
//Student2 Copy that assignment
|
||||
stu2.copyAssignment(assignment1);
|
||||
//stu2's name should NOT be equal with the name variable in the copied assignment object
|
||||
System.out.println((stu2.getName()==assignment1.getName())==false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
|
||||
public class Teacher {
|
||||
//instance variable
|
||||
private String name;
|
||||
|
||||
//constructor
|
||||
public Teacher(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//method
|
||||
public int grading(Student s) {
|
||||
//if no assignment submitted
|
||||
if(s.getAssignment() == null) return 0;
|
||||
//if the student copied
|
||||
if(s.getAssignment().getName() != s.getName()) return 0;
|
||||
//if submitted not on time
|
||||
if(s.getAssignment().isSubmitted() == false) return 0;
|
||||
//if cannot compile
|
||||
if(s.getAssignment().getCode().compile() == false) return 0;
|
||||
//if cannot run
|
||||
if(s.getAssignment().getCode().run() == false) return 50;
|
||||
//if code lines < 100
|
||||
if(s.getAssignment().getCode().countLines() < 100) return 80;
|
||||
//code lines >= 100
|
||||
else return 100;
|
||||
}
|
||||
|
||||
//test
|
||||
public static void testTeacher() {
|
||||
//set one teacher named xyz
|
||||
Teacher t1=new Teacher("xyz");
|
||||
//tests for grading
|
||||
//4 kinds of code
|
||||
Code code1=new Code(true,true, 50);
|
||||
Code code2=new Code(true,false,120);
|
||||
Code code3=new Code();
|
||||
Code code4=new Code(true,true, 120);
|
||||
//set 6 different students
|
||||
//not submit,score 0
|
||||
Assignment a1=new Assignment(code1,false,"abin");
|
||||
Student stu1=new Student("abin",true);
|
||||
stu1.writeAssignment(a1);
|
||||
System.out.println(t1.grading(stu1)==0);
|
||||
//Copying ,score 0
|
||||
Student stu2=new Student("huanfeng",false);
|
||||
stu2.copyAssignment(a1);
|
||||
System.out.println(t1.grading(stu1)==0);
|
||||
//submitted , cannot compile, score 0
|
||||
Assignment a2=new Assignment(code3,true,"Potter");
|
||||
Student stu3=new Student("potter",true);
|
||||
stu3.writeAssignment(a2);
|
||||
System.out.println(t1.grading(stu3)==0);
|
||||
//submitted , can compile, cannot run ,score 50
|
||||
Assignment a3=new Assignment(code2,true,"Ron");
|
||||
Student stu4=new Student("Ron",true);
|
||||
stu4.writeAssignment(a3);
|
||||
System.out.println(t1.grading(stu4)==50);
|
||||
//submitted , can compile, can run, code lines <100 ,score 80
|
||||
Assignment a4=new Assignment(code1,true,"Lupin");
|
||||
Student stu5=new Student("Lupin",true);
|
||||
stu5.writeAssignment(a4);
|
||||
System.out.println(t1.grading(stu5)==80);
|
||||
//submitted , can compile, can run, code lines >100 ,score 100
|
||||
Assignment a5=new Assignment(code4,true,"Hermione");
|
||||
Student stu6=new Student("Hermione",true);
|
||||
stu6.writeAssignment(a5);
|
||||
System.out.println(t1.grading(stu6)==100);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user