Advertisement
zaidhuda

Course.java

Nov 25th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. import java.util.concurrent.atomic.AtomicInteger;
  2. import java.util.ArrayList;
  3.  
  4. public class Course {
  5.     private static AtomicInteger nextId = new AtomicInteger();
  6.     final int id;
  7.     private ArrayList<Integer> availability = new ArrayList<Integer>(java.util.Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11));
  8.     private String code, title = null;
  9.     private int credit=0, requiredSections=1;
  10.    
  11.     public Course(String code){
  12.         constructor(code, null, 0, 1);
  13.         id = nextId.incrementAndGet();
  14.     }
  15.    
  16.     public Course(String code, String title){
  17.         constructor(code, title, 0, 1);
  18.         id = nextId.incrementAndGet();
  19.     }
  20.    
  21.     public Course(String code, String title, int credit){
  22.         constructor(code, title, credit, 1);
  23.         id = nextId.incrementAndGet();
  24.     }
  25.    
  26.     public Course(String code, String title, int credit, int requiredSections){
  27.         constructor(code, title, credit, requiredSections);
  28.         id = nextId.incrementAndGet();
  29.     }
  30.  
  31.     private void constructor(String code, String title, int credit, int requiredSections){
  32.         setCode(code);
  33.         setTitle(title);
  34.         setCredit(credit);
  35.         setRequiredSections(requiredSections);
  36.     }
  37.    
  38.     // setter methods
  39.     public void setCredit(int arg){ credit = arg; }
  40.     public void setRequiredSections(int arg){ requiredSections = arg; }
  41.     public void setTitle(String arg){ title = arg; }
  42.     public void addAvailability(int arg){ availability.add(arg); }
  43.     public void setCode(String arg){
  44.         if(!arg.equals(arg.split(" "))){
  45.             String[] split = arg.split(" ");
  46.             arg = "";
  47.             for (String str : split)
  48.                 arg+=str;
  49.         }
  50.         code = arg.toUpperCase();
  51.     }
  52.  
  53.     // getter methods
  54.     public int getCredit(){ return credit; }
  55.     public int getRequiredSections(){ return requiredSections; }
  56.     public String getCode(){ return code; }
  57.     public String getTitle(){ return title; }
  58.     public ArrayList<Integer> getAvailability(){ return availability; }
  59.  
  60.     @Override
  61.     public boolean equals(Object other) {
  62.         if (!(other instanceof Course))
  63.             return false;
  64.  
  65.         Course that = (Course) other;
  66.  
  67.         return this.code.equalsIgnoreCase(that.code);
  68.     }
  69.  
  70.     public String toString(){
  71.         String course = getCode() + " " + getTitle() + " " + getCredit();
  72.         return course;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement