Ejemplo n.º 1
0
 @Test
 public void testPreassignProject() throws Exception {
   s.preassignProject(testProject_1);
   s.preassignProject(s.getRandomPreference());
   assertEquals("there shouldn't be 2 preassigned project", 1, s.getOrderedPreferences().size());
   assertEquals("expect true", true, s.hasPreassignedProject());
 }
Ejemplo n.º 2
0
 public void Show() {
   for (Student temp : student) {
     System.out.println("First Name:" + temp.getFName() + "\tLast Name :" + temp.getLName());
     System.out.println("Age is :" + temp.getAge());
     System.out.println("College :" + temp.getCollege());
   }
 }
Ejemplo n.º 3
0
 @Test
 public void testGetOrderedPreferences() throws Exception {
   for (Project str : testProject_rest) {
     s.addProject(str);
   }
   assertEquals("expect equal", testProject_rest, s.getOrderedPreferences());
 }
 private void assignStudent(Student s) {
   for (int y = 0; y < dorms.size(); y++) {
     if (s.hasRoom()) {
       break;
     }
     Dorm d = (Dorm) dorms.get(y);
     if (d.isFull()) {
       continue;
     }
     if (d.isFemaleOnly() && s.getGender() == Student.Gender.MALE) {
       continue;
     }
     int i = 0;
     while (i < d.getNumRooms()) {
       if (s.hasRoom()) {
         break;
       }
       try {
         d.getRoomByIndex(i).addResident(s);
       } catch (IllegalArgumentException e) {
       }
       i++;
     }
   }
 }
Ejemplo n.º 5
0
  @Test
  public void test1() throws Exception {

    Student denise = studentHome.create("823", "Denise Smith");

    Course power = courseHome.create("220", "Power J2EE Programming");

    Enroller enroller = enrollerHome.create();
    enroller.enroll("823", "220");
    enroller.enroll("823", "333");
    enroller.enroll("823", "777");
    enroller.enroll("456", "777");
    enroller.enroll("388", "777");

    System.out.println(denise.getName() + ":");
    ArrayList courses = denise.getCourseIds();
    Iterator i = courses.iterator();
    while (i.hasNext()) {
      String courseId = (String) i.next();
      Course course = courseHome.findByPrimaryKey(courseId);
      System.out.println(courseId + " " + course.getName());
    }

    System.out.println();

    Course intro = courseHome.findByPrimaryKey("777");
    System.out.println(intro.getName() + ":");
    courses = intro.getStudentIds();
    i = courses.iterator();
    while (i.hasNext()) {
      String studentId = (String) i.next();
      Student student = studentHome.findByPrimaryKey(studentId);
      System.out.println(studentId + " " + student.getName());
    }
  }
Ejemplo n.º 6
0
 public static void main(String args[]) {
   Student someone = new Student();
   someone.Display();
   Student fred = new Student(new String("Fred"), 4570, new String("03/15/1985"), 'M');
   fred.Display();
   System.out.println("(press Enter to exit)");
   try {
     System.in.read();
   } catch (IOException e) {
     return;
   }
 }
Ejemplo n.º 7
0
    public static Student findStudent(
            final Group group,
            final String authId
    ) {
        for (Student student : group.getStudents().values()) {
            if (authId.equalsIgnoreCase(student.getEmail())) {
                return student;
            }
        }

        return null;
    }
Ejemplo n.º 8
0
 @Test
 public void testAddProject() {
   int lastIndex = s.getNumberOfPreferences() - 1;
   s.addProject(testProject_1);
   assertEquals(
       "expected addProject to append object at the end of the array.",
       lastIndex + 1,
       s.getProjects().indexOf(testProject_1));
   for (Project project : testProject_rest) {
     s.addProject(project);
   }
   assertEquals(
       "expect to add %d projects.", testProject_rest.size() + 1, s.getNumberOfPreferences());
 }
Ejemplo n.º 9
0
  public String getRosterReport() {
    StringBuilder buffer = new StringBuilder();

    buffer.append(ROSTER_REPORT_HEADER);

    for (Student student : students) {
      buffer.append(student.getName());
      buffer.append(NEWLINE);
    }

    buffer.append(ROSTER_REPORT_FOOTER + students.size() + NEWLINE);

    return buffer.toString();
  }
Ejemplo n.º 10
0
  public static void createAd(@Valid Ad ad, File photo) throws IOException {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    // get current date time with Date()
    Date date = new Date();
    ad.createDate = dateFormat.format(date);
    ad.student = Student.findById(1l);
    // ad.category=Category.findById(ad.category.id);
    File d = new File(Play.applicationPath.getAbsolutePath() + "/public/img/ads");
    // if(d.exists()){
    String suffix = FilenameUtils.getExtension(photo.getName());
    File o = File.createTempFile("ad-", "." + suffix, d);

    InputStream input = new FileInputStream(photo);
    OutputStream output = new FileOutputStream(o);
    ad.image = o.getName();

    ad.save();
    try {
      IOUtils.copy(input, output);
    } finally {
      IOUtils.closeQuietly(output);
      IOUtils.closeQuietly(input);
    }

    Ads.index(1, ad.category.id.toString());
  }
Ejemplo n.º 11
0
 public static void GameOver(Student player, Teacher teacher, int battles) {
   System.out.println("The classwork was overwhelming! Beaten by " + teacher.getName());
   System.out.println("Winner info:");
   System.out.println("Name: " + teacher.getName());
   System.out.println("Strength: " + teacher.getStrength());
   System.out.println("Hitpoints: " + teacher.getHP());
   teacher.showAbilities();
   System.out.println();
   System.out.println("Loser info:");
   System.out.println("Name: " + player.getName());
   System.out.println("Strength: " + player.getStrength());
   System.out.println("Hitpoints: " + player.getHP());
   System.out.println("Classes attended: " + battles);
   player.showPlayerInventory(false);
   System.exit(0);
 }
Ejemplo n.º 12
0
 /**
  * The menu shown before battles Switch statement on the input determines which menu action to
  * take
  *
  * @param player the current player
  */
 public static void ShowPreBattleMenu(Student player) {
   boolean has_potions = player.checkIfPlayerHasItem("Potion");
   boolean show_menu = true;
   while (show_menu) {
     System.out.println("Strength: " + player.getStrength());
     System.out.println("Class starts soon, what do you want to do?");
     System.out.println("1) Start class");
     System.out.println("2) View inventory");
     System.out.println("3) Dropout (Quit)");
     if (has_potions) {
       System.out.println("4) Use Potion");
     }
     System.out.print(BOLDTEXT + "Enter a choice> " + PLAINTEXT);
     show_menu = PerformPreBattleMenuAction(player, has_potions);
   }
 }
Ejemplo n.º 13
0
 @Test
 public void testGetNumberOfStatedPreferences() {
   assertEquals(0, s.getNumberOfStatedPreferences());
   s.addProject(testProject_1);
   assertEquals(0, s.getNumberOfStatedPreferences());
   for (Project p : testProject_rest) {
     s.addProject(p);
   }
   assertEquals(0, s.getNumberOfStatedPreferences());
   s.setNumberOfStatedPreferences(100);
   assertEquals(100, s.getNumberOfStatedPreferences());
   s.preassignProject(testProject_1);
   assertEquals(1, s.getNumberOfStatedPreferences());
 }
Ejemplo n.º 14
0
 @Test
 public void testGetRandomPreference() throws Exception {
   int seed = 123;
   int num = 1;
   List<Project> expected = TheRNG().TestRandomPreferenceUtility(preped_s, seed, num);
   TheRNG().setSeed(seed);
   Project got = preped_s.getRandomPreference();
   assertEquals("should equal", expected.get(0), got);
 }
Ejemplo n.º 15
0
 @Check("login")
 public static void index() {
   User curUser = User.find("byName", Secure.Security.connected()).first();
   if (curUser.type == UserType.ADMINISTRATOR) {
     redirect("/admin/crud");
   } else if (curUser.type == UserType.STUDENT) {
     Student.index();
   } else {
     Teacher.index();
   }
 }
