Created
April 25, 2015 09:36
-
-
Save ad-m/d3cce797960df544b070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package v1; | |
| import java.util.LinkedList; | |
| import java.util.Scanner; | |
| public abstract class Algorithm { | |
| protected LinkedList<Integer> datas = new LinkedList<Integer>(); | |
| public Scanner sc = new Scanner(System.in); | |
| public Algorithm() { | |
| } | |
| private void load(){ | |
| System.out.println("How much number do you want to load?"); | |
| for(int count = sc.nextInt(); count>0; count--){ | |
| Integer row = (Integer) sc.nextInt(); | |
| this.datas.add(row); | |
| } | |
| } | |
| protected abstract void operation(); | |
| private void print(){ | |
| System.out.println(datas); | |
| } | |
| public void action(int step){ | |
| if(step ==1){ | |
| this.load(); | |
| }else if(step == 2){ | |
| this.operation(); | |
| }else if(step == 3){ | |
| this.print(); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class ArrayStack implements Stack{ | |
| private int[] datas; | |
| private int count=0; | |
| public ArrayStack(int size) { | |
| this.datas = new int[size]; | |
| } | |
| @Override | |
| public void push(int val){ | |
| this.datas[count++] = val; | |
| } | |
| @Override | |
| public int popd(){ | |
| return this.datas[count--]; | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public abstract class Person { | |
| String firstName; | |
| String secondName; | |
| public Person(String firstName, String secondName) { | |
| super(); | |
| this.firstName = firstName; | |
| this.secondName = secondName; | |
| } | |
| public String getFirstName() { | |
| return firstName; | |
| } | |
| public void setFirstName(String firstName) { | |
| this.firstName = firstName; | |
| } | |
| public String getSecondName() { | |
| return secondName; | |
| } | |
| public void setSecondName(String secondName) { | |
| this.secondName = secondName; | |
| } | |
| public String getName(){ | |
| return this.firstName+" "+this.secondName; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Person [firstName=" + firstName + ", secondName=" + secondName | |
| + "]"; | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class PersonSet { | |
| private Person[] bank; | |
| private int count=0; | |
| public PersonSet(int size) { | |
| this.bank = new Person[size]; | |
| } | |
| public void add(Person obj){ | |
| this.bank[count++] = obj; | |
| }; | |
| public Person pop(Person obj){ | |
| return this.bank[count--]; | |
| } | |
| public void printAll(){ | |
| for(int i=0; i<count; i++){ | |
| System.out.println((i+1)+". "+this.bank[i]); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class PersonSetTest { | |
| public PersonSetTest() { | |
| // TODO Auto-generated constructor stub | |
| } | |
| public static void main(String[] args) { | |
| PersonSet set = new PersonSet(10); | |
| Student p = new Student("John", "Smith"); | |
| System.out.println(p); | |
| set.add(p); | |
| TeachingStaff ts = new TeachingStaff("John", "Smith", 5); | |
| System.out.println(ts); | |
| set.add(ts); | |
| TechnicalStaff ts2 = new TechnicalStaff("John", "Smith", 5); | |
| System.out.println(ts2); | |
| set.add(ts2); | |
| System.out.println("\tPerson list:"); | |
| set.printAll(); | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class Researcher extends Staff{ | |
| public int degree; | |
| public Researcher(String firstName, String secondName, int degree) { | |
| super(firstName, secondName); | |
| this.degree = degree; | |
| } | |
| public Researcher(String firstName, String secondName) { | |
| super(firstName, secondName); | |
| // TODO Auto-generated constructor stub | |
| } | |
| public int getDegree() { | |
| return degree; | |
| } | |
| public void setDegree(int degree) { | |
| this.degree = degree; | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| import java.util.Collections; | |
| public class ReverseAlgorithm extends Algorithm { | |
| public ReverseAlgorithm() { | |
| // TODO Auto-generated constructor stub | |
| } | |
| @Override | |
| protected void operation() { | |
| Collections.reverse(this.datas); | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| import java.util.Collections; | |
| public class SortAlgorithm extends Algorithm { | |
| public SortAlgorithm() { | |
| // TODO Auto-generated constructor stub | |
| } | |
| @Override | |
| protected void operation() { | |
| Collections.sort(this.datas); | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| import java.util.Collections; | |
| public class SortReverseAlgorithm extends Algorithm { | |
| public SortReverseAlgorithm() { | |
| // TODO Auto-generated constructor stub | |
| } | |
| @Override | |
| protected void operation() { | |
| Collections.sort(this.datas); | |
| Collections.reverse(this.datas); | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public interface Stack { | |
| public abstract void push(int v); | |
| public abstract int popd(); | |
| } |
This file contains hidden or 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
| package v1; | |
| public abstract class Staff extends Person { | |
| public Staff(String firstName, String secondName) { | |
| super(firstName, secondName); | |
| // TODO Auto-generated constructor stub | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class Student extends Person { | |
| public Student(String firstName, String secondName) { | |
| super(firstName, secondName); | |
| // TODO Auto-generated constructor stub | |
| } | |
| @Override | |
| public String toString() { | |
| return "Student [getName()=" + getName() + "]"; | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class TeachingStaff extends Staff { | |
| public int hours; | |
| public TeachingStaff(String firstName, String secondName) { | |
| super(firstName, secondName); | |
| } | |
| public TeachingStaff(String firstName, String secondName, int degree) { | |
| super(firstName, secondName); | |
| hours = degree; | |
| } | |
| public int getHours() { | |
| return hours; | |
| } | |
| public void setHours(int hours) { | |
| this.hours = hours; | |
| } | |
| @Override | |
| public String toString() { | |
| return "TeachingStaff [Degree=" + hours + ", getName()=" + getName() | |
| + "]"; | |
| } | |
| } |
This file contains hidden or 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
| package v1; | |
| public class TechnicalStaff extends Staff{ | |
| int DepartmentId; | |
| public TechnicalStaff(String firstName, String secondName, int departmentId) { | |
| super(firstName, secondName); | |
| DepartmentId = departmentId; | |
| } | |
| public int getDepartmentId() { | |
| return DepartmentId; | |
| } | |
| public void setDepartmentId(int departmentId) { | |
| DepartmentId = departmentId; | |
| } | |
| @Override | |
| public String toString() { | |
| return "TechnicalStaff [DepartmentId=" + DepartmentId + ", getName()=" | |
| + getName() + "]"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment