Пример #1
0
  public void addRecord(DatabaseContainer db, MyScanner sc) {
    int id =
        sc.nextInt("Please enter student ID (1000000000 - 1999999999): ", 1000000000, 1999999999);
    String fName = sc.nextLine("Please enter student First Name: ", 1, 50);
    String lName = sc.nextLine("Please enter student Last Name: ", 1, 50);
    int age = sc.nextInt("Please enter student age: ");
    boolean sex;
    String sexStr = sc.validate("Please enter the student sex (male / female)", "male|female");
    if (sexStr.equals("male")) sex = true;
    else sex = false;
    double GPA = sc.nextDouble("Please enter the student's current GPA (0-100): ", 0.0, 100.0);

    Student newStudent = new Student(id, fName, lName, age, sex, GPA);
    db.getFile().addStudent(newStudent);
    System.out.println("Student added!");
  }
Пример #2
0
  public void searchByRange(DatabaseContainer db, MyScanner sc) {
    String typeStr =
        sc.validate("Please enter which field you want to search (age / gpa): ", "age|gpa");
    boolean type;
    if (typeStr.equals("age")) type = db.getFile().AGE_TYPE;
    else type = db.getFile().GPA_TYPE;

    int lo = sc.nextInt("What is the lower range of your search?");
    int hi = sc.nextInt("What is the higher ranger of your search?");

    ArrayList<Student> results = db.getFile().searchByRange(hi, lo, type);

    if (!results.isEmpty()) {
      System.out.println("Results found: ");
      for (Student s : results) {
        System.out.println("**********");
        System.out.println(s);
      }
    } else System.out.println("No results found!");
  }
Пример #3
0
  public void editRecord(DatabaseContainer db, MyScanner sc) {
    int id =
        sc.nextInt("Please enter the id of the student you wish to edit: ", 1000000000, 1999999999);
    Student s = db.getFile().getStudent(id);
    int choice =
        sc.nextInt(
            "Please enter the number of the field you wish to edit:"
                + "\n1. ID"
                + "\n2. First Name"
                + "\n3. Last Name"
                + "\n4. Age"
                + "\n5. Sex"
                + "\n6. Current GPA",
            1,
            6);

    if (choice == 1) {
      s.setID(
          sc.nextInt(
              "Please enter student ID (1000000000 - 1999999999): ", 1000000000, 1999999999));
    } else if (choice == 2) {
      s.setFirstName(sc.nextLine("Please enter student First Name: ", 1, 50));
    } else if (choice == 3) {
      s.setLastName(sc.nextLine("Please enter student Last Name: ", 1, 50));
    } else if (choice == 4) {
      s.setAge(sc.nextInt("Please enter student age: "));
    } else if (choice == 5) {
      boolean sex;
      String sexStr = sc.validate("Please enter the student sex (male / female)", "male|female");
      if (sexStr.equals("male")) sex = true;
      else sex = false;
      s.setSex(sex);
    } else if (choice == 6) {
      s.setCurrentGPA(
          sc.nextDouble("Please enter the student's current GPA (0-100): ", 0.0, 100.0));
    }
    System.out.println("Record Edited!");
  }