Ejemplo n.º 16
0
  public static void WinScreen(Student player, Teacher teacher, int battles) {
    if (teacher == null) {
      Teacher teacher1 = new Teacher();
      teacher = teacher1;
    }
    System.out.println(
        "Congratulations " + player + ", you passed " + teacher.getName() + "'s class!");
    System.out.println("Winner info:");
    System.out.println("Name: " + player.getName());
    System.out.println("Strength: " + player.getStrength());
    System.out.println("Hitpoints: " + player.getHP());
    System.out.println("Classes attended: " + battles);
    player.showPlayerInventory(false);

    System.out.println();
    System.out.println("Loser info:");
    System.out.println("Name: " + teacher.getName());
    System.out.println("Strength: " + teacher.getStrength());
    teacher.showAbilities();
    System.exit(0);
  }
Ejemplo n.º 17
0
 @Before
 public void setUp() throws Exception {
   testProject_1 = new Project("Test The Project of the First Non-Sense");
   s = new Student("test student");
   testProject_rest = new ArrayList<Project>();
   Random r = new Random();
   for (int i = 0; i < 50; i++)
     testProject_rest.add(new Project("test project another " + r.nextInt()));
   preped_s = new Student("I'm prepared");
   for (Project p : testProject_rest) {
     preped_s.addProject(p);
   }
 }
Ejemplo n.º 18
0
 /**
  * Perform the action from the menu above Needs refactoring for readability
  *
  * @param player current player
  * @param has_potions whether the player has potions in inventory
  * @return true or false whether to continue showing menu
  */
 public static boolean PerformPreBattleMenuAction(Student player, boolean has_potions) {
   Scanner input = new Scanner(System.in);
   switch (input.nextInt()) {
     case 1:
       return false;
     case 2:
       player.showPlayerInventory(true);
       break;
     case 3:
       System.exit(0);
       break;
     case 4:
       if (has_potions) {
         player.usePotion();
       }
       break;
     default:
       System.out.println("Invalid choice");
       break;
   }
   return true;
 }
Ejemplo n.º 19
0
  @Test
  public void test() {
    // Create students, and populate them into a List of there studies.
    Student studenta = new Student("Paul Barber", "1000");
    Student studentb = new Student("Chris Cooper", "A1000");
    Student studentc = new Student("Paul, Barber", "B1000");
    List<Student> studiesHistory = new ArrayList<Student>();
    studiesHistory.add(studenta);
    studiesHistory.add(studentb);
    studiesHistory.add(studentc);
    List<Student> studiesSport = new ArrayList<Student>();
    studiesSport.add(studentb);

    // Create exams for the modules.
    Exam exam = new Exam(2);
    Exam exama = new Exam(1);

    // Create the modules with the above date.
    Module module = new Module("HIS100", "History", exam, studiesHistory);
    Module sport = new Module("SPO109", "Sport", exama, studiesSport);
    List<Module> allModules = new ArrayList<Module>();
    // add all the modules to an allModules list.
    allModules.add(module);
    allModules.add(sport);

    // Set the Modules List in the Student Class.
    System.out.println(module.getStudentsEnrolled());
    System.out.println(sport.getStudentsEnrolled());
    System.out.println(studenta.getStudiesModules());
    studenta.setModules(allModules);
    studentb.setModules(allModules);
    studentc.setModules(allModules);
    System.out.println(studenta.getStudiesModules());
    System.out.println(studentb.getStudiesModules());
    System.out.println(studentc.getStudiesModules());

    System.out.println(module.compareTo(sport));
  }
Ejemplo n.º 20
0
 public int compare(Student left, Student right) {
   if (left.getUnivClass().equals(right.getUnivClass())) return 0; // Both in same University class
   else {
     for (int i = 0; i < ClassOrder.length; i++) {
       if (left.getUnivClass().equals(ClassOrder[i])) return -1;
       else if (right.getUnivClass().equals(ClassOrder[i])) return +1;
     }
     assert false
         : "error occurred("
             + left.getUnivClass()
             + ","
             + right.getUnivClass()
             + ")"; // what's the error??
     return +1; // have to put a return here to avoid "missing return" error
   }
 }
Ejemplo n.º 21
0
 public static void reports(String value, int report) {
   List<Student> students = Student.findAll();
   List<Result> results = null;
   if (report != 0) {
     switch (report) {
       case 1:
         results = StudentResults.generalAveragePerQuarter(Integer.parseInt(value));
         renderArgs.put("userSelected", Integer.parseInt(value));
         break;
       case 2:
         results = StudentResults.subjectGradesPerQuarter(value);
         renderArgs.put("subjectSelected", value);
         break;
       case 3:
         results = StudentResults.yearQuarterGeneralAverage(value);
         renderArgs.put("yearquarterSelected", value);
         break;
     }
     renderArgs.put("reportSelected", report);
   } else {
     renderArgs.put("reportSelected", 0);
   }
   render(students, results);
 }
