InfoProcessorTest.java   import java.util.*; /** * * Class to process and extract information from a list of lines. * */ public class InfoProcessorTest { /** * * List of lines to process. * */ private ArrayList lines =new ArrayList(); /** * * Creates InfoProcessor with given list of lines. * * @param lines to process * */ public InfoProcessorTest(ArrayList lines) { this.lines = lines; } /** * * Gets the course name from the list of lines. * * First, finds the line that starts with "Course:". * * Second, gets the String on the very next line, which should be the course * name. * * Third, returns the String from the method. * * * * Hint(s): * * - Use the getNextStringStartsWith(String str) method to find the course name * * * * Example(s): * * - If the ArrayList lines contains: "Course:" and "CIT590", and we * call * * getCourseName(), we'll get "CIT590". * * * * - If the ArrayList lines contains: "Course:" and "CIT 593", and we * call * * getCourseName(), we'll get "CIT 593". * * * * @return course name * */ public String getCourseName() { return getNextStringStartsWith("Course"); } /** * * Gets the course ID from the list of lines. * * First, finds the line that starts with "CourseID:". * * Second, gets the String on the very next line, which should be the course ID. * * Third, casts the String to an int and returns it from the method. * * * * Hint(s): * * - Use the getNextStringStartsWith(String str) method to find the course ID * * * * Example(s): * * - If the ArrayList lines contains: "CourseID:" and "590", and we call * * getCourseId(), we'll get the int 590. * * * * - If the ArrayList lines contains: "CourseID" and "593", and we call * * getCourseId(), we'll get the int 593. * * * * @return course ID * */ publicint getCourseId() { String courseId = getNextStringStartsWith("CourseID:"); int cid = Integer.parseInt(courseId); return cid; } /** * * Gets the student ID from the list of lines. * * First, finds the line that starts with "StudentID:". * * Second, gets the String on the very next line, which should be the student * ID. * * Third, casts the String to an int and returns it from the method. * * * * Hint(s): * * - Use the getNextStringStartsWith(String str) method to find the student ID * * * * Example(s): * * - If the ArrayList lines contains: "StudentID:" and "101", and we * call * * getStudentId(), we'll get the int 101. * * * * - If the ArrayList lines contains: "StudentID" and "5554", and we * call * * getStudentId(), we'll get the int 5554. * * * * @return student ID * */ publicint getStudentId() { String studentId = getNextStringStartsWith("CourseID:"); int sid = Integer.parseInt(studentId); return sid; } /** * * To be used by "getCourseName", "getCourseId", and "getStudentId" methods. * * * * Gets the String that follows the line that starts with the given String. * * Gets and returns the String on the very next line. * * If the given String doesn't exist, should return null. * * * * Example(s): * * - If an ArrayList lines contains: "hello" and "world", and we call * * getNextStringStartsWith("hello"), we'll get the String "world". * * * * - If an ArrayList lines contains: "Course" and "CIT590", and we call * * getNextStringStartsWith("Course"), we'll get the String "CIT590". * * * * - If an ArrayList lines contains: "hello" and "world", and we call * * getNextStringStartsWith("goodbye"), we'll get null. * * * * @param str to look for in lines * * @return String from the very next line * */ String getNextStringStartsWith(String str) { Iterator iterator = lines.iterator(); while (iterator.hasNext() &&!iterator.next().equals(str)) { iterator.next(); } return iterator.next(); }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

InfoProcessorTest.java

 

import java.util.*;

/**
*
* Class to process and extract information from a list of lines.
*
*/

public class InfoProcessorTest {

/**
*
* List of lines to process.
*
*/

private ArrayList<String> lines =new ArrayList<String>();

/**
*
* Creates InfoProcessor with given list of lines.
*
* @param lines to process
*
*/

public InfoProcessorTest(ArrayList<String> lines) {

this.lines = lines;

}

/**
*
* Gets the course name from the list of lines.
*
* First, finds the line that starts with "Course:".
*
* Second, gets the String on the very next line, which should be the course
* name.
*
* Third, returns the String from the method.
*
*
*
* Hint(s):
*
* - Use the getNextStringStartsWith(String str) method to find the course name
*
*
*
* Example(s):
*
* - If the ArrayList<String> lines contains: "Course:" and "CIT590", and we
* call
*
* getCourseName(), we'll get "CIT590".
*
*
*
* - If the ArrayList<String> lines contains: "Course:" and "CIT 593", and we
* call
*
* getCourseName(), we'll get "CIT 593".
*
*
*
* @return course name
*
*/

public String getCourseName() {

return getNextStringStartsWith("Course");

}

/**
*
* Gets the course ID from the list of lines.
*
* First, finds the line that starts with "CourseID:".
*
* Second, gets the String on the very next line, which should be the course ID.
*
* Third, casts the String to an int and returns it from the method.
*
*
*
* Hint(s):
*
* - Use the getNextStringStartsWith(String str) method to find the course ID
*
*
*
* Example(s):
*
* - If the ArrayList<String> lines contains: "CourseID:" and "590", and we call
*
* getCourseId(), we'll get the int 590.
*
*
*
* - If the ArrayList<String> lines contains: "CourseID" and "593", and we call
*
* getCourseId(), we'll get the int 593.
*
*
*
* @return course ID
*
*/

publicint getCourseId() {

String courseId = getNextStringStartsWith("CourseID:");
int cid = Integer.parseInt(courseId);
return cid;

}

/**
*
* Gets the student ID from the list of lines.
*
* First, finds the line that starts with "StudentID:".
*
* Second, gets the String on the very next line, which should be the student
* ID.
*
* Third, casts the String to an int and returns it from the method.
*
*
*
* Hint(s):
*
* - Use the getNextStringStartsWith(String str) method to find the student ID
*
*
*
* Example(s):
*
* - If the ArrayList<String> lines contains: "StudentID:" and "101", and we
* call
*
* getStudentId(), we'll get the int 101.
*
*
*
* - If the ArrayList<String> lines contains: "StudentID" and "5554", and we
* call
*
* getStudentId(), we'll get the int 5554.
*
*
*
* @return student ID
*
*/

publicint getStudentId() {
String studentId = getNextStringStartsWith("CourseID:");
int sid = Integer.parseInt(studentId);
return sid;
}

/**
*
* To be used by "getCourseName", "getCourseId", and "getStudentId" methods.
*
*
*
* Gets the String that follows the line that starts with the given String.
*
* Gets and returns the String on the very next line.
*
* If the given String doesn't exist, should return null.
*
*
*
* Example(s):
*
* - If an ArrayList<String> lines contains: "hello" and "world", and we call
*
* getNextStringStartsWith("hello"), we'll get the String "world".
*
*
*
* - If an ArrayList<String> lines contains: "Course" and "CIT590", and we call
*
* getNextStringStartsWith("Course"), we'll get the String "CIT590".
*
*
*
* - If an ArrayList<String> lines contains: "hello" and "world", and we call
*
* getNextStringStartsWith("goodbye"), we'll get null.
*
*
*
* @param str to look for in lines
*
* @return String from the very next line
*
*/

String getNextStringStartsWith(String str) {

Iterator<String> iterator = lines.iterator();
while (iterator.hasNext() &&!iterator.next().equals(str)) {
iterator.next();
}

return iterator.next();

}

}
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning