Question: Given the following Student and ArrayQueue classes Write a java method named findStudentName that finds and returns the name of a student from a given
Given the following Student and ArrayQueue classes Write a java method named findStudentName that finds and returns the name of a student from a given Queue. The method receives student id, then searches in the queue to find and return the student name. Test the method by creating a queue with number of students, and then read student id from the keyboard and call the method to find and display the student name. the subject is data structure and i need the code in java and there are two classes one for writiing method and the othe is Implementation for testing
// The Student Class import java.util.*; public class Student { private int studentId; // Student Id number private String studentName; // Student Name private int studentGender; //student Gender 1 male, 2 Female public Student(int e, String n, int g) { studentId = e; studentName = n; studentGender = g; } public int getStudentId( ) { return studentId; } public String getStudentName( ) { return studentName; } public int getStudentGender( ) { return studentGender; } } //********** end of Student Class******** //end of Student class //Start of ArrayQueue class public class ArrayQueue{ public class ArrayQueue { private Student[] data; private int front = 0; // index of front private int qSize = 0; // queue size // constructors public ArrayQueue(int CAPACITY) { data = new Student[CAPACITY]; }
public int size() { return qSize; }
public boolean isEmpty() { return (qSize == 0); }
public void enqueue(Student e) { int avail = (front + qSize) % data.length; data[avail] = e; qSize++; }
public Student first() { return data[front]; } public Student dequeue() { Student answer = data[front]; front = (front + 1) % data.length; qSize--; return answer; } //Class Implementation import java.util.*; public class testArrayQueue{ static Scanner console = new Scanner(System.in); public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayQueue myQueue = new ArrayQueue(100); int id; int gender; String ename; Student st; while(true){ System.out.print("Enter Student Number (999 to stop): "); id = console.nextInt(); if(id==999) break; System.out.println("Enter Student Name: "); ename = in.nextLine(); System.out.print("Enter Student gender (1 male, 2 female): "); gender = console.nextInt(); st = new Student(id, ename, gender); myQueue.enqueue(st); } //testing findStudentName } // End of main }//end of class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
