Advertisement
Guest User

DeclareMajor

a guest
Mar 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.util.ArrayList;
  2. /**
  3.  *
  4.  */
  5. public class DeclareMajor
  6. {
  7.     public static void main(String[] args){
  8.         //ArrayList<String> cs = new ArrayList();
  9.         Subject math = new Subject("Math","Mathematics");
  10.         Subject cs = new Subject("CS","Computer Science");
  11.        
  12.         Student sam = new Student("Samantha","Jones",'F',true);
  13.         Student rob = new Student("Robert","Smith",'M',true);
  14.         Student jill = new Student("Jill","Lee",'F',true);
  15.         // the majors
  16.  
  17.         sam.setMajor(cs);
  18.         cs.addMajor(sam);
  19.         rob.setMajor(cs);
  20.         cs.addMajor(rob);
  21.         jill.setMajor(math);
  22.         math.addMajor(jill);
  23.        
  24.         System.out.println("Math majors = "+math.getMajors());        
  25.         System.out.println("cs= " +cs.getMajors());
  26.              
  27.         //int pos = cs.indexOf("Robert");
  28.         //String removed = cs.remove(0);
  29.         if (cs.contains(rob)) {
  30.             cs.removeMajor(rob);
  31.             rob.setMajor(math);
  32.             cs.addMajor(rob);
  33.         }
  34.         //System.out.println(pos);
  35.         System.out.println("get Rob's full name " + rob.getFullName());
  36.         System.out.println("new Math majors = "+math.getMajors());        
  37.         System.out.println("new cs= " +cs.getMajors());
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement