Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the following StudentDriver class skeleton by replacing all six occurre

ID: 3762785 • Letter: C

Question

Complete the following StudentDriver class skeleton by replacing all six occurrences of <insert-code-here> with your own code such that the program operates properly. For details, read the comments above and next to the <insert-code-here> insertions. Note the Student class, which is below the StudentDriver class. The two classes are in separate files.

import java.util.Scanner;

public class StudentDriver

{

public static void main(String[] args)

{

    Scanner stdIn = new Scanner(System.in);

    Student student; // student object

    String name;      // student name

    // Instantiate Student object and assign it to student.

    <insert-code-here>

    System.out.print("Enter student name: ");

    name = stdIn.nextLine();

    // Assign name to the student object.

    <insert-code-here>

    System.out.print("Enter student id: ");

    // In a single statement, read an int for the id value,

    // and assign it to the student object.

    <insert-code-here>

    // If invalid id, execute the loop.

    // (Use the isValid method in the while loop heading.)

    while (<insert-code-here>)

    {

      System.out.print("Invalid student id - reenter: ");

      // In a single statement, read an int for the id value

      // and assign it to the student object.

      <insert-code-here>

    }

    System.out.println(" " + name +

      ", your new e-mail account is: " +

      <insert-code-here>                   // Get email account.

} // end main

} // end class StudentDriver

public class Student

{

private String name; // student name

private int id;       // student id

//*********************************************************

public void setName(String n)

{

    this.name = n;

}

public void setId(int id)

{

    this.id = id;

}

//*********************************************************

public String getEmailAccount()

{

    // Include "" in concatenation to convert to strings.

    return "" + this.name.charAt(0) + this.id +

      "@park.edu";

}

//*********************************************************

public boolean isValid()

{

    return this.id >= 100000 && this.id <= 999999;

}

} // end class Student

Explanation / Answer

import java.util.Scanner;

public class StudentDriver {

   public static void main(String[] args)

{

Scanner stdIn = new Scanner(System.in);

Student student; // student object

String name; // student name

// Instantiate Student object and assign it to student.

student = new Student();

System.out.print("Enter student name: ");

name = stdIn.nextLine();

// Assign name to the student object.

student.setName(name);

System.out.print("Enter student id: ");

// In a single statement, read an int for the id value,

// and assign it to the student object.

student.setId(stdIn.nextInt());

// If invalid id, execute the loop.

// (Use the isValid method in the while loop heading.)

while (student.isValid())

{

System.out.print("Invalid student id - reenter: ");

// In a single statement, read an int for the id value

// and assign it to the student object.

student.setId(stdIn.nextInt());

}

System.out.println(" " + name +

", your new e-mail account is: " +

student.getEmailAccount()); // Get email account.

} // end main

} // end class StudentDriver

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote