In: Computer Science
Given the StudentIDDriver.java file, fill in the ‘gaps’ in the code (designated by insert code here that “exercises” (tests) the StudentID class by calling its methods.
There are six occurrences of ‘insert code here comments’. Above these are comments that help you understand what your code should accomplish.
Don’t forget to comment your StudentIDDriver.java file
(including a prologue section at the top of the file).
Create a project in Eclipse for your StudentIdDriver.
Add another class for it StudentId
Sample session:
Enter student name: Carol
Enter student id: 1234
Invalid student id - reenter: 123400
Carol, your new e-mail account is:
/**********************************************************
* StudentIdDriver.java
* Dean & Dean
*
* Exercise 6.12 driver
**********************************************************/
import java.util.Scanner;
public class StudentIdDriver
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
StudentId myStudent;
String name;
// Instantiate StudentId 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 condition.)
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("\n" + name +
", your new e-mail account is: \n" +
<insert-code-here> ; // Get email account.
} // end main
} // end class StudentIdDriver
/**********************************************************
* StudentId.java
* Dean & Dean
*
* Exercise 6.12 driven class
**********************************************************/
public class StudentId
{
private String name;
private int id;
//*********************************************************
public void setName(String n)
{
this.name = n;
}
public String getName()
{
return this.name;
}
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return this.id;
}
//*********************************************************
public String getEmailAccount()
{
// Include "" in concatenation to convert to strings.
return "" + this.name.charAt(0) + this.id +
"@pirate.park.edu";
}
//*********************************************************
public boolean isValid()
{
return this.id >= 100000 && this.id <= 999999;
}
} // end class StudentId
/**********************************************************
* StudentIdDriver.java
* Dean & Dean
*
* Exercise 6.12 driver
**********************************************************/
import java.util.Scanner;
public class StudentIdDriver
{
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
StudentId myStudent;
String name;
// Instantiate StudentId object and assign it to student.
StudentId student = new StudentId();
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 condition.)
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("\n" + name + ", your new e-mail account is: \n" +
student.getEmailAccount()) ; // Get email account.
} // end main
} // end class StudentIdDriver
/**********************************************************
* StudentId.java
* Dean & Dean
*
* Exercise 6.12 driven class
**********************************************************/
public class StudentId
{
//private data members
private String name;
private int id;
//*********************************************************
//method to set the name of the student
public void setName(String n)
{
this.name = n;
}
//method to return the name of the student
public String getName()
{
return this.name;
}
//method to set the id of the student
public void setId(int id)
{
this.id = id;
}
//method to return the id of the student
public int getId()
{
return this.id;
}
//*********************************************************
//method to create and return the new email account of the
student
public String getEmailAccount()
{
// Include "" in concatenation to convert to strings.
return "" + this.name.charAt(0) + this.id +
"@pirate.park.edu";
}
//*********************************************************
//method to return true if id is valid, otherwise return
false
public boolean isValid()
{
return this.id >= 100000 && this.id <= 999999;
}
} // end class StudentId
Output:
Solving your question and
helping you to well understand it is my focus. So if you face any
difficulties regarding this please let me know through the
comments. I will try my best to assist you. However if you are
satisfied with the answer please don't forget to give your
feedback. Your feedback is very precious to us, so don't give
negative feedback without showing proper reason.
Always avoid copying from existing answers to avoid
plagiarism.
Thank you.