Question

In: Computer Science

Given the StudentIDDriver.java file, fill in the ‘gaps’ in the code (designated by insert code here...

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:

[email protected]

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

* 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

Solutions

Expert Solution

/**********************************************************
* 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.


Related Solutions

Please carefully review the code to fill in after the given instructions and complete the code...
Please carefully review the code to fill in after the given instructions and complete the code for me. Thank you in advance. In this problem, we will implement a simple dictionary of common words in the English language, represented as an array of words paired with their lengths. You will need to implement each of the below methods in the Dictionary class. In this problem, the first line of input represents the method to call. It will be one of...
The code file is attached. Portion of the code is given (1, 2, 3, 4). You...
The code file is attached. Portion of the code is given (1, 2, 3, 4). You have to write the code for the remaining items (5, 6, 7). #include <iostream> using namespace std; struct node { int data; node* next; }; node* head=NULL; void appendNode(int value) { node *newNode, *curr; newNode = new node(); newNode->data=value; newNode->next=NULL; if (!head) head=newNode; else { curr=head; while (curr->next) curr = curr->next; curr->next = newNode; } } void insertNode(int value) { node *newNode, *curr, *previous;...
Objective: Describe the advantages that surveys have to offer. Surveys attempt to fill the gaps of...
Objective: Describe the advantages that surveys have to offer. Surveys attempt to fill the gaps of the UCR. There is so much crime that goes unreported to law enforcement that this approach is necessary to attempt to get an accurate picture of crime and victims in the country. Over the years, these surveys have had to be changed to address problems with their predecessors. Review Chapter 2 in your textbook. Write a three paragraph response on the use of victim...
The wisdom of depending on International Medical School Graduates (IMGs) to fill gaps in physician supply,...
The wisdom of depending on International Medical School Graduates (IMGs) to fill gaps in physician supply, while US medical schools hold class size constant, is questionable. In addition, the aging of the physician workforce, the decreasing hours worked by both physicians in practice and physicians in residency, and a 20 percent reduction in the effort of the increasing proportion of female physicians, will result in a significant decrease in the “effective” supply of physicians. Should the gap be filled by...
Fill in the blank with the appropriate medical term. Please “BOLD” the terms that you insert....
Fill in the blank with the appropriate medical term. Please “BOLD” the terms that you insert. Mary just had a baby; therefore, she is in the 6-week period after birth, better known as _________. Since this was Mary’s first viable child, she was termed_________. Before the birth, or during the ________ portion, she was worried that her baby would be born dead, or ______________. She was also worried she may develop metabolic disturbances such as eclampsia, which is known as...
Need to fill in yellow gaps in the table Inventory Items Historical Cost Current Sales Price...
Need to fill in yellow gaps in the table Inventory Items Historical Cost Current Sales Price Disposal Cost Current Replacement Cost Normal Mark-up (Profit Margin) TGIT $20.00 $25.00 $7.15 $22.00 $8.00 TT9G5 $25.00 $30.00 $6.90 $29.00 $12.00 Inventory Items Floor Current Replacement Cost Ceiling Choose the appropriate comparison price TGIT $9.85 $22.00 $17.85 i.e., the designated market value TT9G5 $11.10 $29.00 $23.10 Inventory Items Historical Cost Designated Market Value Adjustment compare designated market value to TGIT $20.00 historical cost, and...
Fill in the blanks in the MATLAB code below.
Fill in the blanks in the MATLAB code below. (Do not type unnecessary words or blank spaces in your response. The correct answers are case-sensitive.) % Consider a row vector v. % Complete the lines of code below to find the average and standard deviation of the elements of vector v such that these two values are assigned to variables M and S, respectively. E = G =
AVL tree; Insert and Range Minimum operation in Java code.
AVL tree; Insert and Range Minimum operation in Java code.
Given a server.js file that uses express (i.e. var app = express();), write code to respond...
Given a server.js file that uses express (i.e. var app = express();), write code to respond to the routes below as specified in the description.  NOTE: all callback functions must be written in the new ES6 "Arrow Function" syntax: (1) Match the "GET" route "/users" and accept query string of "page=2&perPage=10" in the url, i.e. "/users? page=2&perPage=10". This route must show the following in browser: Query String Parameters: Page: 2 perPage: 10 Note: the query string parameters may have different values,...
Start with the provided code for the class linkedListType. Be sure to implement search, insert, and...
Start with the provided code for the class linkedListType. Be sure to implement search, insert, and delete in support of an unordered list (that code is also provided). Now, add a new function called insertLast that adds a new item to the END of the list, instead of to the beginning of the list. Note: the link pointer of the last element of the list is NULL. Test your new function in main. Submit a .zip of your entire project....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT