Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

/** * *********************** Provided class - do not modify. *********************** * This class represents a student. Each student has a name and a problem difficulty. * Note: Student objects are...

1 answer below »
/** * *********************** Provided class - do not modify. *********************** * This class represents a student. Each student has a name and a problem difficulty. * Note: Student objects are immutable - that is, there are no mutator methods in this * class by design. */ public class Student { // instance variables private String name; private String problemDifficulty; //class constant private static final String[] DIFFICULTY_CODE = {"very easy", "easy", "medium", "difficult", "very difficult"}; /** * Constructor for objects of class Student - all Student * objects must have a name and a problem difficulty. */ public Student(String name, String problemDifficulty) { XXXXXXXXXXthis.name = name; XXXXXXXXXXif (contains(DIFFICULTY_CODE, problemDifficulty)) { XXXXXXXXXXthis.problemDifficulty = problemDifficulty; }else { XXXXXXXXXXthis.problemDifficulty = "medium"; XXXXXXXXXXSystem.out.println("Invalid problem difficulty for student: " + name + ". Defaulting to \"medium\"."); } } /** * accessor method for Student's name. */ public String getName() { XXXXXXXXXXreturn name; } /** * accessor method for Student's problem difficulty. */ public String getDifficulty() { XXXXXXXXXXreturn problemDifficulty; } /** * toString - returns the String representation of a Student object. */ public String toString() { XXXXXXXXXXreturn "{ Student's name: " + name + ", Problem difficulty: " + problemDifficulty + " }"; } /** * private class method contains - helps validate the problem difficulty code * in the constructor. */ private static boolean contains(String[] array, String target) { XXXXXXXXXXfor (int i = 0; i < array.length; i++) { XXXXXXXXXXif (array[i].toLowerCase().equals(target.toLowerCase())) return true; } XXXXXXXXXXreturn false; } }

Part 1: (No template provided) Write a class called LineAtOfficeHour to represent a line of students waiting
to speak with their teacher during an oce hour. The teacher observes a \ rst-come- rst-serve" policy, and the
most students that can t in a line in the teacher's oce is 10. For this exercise, you will need to work with
the provided Student class containing various constructors and methods (do not modify this class) - so make
sure you read and understand how to use the Student class before tackling this assignment.
Your class should have the following variables, constructors and methods:
instance variables:
- an array of Students called line,
- an integer N representing the number of students in the line,
- an integer back representing the index of the last student in line;


constructors:
- a no-argument constructor which sets the length of the line to 10, however the line should start o
empty;
- a constructor that takes an array of Student objects as argument and lls the line variable with up
to 10 Students. If the given argument array has more than 10 Students, then you should populate
the line with 10 random Students out of the given array;


a method called isEmpty which returns true if the line is empty;
a method called isFull which returns true if the line is full;
a method called size which returns the number of students waiting in line;
a method called enterLine which takes a Student object as argument and puts it at the back of the line
(i.e. behind the last student currently in line). This method does not need to return anything. Note: if
the line is full, the Student should not be placed in the line and should be rejected with an appropriate
message;
a method called seeTeacher which removes the Student object from the front of the line (i.e. the student
who is currently rst in line gets to see the teacher when this method is called) and returns the Student
object. Note: the remaining students should move toward the front of the line as result of this method
being called;
a method called whosNext which returns the name of the Student object at the front of the line, however
it does NOT remove it from the line;
a method called studentsInLine which returns a 2-D array such that the rst column contains the names
of the students that are standing in line and the second column contains their respective problem diculty
code (see the Student class for more detail).

Answered 1 days After May 12, 2022

Solution

Vibhav answered on May 14 2022
107 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here