1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
xz_007 [3.2K]
3 years ago
8

You will create three classes, the first two being Student and LineAtOfficeHour. The instances of the first class defines a sing

le student while an instance of the second class defines a line of students waiting to see an instructor in their office hour. The Student class should have the following: • Private instance variables to store the first and last name of the student. • A constructor that sets all of the instance variables. You do not need to write a no-arg constructor in addition to the constructor that sets all of the instance variables. • Public methods to get and set the instance variables and a method fullName() that returns the full name of the student (first then last) as a String (i.e., does not print it out to the screen). The LineAtOfficeHour class holds Student objects in a line and has methods to manipulate this line. • Private instance variables: o an array of Students called line. o an integer N representing the number of students in the line. o an integer back representing the index of the last student in line. • Constructors: o no-argument constructor which sets the length of the line to 5, however the line should start off empty. • a constructor that takes an array of Student objects as argument and fills the line variable with up to 5 Students (but can also take as input an array of fewer than 5 Student objects). If the given input argument array has more than 5 Students, then you should populate the line with the first 5 Students out of the input array. • Public methods: • a method called isEmpty which returns true if the line is empty. o a method called isFull which returns true if the line is full. o a method called size which returns the number of students waiting in line. o a method called enterLine which takes a Student object as the 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. o a method called see Teacher which removes the Student object from the front of the line (i.e. the student who is currently first 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. o a method called whoslnLine which returns a list (as a String) of all the names of the Students in the line, in the order they are in line (the first student first, a comma, the second name, and so on). Finally, write a driver class TestLine that will create a LineAtOfficeHour object, fill it with Student objects, and test that the methods of LineAtOfficeHour function correctly.
Engineering
1 answer:
White raven [17]3 years ago
6 0

Answer:

Complete solution is given below:

Explanation:

//student class

class Student{

  private String firstname,lastname;

 

  //constructor

  Student(String first,String last){

      this.firstname=first;

      this.lastname=last;

  }

 

  //getters and setters

  public String getFirstname() {

      return firstname;

  }

  public void setFirstname(String firstname) {

      this.firstname = firstname;

  }

  public String getLastname() {

      return lastname;

  }

  public void setLastname(String lastname) {

      this.lastname = lastname;

  }

  //function to get the fullname of student

  public String fullName() {

      return this.firstname+" "+this.lastname;

  }

}

//class for line at office hour

class LineAtOfficeHour{

 

  private Student line[];

  private int N=0;

  private int back=0;

 

  //empty constructor

  LineAtOfficeHour() {

      line=new Student[5];

  }

  //parameterized constructor

  LineAtOfficeHour(Student st[]) {

      int i=0;

      line=new Student[5];

      while(i<st.length && i<5) {

          line[i]=st[i];

          i++;

      }

      this.N=i;

      this.back=i-1;

  }

  //function to check if line is empty or not

  public boolean isEmpty() {

      if(this.N==0)

          return true;

      else

          return false;

  }

  //function to check if line is full

  public boolean isFull() {

      if(this.N==5) {

          return true;

      }else

          return false;

  }

  ///function to get the size of line

  public int size() {

      return this.N;

  }

 

  //function to add a student to the line

  public void enterLine(Student s) {

      if(isFull())

          System.out.println("Line is full!!!!");

      else {

          line[++back]=s;

          this.N++;

      }

  }

  public Student seeTeacher() {

      Student result=null;

      if(this.N>=0) {

          result=line[0];

          int i=0;

          for(i=1;i<N;i++) {

              line[i-1]=line[i];

          }

          line[i-1]=null;

          this.N--;

          this.back--;

      }

     

     

      return result;

  }

  //function to print students in line

  public String whosInLine() {

      String result ="";

      for(int i=0;i<this.N;i++) {

          result+=line[i].fullName()+",";

      }

      return result;

  }

}

//driver method

public class TestLine {

  public static void main(String[] args) {

      LineAtOfficeHour list=new LineAtOfficeHour();

     

      if(list.isEmpty()) {

          System.out.println("Line is empty!!!!!!!!!");

      }

     

      Student s1[]=new Student[3];

      s1[0]=new Student("John","Smith");

      s1[1]=new Student("Sam","Zung");

      s1[2]=new Student("Peter","Louis");

      list=new LineAtOfficeHour(s1);

     

      if(list.isEmpty()) {

          System.out.println("Line is empty!!!!!!!!!");

      }else {

          System.out.println("Line is not empty.........");

      }

     

      System.out.println("Students in line: "+list.whosInLine());

     

      System.out.println("Student removed: "+list.seeTeacher().fullName());

     

      System.out.println("Students in line: "+list.whosInLine());

  }

}

You might be interested in
In this type of projection, the angles between the three axes are different:- A) Isometric B) Axonometric C) Trimetric D) Dimetn
nekit [7.7K]

Answer:

The correct answer is C) Trimetric

Explanation:

The most suitable answer is a trimetric projection because, in this type of projection, we see that the projection of the three angles between the axes are not equal. Therefore, to generate a trimetric projection of an object, it is necessary to have three separate scales.

7 0
3 years ago
In a production turning operation, the foreman has decreed that a single pass must be completed on the cylindrical workpiece in
stellarik [79]

Answer:

V = 125.7m/min

Explanation:

Given:

L = 400 mm ≈ 0.4m

D = 150 mm ≈ 0.15m

T = 5 minutes

F = 0.30mm ≈ 0.0003m

To calculate the cutting speed, let's use the formula :

T = \frac{pi* D * L}{V*F}

We are to find the speed, V. Let's make it the subject.

V = \frac{pi* D * L}{F*T}

Substituting values we have:

V = \frac{pi* 0.4 * 0.15}{0.0003*5}

V = 125.68 m/min ≈ 125.7 m/min

Therefore, V = 125.7m/min

7 0
3 years ago
Component(s) that only allow(s) electrons to flow in one direction. Mark all that apply
Korolek [52]

Answer:

A,D, and E

Explanation:

6 0
3 years ago
The host at the end of the video claims that ___________ is crucial to his success as a driver. A. Reaction time B. A safe space
Snezhnost [94]

Answer:

answer is C. his seat belt

5 0
2 years ago
Suppose the working pressure for a boiler is 10 psig, then what is the corresponding absolute pressure?
yanalaym [24]

Answer:

The corresponding absolute pressure of the boiler is 24.696 pounds per square inch.

Explanation:

From Fluid Mechanics, we remember that absolute pressure (p_{abs}), measured in pounds per square inch, is the sum of the atmospheric pressure and the working pressure (gauge pressure). That is:

p_{abs} = p_{atm}+p_{g} (1)

Where:

p_{atm} - Atmospheric pressure, measured in pounds per square inch.

p_{g} - Working pressured of the boiler (gauge pressure), measured in pounds per square inch.

If we suppose that p_{atm} = 14.696\,psi and p_{g} = 10\,psi, then the absolute pressure is:

p_{abs} = 14.696\,psi+10\,psi

p_{abs} = 24.696\,psi

The corresponding absolute pressure of the boiler is 24.696 pounds per square inch.

8 0
2 years ago
Other questions:
  • To operate a vehicle in Florida, you must
    10·2 answers
  • . A storm sewer is carrying snow melt containing 1.200 g/L of sodium chloride into a small stream. The stream has a naturally oc
    8·1 answer
  • A car is traveling at 36 km/h on an acceleration lane to a freeway. What acceleration is required to obtain a speed of 72 km/h i
    12·1 answer
  • A turntable A is built into a stage for use in a theatrical production. It is observed during a rehearsal that a trunk B starts
    5·1 answer
  • The convection heat transfer coefficient for a clothed person standing in moving air is expressed as h 5 14.8V0.69 for 0.15 , V
    6·2 answers
  • Which is the required type of fire extinguisher for standard naval vessels
    9·1 answer
  • A Carnot heat engine absorbs 235 KW of heat from a heat source and rejects 164 KW to the atmosphere. Determine the thermal effic
    7·1 answer
  • Whats the purpose of the keyway
    13·1 answer
  • Reason fo I.EE regulations in electrical installations​
    13·1 answer
  • (i) what assumptions about the relationship between the inputs and output are inherent in this specification? do scatter plots s
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!