Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Working with arrays and trying to figure out how to put this together. Ive creat

ID: 3662933 • Letter: W

Question

Working with arrays and trying to figure out how to put this together. Ive created the driverclass but need help with this.

***********************************

Stores and prints a line at a DMV. Write a DMV class that implements these members:

An instance constant that holds the maximum number of a line.

Three instance variables that hold, respectively, the actual number of people in line, an array of the names of the people in line, and the DMV workers name.

A constructor that stores the maximum number of the line and the workers name.

An addCustomer method that adds a customer to the line list or prints an error message if the customer is already on the list or there’s no more room in the line.

helper method, isInLine, that receives a parameter named customer. The method returns true if customer is in the line and returns false otherwise.

A printDMVLINE method that prints the DMV representative and customer.

******************************************

Explanation / Answer

import java.io.* ;

import java.util.*; //for using the dynamic array.

public class DMV // class definition

{

public int max_no_line=20 ; //constant

public int no_persn_inline;

public DMV( int no_persn_inline) // constuctor

{

this.no_persn_inline=no_persn_inline; // initialization

}

public addCustomer(String name) // to add customer in Line, it takes as customer name as parimeter

{

int t=isInLine(name);

if(t)

{
System.out.println("ERROR:Array already contains name" + name);
}

else // adding customer into line

{
  names_of_the_people.add(name);

}

}

public boolean isInLine(String name) //helper function definition

{

boolean contains = false;
  for(int i=0; i < names_of_the_people.length; i++) //iterate the String array

{

if(names_of_the_people[i].equals(name)) //check if string array contains the string

{

  contains = true;     //string found
break;

}
}

return contains ; //returning the value

}

}// end of class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote