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
When designing a car that runs on wind or Air car . can you tell me the details for the following points Compressed Air Engine:
BabaBlast [244]

Answer:

a)

The crack and connecting rod is used in the design of car.This mechanism is known as slider -crank mechanism.

Components:

1.Inlet tube

2. Wheel

3. Exhaust

4. Engine

5.Air tank

6.Pressure gauge

7.Stand

8. Gate valve

b)

The efficiency of air engine is less as compare to efficiency of electric engine and this is not ecofriendly because it produce green house gases.These gases affect the environment.

c)

it can run around 722 km when it is full charge.

                                                                                                                                                     

5 0
3 years ago
Suppose there are 76 packets entering a queue at the same time. Each packet is of size 5 MiB. The link transmission rate is 2.1
tia_tia [17]

Answer:

938.7 milliseconds

Explanation:

Since the transmission rate is in bits, we will need to convert the packet size to Bits.

1 bytes = 8 bits

1 MiB = 2^20 bytes = 8 × 2^20 bits

5 MiB = 5 × 8 × 2^20 bits.

The formula for queueing delay of <em>n-th</em> packet is :  (n - 1) × L/R

where L :  packet size = 5 × 8 × 2^20 bits, n: packet number = 48 and R : transmission rate =  2.1 Gbps = 2.1 × 10^9 bits per second.

Therefore queueing delay for 48th packet = ( (48-1) ×5 × 8 × 2^20)/2.1 × 10^9

queueing delay for 48th packet = (47 ×40× 2^20)/2.1 × 10^9

queueing delay for 48th packet = 0.938725181 seconds

queueing delay for 48th packet = 938.725181 milliseconds = 938.7 milliseconds

4 0
3 years ago
The period of an 800 hertz sine wave is
sukhopar [10]

Explanation:

White Board Activity: Practice: A sound has a frequency of 800 Hz. What is the period of the wave? The wave repeats 800 times in 1 second and the period of the function is 1/800 or 0.00125.

3 0
2 years ago
stimate the maximum efficiency of an automobile engine that has a compression ratio of 5:1.0. Assume the engine operates accordi
Fed [463]

Answer:

Efficiency based on Otto cycle.

Effotto = 47.47%

Explanation:

Efficiency based on Otto cycle.

effotto = 1 – (V2 / V1)^γ-1

effotto = 1 – (1 / 5)^1.4 - 1

effotto = 47.47%

5 0
3 years ago
What are the advantages and disadvantages of a mine heardgear​
Irina18 [472]

Answer:

If there is a shaft with headgear, then mining can take place until that depth of the shaft. If it is accessed horizontal Adits, it can mine until the lowest Adit from upwards. If it is accessed decline, the development and mining can continue so long as economic exploitation is possible.

Explanation:

What are the disadvantages of mining headgear? They totally cut off your vision of anything above your head. They are hot, most of the time

7 0
1 year ago
Other questions:
  • An alloy has a yield strength of 818 MPa and an elastic modulus of 104 GPa. Calculate the modulus of resilience for this alloy [
    13·1 answer
  • Explain how the objects in a battery work with its components
    10·1 answer
  • Two variables, num_boys and num_girls, hold the number of boys and girls that have registered for an elementary school. The vari
    8·1 answer
  • For the reactions of ketone body metabolism, _______.
    15·1 answer
  • An approach to a signalized intersection has a saturation flow rate of 1800 veh/h. At the beginning of an effective red, there a
    15·1 answer
  • The shaft is hollow from A to B and solid from B to C. The shaft has an outer diameter of 79 mm, and the thickness of the wall o
    6·1 answer
  • A gas has an initial volume o.25m^3, and absolute pressure 100kPa. Its initial temperature is 290k. The gas is compressed into a
    11·1 answer
  • soy nueva en esto me pudieran ayudar nadie me ayuda soy de peru y no endiendo nada de lo que me dicen alguie me puediera explica
    10·1 answer
  • QUICK!<br> WHAT DOES BIOCHEMICAL MEAN?
    11·2 answers
  • If a 110-volt appliance requires 20 amps, what is the total power consumed?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!