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]
4 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]4 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
A rectangular open box, 25 ft by 10 ft in plan and 12 ft deep weighs 40 tons. Sufficient amount of stones is placed in the box a
dimulka [17.4K]

Answer:

44.95 tonnes

Explanation:

According to principle of buoyancy the object will just sink when it's weight is more than the weight of the liquid it displaces

It is given that empty weight of box = 40 tons

Let the mass of the stones to be placed be = M tonnes

Thus the combined mass of box and stones = (40+M) tonnes..........(i)

Since the box will displace water equal to it's volume V we have volume of box = 25ft*10ft*12ft= 3000ft^{3}

Volume= 84.95m^{3}

Since 1ft^{3} =0.028m^{3}

Now the weight of water displaced = Weight =\rho \times Volumewhererho is density of water = 1000kg/m^{3}

Thus weight of liquid displaced = \frac{84.95X1000}{1000}tonnes=84.95 tonnes..................(ii)

Equating i and ii we get

40 + M = 84.95

thus Mass of stones = 44.95 tonnes

3 0
3 years ago
You don't know which insert you have, and the inserts are different sizes, meaning the amount needed for a 1:3 ratio is differen
VashaNatasha [74]

Answer:

Explanation:

For ligation process the 1:3 vector to insert ratio is the good to utilize . By considering that we can take 1 ratio of vector and 3 ratio of insert ( consider different insert size ) and take 10 different vials of ligation ( each calculated using different insert size from low to high ) and plot a graph for transformation efficiency and using optimum transformation efficiency we can find out the insert size.

6 0
3 years ago
A teenager was pulling a prank and placed a large stuffed penguin in the middle of a roadway. A driver is traveling on this leve
Anvisha [2.4K]
Whats the question????
3 0
4 years ago
ممكن الحل ............
Roman55 [17]

Answer:

i dont understand

Explanation:

4 0
3 years ago
2. What is the Function of the Camshaft in an Internal Combustion Engine?
mamaluj [8]

Answer:

camshaft, in internal-combustion engines, rotating shaft with attached disks of irregular shape (the cams), which actuate the intake and exhaust valves of the cylinders.

Explanation:

I'm taking an engineering/tech class. I hope this helps! :)

8 0
3 years ago
Other questions:
  • "From the earth to the moon". In Jules Verne’s 1865 story with this title, three men went to the moon in a shell fired from a gi
    5·1 answer
  • A market research survey has 15 questions and will be sent to 500 people. What is the total cost to conduct survey if it has a $
    12·1 answer
  • Explain the difference in the heat transfer modes of conduction and convection.
    14·1 answer
  • Project 8:The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exe
    5·1 answer
  • What do you need for an object to fly?
    10·1 answer
  • With a reservoir pressure of 1.0 MPa and temperature of 750 K, air enters a converging-diverging nozzle, in a steady fashion. Fl
    5·1 answer
  • A fair die is thrown, What is the probability gained if you are told that 4 will
    12·1 answer
  • Find the general solution of the equation<br>a) Tan A = 1/√3​
    11·1 answer
  • There are two methods to create simple robots. First, you can construct them by purchasing various individual components and ass
    15·1 answer
  • Instructions: For each problem, identify the appropriate test statistic to be use (t test or z-test). Then compute z or t value.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!