Ejemplo n.º 22
0
 public int compareTo(Student other) {
   if (score == other.getScore()) return name.compareTo(other.getName());
   return other.getScore() - score;
 }
  /**
   * Assign the set of students (presumably non-incoming-freshmen, but this is not checked) passed
   * to their dorm rooms, in a way that does not take race into account. (compare {@link
   * #assignByRace}.) As a precursor (side effect) to this, any students already existing in
   * upperclass dorms will be removed.
   */
  public void assign(Bag students) {

    emptyDorms();

    // Purge all freshmen. (We're not assigning those.)
    Bag upperclassmen = null;
    try {
      upperclassmen = (Bag) students.clone();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
    for (int x = upperclassmen.size() - 1; x >= 0; x--) {
      Student s = (Student) upperclassmen.get(x);
      if (s.getGrade() < 2) {
        upperclassmen.remove(s);
      }
    }

    for (int x = 0; x < upperclassmen.size(); x++) {
      Student s = (Student) upperclassmen.get(x);
      if (s.getGrade() < 2) {
        // We're only assigning upperclassmen here.
        continue;
      }
      s.leaveRoom();
      for (int y = 0; y < dorms.size(); y++) {
        if (s.hasRoom()) {
          break;
        }
        Dorm d = (Dorm) dorms.get(y);
        if (d.isFull()) {
          continue;
        }
        if (d.isFemaleOnly() && s.getGender() == Student.Gender.MALE) {
          continue;
        }
        int i = 0;
        while (i < d.getNumRooms()) {
          if (s.hasRoom()) {
            break;
          }
          try {
            d.getRoomByIndex(i).addResident(s);
          } catch (IllegalArgumentException e) { // System.out.println(e);
          }
          i++;
        }
      }
    }

    // Error testing to see if there are upperclassmen who don't have a
    //  room/dorms that aren't full
    // int q=0;
    for (int x = 0; x < upperclassmen.size(); x++) {
      Student s = (Student) upperclassmen.get(x);
      if (!s.hasRoom()) {
        System.out.println(s + " has no upperclass dorm room!");
      }
    }
  }
  /**
   * Assign the set of students (presumably non-incoming-freshmen, but this is not checked) students
   * passed to their dorm rooms, in a way that <i>does</i> take race into account. (compare {@link
   * #assign}.) Minorities will have a higher probability of rooming with other minorities than they
   * would otherwise have had. As a precursor (side effect) to this, any students already existing
   * in upperclass dorms will be removed.
   */
  public void assignByRace(Bag upperclassmen) {
    emptyDorms();
    boolean foundRoomie;
    for (int x = 0; x < upperclassmen.size(); x++) {
      foundRoomie = false;
      Student s = (Student) upperclassmen.get(x);
      // need to leave current room so that they can get a new room
      s.leaveRoom();
      if (s.getRace() == Student.Race.MINORITY) {
        double rollDice = Sim.instance().random.nextDouble();
        if (rollDice < Sim.PROB_DUAL_MINORITY) {
          for (int m = 0; m < upperclassmen.size(); m++) {
            Student r = (Student) upperclassmen.get(m);
            // if the potential roommate is the same gender, is a
            //  minority, and has no room
            if (r.getId() == s.getId()) {
              continue;
            }
            if (r.getRace() == Student.Race.MINORITY
                && r.getGender() == s.getGender()
                && !(r.hasRoom())
                && !(s.hasRoom())) {
              // find a room that is completely empty
              foundRoomie = true;
              for (int y = 0; y < dorms.size(); y++) {
                Dorm d = (Dorm) dorms.get(y);
                if (d.isFull()) {
                  continue;
                }
                if (d.isFemaleOnly() && s.getGender() == Student.Gender.MALE) {
                  continue;
                }
                int i = 0;
                while (i < d.getNumRooms()) {
                  if (s.hasRoom() && r.hasRoom()) {
                    break;
                  }
                  try {
                    if (d.getRoomByIndex(i).isEmpty()) {
                      try {
                        d.getRoomByIndex(i).addResidents(s, r);
                      } catch (IllegalArgumentException e) {
                        System.out.println(e);
                      }
                    }
                  } catch (IllegalArgumentException e) {
                  }
                  i++;
                }
              }
              if (!s.hasRoom()) {
                // no empty room has been found to put these
                // students in; just assign them normally
                assignStudent(s);
              }
              if (!r.hasRoom()) {
                assignStudent(r);
              }
            }
          }
          if (foundRoomie == false) {
            // no same-minority, same-sex, roomless roommate found
            assignStudent(s);
          }
        } else {
          // dice roll not under PROB_DUAL_MINORITY
          assignStudent(s);
        }

      } else {
        // not a minority, assign normally
        assignStudent(s);
      }
    }
  }
Ejemplo n.º 25
0
  /** @param userList Populate system with list of students accounts from text file */
  public static void populateStudentAccounts(LinkedList<User> userList) {
    Scanner inputStream = null;
    // open text file of accounts
    try {
      inputStream = new Scanner(new FileInputStream("accounts.txt"));
      // System.out.println("accounts file read");
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(null, "The file \"accounts.txt\" could not be found");
      JOptionPane.showMessageDialog(null, "The system will now exit");
      System.exit(0);
    }

    // Pull line of text to generate a student
    while (inputStream.hasNextLine()) {
      String s1 = inputStream.nextLine();
      // locate first name
      int fNsameStart = (s1.indexOf("-") + 1);
      int fNameEnd = (s1.indexOf(","));
      String fName = s1.substring(fNsameStart, fNameEnd);
      // locate Last name
      int lNameStart = (s1.indexOf(",", fNameEnd) + 1);
      int lNameEnd = (s1.indexOf(",", lNameStart));
      String lName = s1.substring(lNameStart, lNameEnd);
      // locate gNumber
      int gNumberStart = (s1.indexOf(",", lNameEnd) + 1);
      int gNumberEnd = (s1.indexOf(",", gNumberStart));
      String gNumber = s1.substring(gNumberStart, gNumberEnd);
      // locate password
      int passwordStart = (s1.indexOf(",", gNumberEnd) + 1);
      int passwordEnd = (s1.indexOf(",", passwordStart));
      String password = s1.substring(passwordStart, passwordEnd);
      // locate phone number
      int phoneNumberStart = (s1.indexOf(",", passwordEnd + 1));
      int phoneNumberEnd = (s1.indexOf(",", phoneNumberStart));
      String phoneNumber = s1.substring(phoneNumberStart, phoneNumberEnd);
      // locate email
      int emailStart = (s1.indexOf(",", phoneNumberEnd) + 1);
      int emailEnd = (s1.indexOf(",", emailStart));
      String email = s1.substring(emailStart, emailEnd);
      // locate username
      int usernameStart = (s1.indexOf(",", emailEnd) + 1);
      int usernameEnd = (s1.indexOf(",", usernameStart));
      String username = s1.substring(usernameStart, usernameEnd);
      // locate address
      int addressStart = (s1.indexOf(",", usernameEnd) + 1);
      String address = s1.substring(addressStart);

      // create student object and populate info
      User aStudent = new Student(username);
      aStudent.setFirstName(fName);
      aStudent.setLastName(lName);
      aStudent.setgNumber(gNumber);
      aStudent.setPassword(password);
      aStudent.setPhoneNumber(phoneNumber);
      aStudent.setEmail(email);
      if (aStudent instanceof Student) {
        ((Student) aStudent).setShippingAddress(address);
      }

      // add Student to list
      userList.add(aStudent);
      System.out.println(userList.size());
    }
  }
Ejemplo n.º 26
0
 /**
  * Create a character menu
  *
  * @param player
  */
 public static void CreateCharacterMenu(Student player) {
   Scanner input = new Scanner(System.in);
   System.out.print(BOLDTEXT + "Enter your name> " + PLAINTEXT);
   String name = input.nextLine();
   player.setName(name);
 }
Ejemplo n.º 27
0
  /**
   * Prompt student with list of courses and add each on based on selection to their list of courses
   *
   * @param allCourses
   * @param aStudent
   */
  public static void menu(LinkedList<Course> courseList, User aUser, LinkedList<User> userList) {
    int selection = -1;
    final int MAX_COURSES = 7;
    boolean more;

    // send user if admin to add course
    Student aStudent = new Student();
    if (aUser instanceof Student) {
      aStudent = (Student) aUser;
      String menuPrompt =
          "Welcome to the GMU IT Bookstore!"
              + "\nPlease enter the number that corresponds to one of your classes";
      for (int i = 0; i < courseList.size(); i++) {
        Course aCourse = courseList.get(i);
        menuPrompt += "\n" + (i + 1) + ") " + aCourse.getCourseName();
      }

      do {
        do {
          try {
            selection = Integer.parseInt(JOptionPane.showInputDialog(menuPrompt));

            if (selection > courseList.size() || selection <= 0) {
              throw new IllegalArgumentException();
            }
          } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(
                null, "Invalid entry, please enter number associated with course");
            selection = -1;
          } catch (IllegalArgumentException e) {
            JOptionPane.showMessageDialog(null, "Invalid Selection. Try again.");
            selection = -1;
          }

        } while (selection > courseList.size() || selection <= 0);

        // add a course to student list of courses if its not already added to student's courses
        if (aStudent.getCourseList().contains(courseList.get(selection - 1))) {
          JOptionPane.showMessageDialog(null, "You have already ordered this book");
        } else if (aStudent.getCourseList().size() >= MAX_COURSES) {
          JOptionPane.showMessageDialog(
              null,
              "You have already registered " + MAX_COURSES + " courses, the max number allowed");
          break;
        } else {
          if (courseList.get(selection - 1).getTextStock() < 1) {
            JOptionPane.showMessageDialog(
                null, "This book is backordered and will take extra processing time");
          }
          Course aCourse = (courseList.get(selection - 1));
          aStudent.addCourse(aCourse);
          JOptionPane.showMessageDialog(
              null, courseList.get(selection - 1).getCourseText() + " Has been added to your cart");
        }

        // prompt student if they would like to continue entering courses
        int reply =
            JOptionPane.showConfirmDialog(
                null, "Do you have another class to enter?", "title", JOptionPane.YES_NO_OPTION);
        if (reply == 1) {
          more = false;
        } else {
          more = true;
        }
      } while (more && (aStudent.getCourseList().size() <= MAX_COURSES));

      // Give confirmation of order
      JOptionPane.showMessageDialog(null, "Your order has been entered\n");
    } else {
      // Admin tempAdmin;
      addCourse(courseList);
    }

    // return user to login screen
    login(userList, courseList);
  }
Ejemplo n.º 28
0
  /**
   * @param userList
   * @return Student Register new student by prompting them for user info
   */
  public static Student registerStudentAccount(LinkedList<User> userList) {
    String username = "";
    String password = "";
    String first = "";
    String last = "";
    String GNum = "";
    String phoneNum = "";
    String email = "";
    String address = "";
    User aStudent = null;

    // prompt for username until available username is entered
    do {
      username = JOptionPane.showInputDialog("Please enter desired username");
      aStudent = validateUsername(username, userList);
      if (aStudent != null) {
        JOptionPane.showMessageDialog(null, "This username is already in use!\nPlease try again");
      }
    } while (aStudent != null);

    // create student object
    aStudent = new Student(username);

    // prompt for password until valid entry is given
    do {
      password = JOptionPane.showInputDialog("Please enter desired password");
      if (!aStudent.setPassword(password)) {
        JOptionPane.showMessageDialog(
            null,
            "Password does not meet requirements. Minimum 8 characters\nTry Again.",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setPassword(password));

    // prompt for first name until valid entry is made
    do {
      first = JOptionPane.showInputDialog("Please enter your first name");
      if (!aStudent.setFirstName(first)) {
        JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again.");
      }
    } while (!aStudent.setFirstName(first));

    // prompt for last name until valid entry is made
    do {
      last = (JOptionPane.showInputDialog("Please enter your last name"));
      if (!aStudent.setLastName(last)) {
        JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again");
      }
    } while (!aStudent.setLastName(last));

    // prompt for G-Number until valid entry is made
    do {
      GNum = (JOptionPane.showInputDialog("Please enter your G-number"));
      if (!aStudent.setgNumber(GNum)) {
        JOptionPane.showMessageDialog(
            null,
            "Invalid entry! Please write your GNumber in this format 00XXXXXX \nPlease try again",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setgNumber(GNum));

    // prompt for phone number until valid entry is made
    do {
      phoneNum = (JOptionPane.showInputDialog("Please enter your phone number"));
      if (!aStudent.setPhoneNumber(phoneNum)) {
        JOptionPane.showMessageDialog(
            null,
            "Invalid entry. Please write your phone number in XXXXXXXXXX format \nPlease try again",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setPhoneNumber(phoneNum));

    // prompt for email until valid entry is made
    do {
      email = (JOptionPane.showInputDialog("Please enter your Email address"));
      if (!aStudent.setEmail(email)) {
        JOptionPane.showMessageDialog(
            null,
            "Invalid entry, correct format: [email protected] \nPlease try again",
            "Error",
            JOptionPane.ERROR_MESSAGE);
      }
    } while (!aStudent.setEmail(email));

    // prompt for address until valid entry is made
    Student nStudent = (Student) aStudent;

    do {
      address = (JOptionPane.showInputDialog("Please enter your shipping address"));
      if (!nStudent.setShippingAddress(address)) {
        JOptionPane.showMessageDialog(null, "Invalid entry \nPlease try again");
      }
    } while (!nStudent.setShippingAddress(address));

    JOptionPane.showMessageDialog(null, "Your account has been created");
    try {
      PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("accounts.txt", true)));

      pw.println(
          "\r\n-"
              + aStudent.getFirstName()
              + ","
              + aStudent.getLastName()
              + ","
              + aStudent.getgNumber()
              + ","
              + aStudent.getPassword()
              + ","
              + aStudent.getPhoneNumber()
              + ","
              + aStudent.getEmail()
              + ","
              + aStudent.getUsername()
              + ","
              + nStudent.getShippingAddress());
      pw.close();

    } catch (IOException e) {
      e.printStackTrace();
    }

    userList.add(aStudent);
    return nStudent;
  }
Ejemplo n.º 29
0
  public static void main(String[] args) {

    Student obj[] = new Student[5];

    for (Student temp : obj) System.out.println(temp.getRoll() + "\t" + temp.getName());
  }
Ejemplo n.º 30
0
  public static void main(String args[]) {
    Main m = new Main();
    World w = new World();
    Avatar a = w.getAvatar();
    Room currentRoom = w.getFirst();
    while (true) {
      // kolla sphinxen - går ur loopen
      // printa rummet
      //	    System.out.print("\033[2J\033[;H");
      System.out.println("=============== PollaxMUD ================");
      System.out.println(currentRoom);
      // kommandon - inläsning från användaren:
      String input =
          m.readInput(
              "go north",
              "go south",
              "go east",
              "go west",
              "inventory",
              "pick up",
              "drop",
              "check courses",
              "talk",
              "trade",
              "graduate",
              "enroll",
              "unlock south",
              "unlock west",
              "unlock east",
              "unlock north");
      // System.out.println(input);
      // go väderstreck - uppdatera currentRoom
      if (input.equals("go north")) {
        if (currentRoom.getRoomNorth() != null) {
          if (currentRoom.getRoomNorth().getDoorNorth() != false) {
            // kolla nycklar o shit
            currentRoom = currentRoom.getRoomNorth();
          } else {
            System.out.println("The door is locked");
          }
          // kolla nycklar o shit
          currentRoom = currentRoom.getRoomNorth();
        } else {
          System.out.println("There is no room in the north direction");
        }
      } else if (input.equals("go south")) {
        if (currentRoom.getRoomSouth() != null) {
          if (currentRoom.getRoomSouth().getDoorSouth() != false) {
            // kolla nycklar o shit
            currentRoom = currentRoom.getRoomSouth();
          } else {
            System.out.println("The door is locked");
          }
        } else {
          System.out.println("There is no room in the south direction");
        }
      } else if (input.equals("go east")) {
        if (currentRoom.getRoomEast() != null) {
          if (currentRoom.getRoomEast().getDoorEast() != false) {
            // kolla nycklar o shit
            currentRoom = currentRoom.getRoomEast();
          } else {
            System.out.println("The door is locked");
          }
        } else {
          System.out.println("There is no room in the east direction");
        }
      } else if (input.equals("go west")) {
        if (currentRoom.getRoomWest() != null) {
          if (currentRoom.getRoomWest().getDoorWest() != false) {
            // kolla nycklar o shit
            currentRoom = currentRoom.getRoomWest();
          } else {
            System.out.println("The door is locked");
          }
        } else {
          System.out.println("There is no room in the west direction");
        }
      } else if (input.equals("unlock south")) {
        Room room = currentRoom.getRoomSouth();
        if (room != null) {
          if (room.getDoorSouth() == false) {
            if (a.getBackpack().getTotalObjects() != 0) {
              Item key = a.getBackpack().getFirstObjectList();
              a.getBackpack().drop(key);
              room.setDoorSouth(true);
            } else {
              System.out.println("You don´t have any keys to use");
            }

          } else {
            System.out.println("The door is already open");
          }
        } else {
          System.out.println("There is no room in the south direction");
        }

      } else if (input.equals("unlock east")) {
        Room room = currentRoom.getRoomEast();
        if (room != null) {
          if (room.getDoorEast() == false) {
            if (a.getBackpack().getTotalObjects() != 0) {
              Item key = a.getBackpack().getFirstObjectList();
              a.getBackpack().drop(key);
              room.setDoorEast(true);
            } else {
              System.out.println("You don´t have any keys to use");
            }

          } else {
            System.out.println("The door is already open");
          }
        } else {
          System.out.println("There is no room in the east direction");
        }

      } else if (input.equals("unlock west")) {
        Room room = currentRoom.getRoomWest();
        if (room != null) {
          if (room.getDoorWest() == false) {
            if (a.getBackpack().getTotalObjects() != 0) {
              Item key = a.getBackpack().getFirstObjectList();
              a.getBackpack().drop(key);
              room.setDoorWest(true);
            } else {
              System.out.println("You don´t have any keys to use");
            }

          } else {
            System.out.println("The door is already open");
          }
        } else {
          System.out.println("There is no room in the east direction");
        }

      } else if (input.equals("unlock north")) {
        Room room = currentRoom.getRoomNorth();
        if (room != null) {
          if (room.getDoorNorth() == false) {
            if (a.getBackpack().getTotalObjects() != 0) {
              Item key = a.getBackpack().getFirstObjectList();
              a.getBackpack().drop(key);
              room.setDoorNorth(true);
            } else {
              System.out.println("You don´t have any keys to use");
            }

          } else {
            System.out.println("The door is already open");
          }
        } else {
          System.out.println("There is no room in the east direction");
        }

      }

      // inventory
      else if (input.equals("inventory")) {
        Backpack b = a.getBackpack();
        b.inventory();
      }
      // kolla kurser
      else if (input.equals("check courses")) {
        m.printCourses(a);
      } else if (input.equals("graduate")) {
        System.out.println("not implemented yet");
        // kolla om sfinxen finns i rummet
      } else if (input.substring(0, 4).equals("talk")) {
        //		System.out.println("not implemented yet");
        String talkPerson = input.substring(5, input.length());
        System.out.print(talkPerson);
        if (talkPerson.equals("teacher")) {
          if (currentRoom.getTeacher() != null) {
            Teacher t = currentRoom.getTeacher();
            t.talk(a);
          }
        } else if (currentRoom.checkStudentName(talkPerson)) {
          Student s = currentRoom.getStudent();
          s.talk(a);
        } else {
          System.out.println("No such person in the room");
        }
      }
      // plocka upp saker
      else if (input.equals("pick up")) {
        ArrayList<Item> Items = currentRoom.getItemsinRoom();
        if (Items.size() != 0) {
          Item key = Items.get(0);
          a.getBackpack().pack(key);
          Items.remove(key);
        } else {
          System.out.println("Det finns inga nycklar i det här rummet");
        }

      } else if (input.length() >= 6) {
        if (input.substring(0, 6).equals("enroll")) {
          System.out.println("not implemented yet");
        }
      }
      // dropa saker
      else if (input.substring(0, 4).equals("drop")) {
        System.out.println("not implemented yet");
      } else if (input.substring(0, 5).equals("trade")) {
        System.out.println("not implemented yet");
      } else {
        System.out.println("OH NOES!!!");
      }
    }
  }