Ejemplo n.º 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!");
  }
Ejemplo n.º 2
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!");
  }