Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.92 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Driver {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner keyboard = new Scanner(System.in);
  8.         ArrayList<Course> courselist = new ArrayList<Course>();
  9.         ArrayList<Instructor> instructorList = new ArrayList<Instructor>();
  10.         ArrayList<TeachingAssistant> taList = new ArrayList<TeachingAssistant>();
  11.  
  12.         while (true) {
  13.             String input = keyboard.nextLine();
  14.             String[] splitted = input.split(";");
  15.             if (input.equalsIgnoreCase("exit")) {
  16.                 System.exit(0);
  17.             }
  18.  
  19.             if (splitted[0].equalsIgnoreCase("create")) {
  20.                 if (splitted[1].equalsIgnoreCase("course")) {
  21.                     for (int i = 0; i <= courselist.size(); i++) {
  22.                         if (i == courselist.size()) {
  23.                             Course CO = new Course(splitted[2], splitted[3], splitted[4], splitted[5], splitted[6]);
  24.                             courselist.add(CO);
  25.                             System.out.println("success");
  26.                             break;
  27.                         }
  28.                         if (courselist.get(i).getCode().equalsIgnoreCase(splitted[2])) {
  29.                             System.out.println("A course with code " + splitted[2] + " already exists.");
  30.                             break;
  31.                         }
  32.                     }
  33.  
  34.                 }
  35.                 if (splitted[1].equalsIgnoreCase("instructor")) {
  36.                     for (int i = 0; i <= instructorList.size(); i++) {
  37.                         if (i == instructorList.size()) {
  38.                             Instructor IN = new Instructor(splitted[2], splitted[3], splitted[4], splitted[5]);
  39.                             instructorList.add(IN);
  40.                             System.out.println("success");
  41.                             break;
  42.                         }
  43.                         if (instructorList.get(i).getID().equalsIgnoreCase(splitted[3])) {
  44.                             System.out.println("A person with ID " + splitted[3] + " already exists.");
  45.                             break;
  46.                         }
  47.                     }
  48.                 }
  49.                 if (splitted[1].equalsIgnoreCase("ta")) {
  50.                     for (int i = 0; i <= taList.size(); i++) {
  51.                         if (i == taList.size()) {
  52.                             TeachingAssistant TA = new TeachingAssistant(splitted[2], splitted[3], splitted[4],
  53.                                     splitted[5]);
  54.                             taList.add(TA);
  55.                             System.out.println("success");
  56.                             break;
  57.                         }
  58.                         if (taList.get(i).getID().equalsIgnoreCase(splitted[3])) {
  59.                             System.out.println("A person with ID " + splitted[3] + " already exists.");
  60.                             break;
  61.                         }
  62.                     }
  63.                 }
  64.  
  65.             }
  66.             if (splitted[0].equalsIgnoreCase("assign")) {
  67.  
  68.                 if (splitted[1].equalsIgnoreCase("instructor")) {
  69.  
  70.                     for (int i = 0; i < instructorList.size(); i++) {
  71.                         if (instructorList.get(i).getID().equalsIgnoreCase(splitted[2])) {
  72.                             instructorList.get(i).setInsCourse(splitted[3] + " - " + courselist.get(i).getName);
  73.                         }
  74.  
  75.                     }
  76.  
  77.                 }
  78.                 if (splitted[1].equalsIgnoreCase("ta")) {
  79.  
  80.                     for (int i = 0; i < taList.size(); i++) {
  81.                         if (taList.get(i).getID().equalsIgnoreCase(splitted[2])) {
  82.                             taList.get(i).setTACourse(splitted[3] + " - " + courselist.get(i).getName());
  83.                         }
  84.                     }
  85.  
  86.                 }
  87.  
  88.             }
  89.  
  90.             if (splitted[0].equalsIgnoreCase("report")) {
  91.                 if (splitted[1].equalsIgnoreCase("course")) {
  92.                     for (int i = 0; i < courselist.size(); i++) {
  93.                         if (courselist.get(i).getCode().equalsIgnoreCase(splitted[2])) {
  94.                             courselist.get(i).readInfo();
  95.                         }
  96.                     }
  97.                 }
  98.                 if (splitted[1].equalsIgnoreCase("instructor")) {
  99.                     for (int i = 0; i < instructorList.size(); i++) {
  100.                         if (instructorList.get(i).getID().equalsIgnoreCase(splitted[2])) {
  101.                             instructorList.get(i).readInsInfo();
  102.                         }
  103.                     }
  104.                 }
  105.                 if (splitted[1].equalsIgnoreCase("ta")) {
  106.                     for (int i = 0; i < taList.size(); i++) {
  107.                         if (taList.get(i).getID().equalsIgnoreCase(splitted[2])) {
  108.                             taList.get(i).readAssInfo();
  109.                         }
  110.                     }
  111.                 }
  112.  
  113.             }
  114.  
  115.             if (!(splitted[0].equalsIgnoreCase("report") || splitted[0].equalsIgnoreCase("create")
  116.                     || splitted[0].equalsIgnoreCase("assign"))) {
  117.                 System.out.println("Unknown command");
  118.             }
  119.             if (!(splitted[1].equalsIgnoreCase("course") || splitted[1].equalsIgnoreCase("instructor")
  120.                     || splitted[1].equalsIgnoreCase("ta"))) {
  121.                 System.out.println("Unknown command");
  122.             }
  123.  
  124.         }
  125.  
  126.     }
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement