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

Java Project. For this project, you will create a class for an elementary school

ID: 3920826 • Letter: J

Question

Java Project.

For this project, you will create a class for an elementary school that will allow a teacher to enter each student's seating assignment. Occasionally, the teacher may need to switch the seating assignment of a student. If there is a seat available, the student is moved. If all of the seats are already assigned, the teacher will have two students trade seats.

Minimum Requirements: Create a class that has a string array of size 20 as a private data member. You cannot use a List or ArrayList for this assignment (5 points). Include a function to add students to the seating chart array (5 points). Position 0 of the array represents the seat closest to the teacher's desk. The array index will represent each seat number for the seating assignments. Include a function that will accept a student name and a target seat. This function should find the students name in the array and move the student's name from his or her original seat to the target seat. If the target seat is empty, move the student's name to the target seat. If the target seat is not empty, swap the names of the students so they trade seating assignments. (5 points).

Hints:

The swap algorithm can be very helpful with this project. You can find an example in the lab activity:  Lab: Shell Games

You will need to decide on a way to track which seats are available.

Explanation / Answer

class Seating {

    private String[] seatingChart;
    private int size;

    public Seating(){
        seatingChart = new String[20];
        for (int i = 0; i<20; i++){
            seatingChart[i] = "empty";
        }
        size = 0;
    }
    public void add(String name){
       if (size < 20){
          seatingChart[size] = name;
       }        
       else {
          System.out.println("Class is full ");
       }
    }
    public void assignSeat(String name, int index){
        if (index <0 || index >= 20){
           System.out.println("Invalid target seat ")
           return;
        }
        int found = 0;
        for (int i = 0; i<size; i++){
            if (seatingChart[i].equals(name)){
               found = 1;
               if (seatingChart[index] == "empty"){
                   seatingChart[i] = "empty";
                   seatingChart[index] = name;
               }
               else {
                    String temp = seatingChart[index];
                    seatingChart[i] = temp;
                    seatingChart[index] = name;
               }
               break;
            }
        }
        if (found == 0){
           System.out.println("Name not found ");
        }
    }
}

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