Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMSC-205 SPRING 2024 ASSIGNMENT 1

Due February 18 at 11:55 PM

Submission Checklist

Your final submission to Gradescope must have the following files:

   SeatReserver.java - contains your main java program.

   A README.txt file that clearly states:

   Your name and the name of the assignment

   Attribution for any sources used

   Any notes on questions, difficulties, or bugs

●   An ImpactsReflection.pdf file which contains your answers to the impacts reflection.

Background

Your favorite music artist is in town and you get to reserve front-row seats (for free) -

congratulations! Unfortunately, to do that, you need to finish writing the software which will let you reserve those seats.

When complete, this program will allow a user to check the status of seats in the front row and reserve one or more seats. For users wishing to reserve multiple seats, the program will assume that the seats do not need to be next to each other (non-contiguous). For an additional challenge, you may add the capability to reserve a set of seats which are all next to each other (contiguous).

We’ve provided you with a partially-complete program which already handles user input – you need to finish the part which keeps track of and reserves seats.

The Assignment

Java Program

In this assignment, you will finish writing a class called Seat Reserver which keeps track of which seats have been reserved in a row of arena seats. We have provided you with a Main class containing a complete main method which handles user interaction - you do not need to  modify the Main class.  Your job is to fill in the body of the constructor and each of the methods in Seat Reserver described below. These are listed in the recommended order of writing them.

Remember to write-a-little then test-a-little so that you can be sure your code is working as you go, instead of writing a lot of code before doing any testing.  To facilitate this, the starter code has an empty testCode method.  After each method you write, you should add some code to testCode to test that the code works.  The testCode method is called at the beginning of the main method, so it will run before getting to the user interaction.

NOTE: This assignment requires the use of starter code available on Moodle.

public SeatReserver(int totalSeats)

   This is the constructor for the class.

●    It takes 1 argument: totalSeats, which is the total number of seats that could be reserved.

   There should be 2 instance variables of this class:

   seatsReserved - a boolean array which holds the current map of reserved seats.

If an element at index i is false, then seat i is not reserved (i.e., is available).

For instance, if seatsReserved looks like:

 

0

1

2

3

4

5

6

Value:

false

false

true

true

false

true

false

Then we would say seats 0, 1, 4, and 6 are not reserved (i.e., available) and seats 2, 3, and 5 are reserved (i.e., not available).

   seatsProposed - a boolean array like seatsReserved. It will hold a copy of

seatsReserved, modified to show what the seats would look like if the user chooses to reserve seats. In other methods, it will get copied into seatsReserved if the user confirms that they want to reserve the seats. Otherwise, it will be updated to match seatsReserved.

○    Remember: unlike in Python, instance variables in Java must be declared outside of the constructor!

●   The constructor should make seatsReserved and seatsProposed into new arrays of the correct size (the total number of seats). Both seatsReserved and seatsProposed should be populated with the boolean false as all elements.

●   Add some code to testCode to see if your constructor works as you expect.  Notice that the starter code also includes complete methods called printSeatsReserved and printSeatsProposed which you may find helpful in your testing.

public void reserveIndivSeat(int seatNum)

   This method reserves a single seat located at seat Num.

●    It has 1 argument, seat Num, which refers to the seat number that the user wishes to reserve


●    It should set the value of that seat index in seatsReserved to true

   When writing this function, assume that the user is allowed to reserve the seat requested

– you do not first need to check if the seat is available.

   Test it!

public boolean isSeatReserved(int seatNum)

   This method checks if the seat at index seat Num is reserved.

●    It has 1 argument, seat Num, which refers to the seat number that the user wishes to check the status of.

●    It returns true if:

   the seat is reserved, OR

   the seat number entered is not valid

   Otherwise, it returns false

   Test it!

private static void copyArray(boolean[] copyFrom, boolean[] copyInto)

   This method copies one array into another

●   This method has 2 arguments: an array of booleans to copy from, and an array of booleans to copy to

●    It copies the values of copyFrom into copyInto. At the end, copyInto should be changed to look like copyFrom

   This method is declared static since it does not need the instance variables.

●    Hint: If you try to use copyInto = copyFrom, any change you make to one array will also change the other. Find another way to copy the data!

   You may assume that copyFrom and copyInto have the same length

   Test it!

public boolean nonContiguousAvailable(int numSeatsWanted)

   This method checks if the total number of seats available (not reserved) is >= the

number of seats that the user wants to reserve. For example, if numSeatsWanted is 7, it is checking if there are at least 7 seats available.

   This method takes 1 argument, the number of seats to check.

●    It returns true if it is possible to reserve the number of seats requested (numSeatsWanted), or false otherwise.

   Test it!

public boolean planNonContiguous(int numSeatsWanted)

●   This method checks if it would be possible to reserve numSeatsWanted seats (Hint: to do this, use another function you’ve already written for this assignment!).

●    If it is possible to reserve the number of seats requested, it should first copy the values from the seatsReserved array into the seatsProposed array, and then modify the seatsProposed array to reflect what seatsReserved would look like if the requested seats were reserved too.

●   Your method should return true IF it has modified seatsProposed (and return false otherwise)!

   Test it!

public void confirmReservation()

●   This method updates seatsReserved to match seatsProposed. It is called when the user has requested seats, been shown what the updated seat map would look like, and confirmed that they would like to reserve the seats.

●    Hint: This method should contain a single function call to a function you've already written!

   Test it!

●    Remember before submitting your code to comment out the call to testCode that is in the main method.

Evaluation:

This section contains a summary of how your program will be evaluated.

Your Java program will be evaluated on:

●   Correctness - Do the constructor and methods behave consistently with the description above?

   Array usage - Are arrays used and updated correctly?

●    Loops - Are loops used appropriately?

●    Documentation - Are there comments present, describing what the code does?

   Style - Are variables named appropriately? Is the indentation consistent?

README

Your README should be a text file (README.txt) that clearly states:

●    Your name and the name of the assignment

●    Attribution for any sources used

●    Any notes on questions, difficulties, or bugs

Evaluation:

Your README will not be evaluated directly, but is critical for explaining your work and thought process. Your README can help increase your score for the rest of the program in the case  where you hit an obstacle that you cannot figure out how to overcome.

Reflection on Impacts

One of the goals of this course is to prepare you to reflect on and discuss how choices made in algorithms and code impact people.

You should submit a PDF containing 2-3 short paragraphs of reflection or separate responses to each question.

There are many assumptions made about the needs of program users and the people who will sit in the reserved seats which allow this program to work the way it does. While assumptions and simplifications are necessary to build programs and model reality, each one has a

consequence. In this reflection, you will practice identifying these assumptions and their impacts. In your reflection, answer each of the following prompts:

1.   What is 1 assumption made about the needs of the user or the people who would sit in the reserved seats?

2.  What impact does this assumption have on that group?

3.  What would need to change about the program to mitigate that impact or remove the assumption?

Evaluation:

Your reflection on social or human impacts will be evaluated on:

●    Depth & Breadth - How well does the reflection meaningfully engage with the impacts of the choices made?

To get credit for your reflection, we are looking for both evidence (what are you basing your responses on or responding to?) & interpretation (your explanation or analysis of the evidence) in your answers. In other words, to receive full credit, it is not enough to say that something is good, bad, or in between – you must provide an explanation of why. What impacts or consequences do you see? Who (or what) is harmed?

Hints and Advice

1.   Read through the Main class, especially the comments. Get an idea for what each part does.

2.   For all the methods that have return types other than void, put in temporary return

values. For example, if a method returns a boolean, you can put “return false;” If it returns an int, you can put “return -1;” If it returns nothing, you can skip this. This will let you run your code to test it without throwing errors.

3.  When testing methods that return boolean, remember to test in situations where true is the correct answer and other situations where false is the correct answer.

4.   Before submitting, comment out the call to testCode. Run main. Double check that your code behaves as expected.

Assignment Submission

Using the Gradescope assignment, submit:

●    Seat Reserver.java

●    README.txt

●    Reflection.pdf

Challenge

What if you only wanted seats next to your friends? There’s a harder version of getting a group of seats where you only want to reserve contiguous (next-to-each-other) seats. If you want to stretch your muscles, try adding the following methods to your code. Please note in the

readme if you attempted this. If the challenge code does not compile, please comment it out!

public int findContiguous(int numSeatsWanted)

   This method checks whether there is a contiguous set of seats of size

numSeatsWanted which are currently available in seatsReserved. For instance, if

numSeatsWanted is 6, it is checking whether there are 6 seats in a row which are not reserved.

   Your function should return:

   -1 if it is not possible to book numSeatsWanted contiguous seats

○   OR, if numSeatsWanted contiguous seats are available, the smallest index where that set of seats begins.

●    For instance, if seatsReserved looks like:

0

1

2

3

4

false

true

false

false

true

○    findContiguous(3) should return -1 because there are not 3 false seats next to each other)

○    findContiguous(2) should return 2 because there are 2 seats which are not reserved (have a value of false) next to each other. This sequence of 2 false values begins at index 2.

○    findContiguous(1) should return 0 because there are several seats which are not reserved. The smallest index where this occurs is at 0.

public boolean planContiguous(int numSeatsWanted)

●   This method checks if it would be possible to reserve numSeatsWanted seats in a contiguous sequence.

●    If it is, it modifies the seatsProposed array to reflect what seatsReserved would look like if the requested seats were reserved too.

●    Notice: This function should work similarly to planNonContiguous, but it is reserving a contiguous set of seats (instead of the first un-reserved seats it comes across.

●   Your method should return true IF it has modified seatsProposed (and return false otherwise)!