EE 422C HW 6 Multithreaded Programming

Similar documents
CSCI 1301: Introduction to Computing and Programming Spring 2019 Lab 10 Classes and Methods

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

CSCI 1301: Introduction to Computing and Programming Summer 2018 Lab 07 Classes and Methods

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment

CMPSCI 187 / Spring 2015 Sorting Kata

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Assignment 19 Deadline: Nov pm COSC211 CRN15376 Session 15 (Nov. 7)

Com S 227 Assignment Submission HOWTO

CMPSCI 187 / Spring 2015 Hangman

CS61BL: Data Structures & Programming Methodology Summer Project 1: Dots!

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

CSE 143: Computer Programming II Winter 2019 HW6: AnagramSolver (due Thursday, Feb 28, :30pm)

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

Part 1: Group Brainstorm (NO computers during this time) Part 2: Submit Individual Brainstorm (You can now use a computer)

Problem 1: Building the BookCollection application

Assignment 4: Hashtables

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

Summary. Recursion. Overall Assignment Description. Part 1: Recursively Searching Files and Directories

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Laboratory Assignment #3 Eclipse CDT

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

Recommended Group Brainstorm (NO computers during this time)

Lab 1: Introduction to Java

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Problem 1: Building and testing your own linked indexed list

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Programming Project 5: NYPD Motor Vehicle Collisions Analysis

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

Project 1 for CMPS 181: Implementing a Paged File Manager

Final Project Option #1 Restaurant Simulation

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Using System.out.println()

CSE 143: Computer Programming II Summer 2015 HW6: 20 Questions (due Thursday, August 13, :30pm)

contain a geometry package, and so on). All Java classes should belong to a package, and you specify that package by typing:

EECE.2160: ECE Application Programming

CS 2316 Homework 9b GT Thrift Shop Due: Wednesday, April 20 th, before 11:55 PM Out of 100 points. Premise

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

Com S 227 Spring 2018 Assignment points Due Date: Wednesday, March 28, 11:59 pm (midnight) "Late" deadline: Thursday, March 29, 11:59 pm

CMPSCI 187 / Spring 2015 Hanoi

Regis University CC&IS CS310 Data Structures Programming Assignment 2: Arrays and ArrayLists

CIT 590 Homework 5 HTML Resumes

CSCI544, Fall 2016: Assignment 1

Tips from the experts: How to waste a lot of time on this assignment

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Documentation Requirements Computer Science 2334 Spring 2016

Assignment Submission HOWTO

Classes Classes 2 / 36

CSE 373: Homework 1. Queues and Testing Due: April 5th, 11:59 PM to Canvas

PIC 10B Lecture 1 Winter 2014 Homework Assignment #3

Lab 1: First Steps in C++ - Eclipse

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

Lab 3: Call to Order CSCI 2101 Fall 2018

EE109 Lab Need for Speed

Address book. Presenting the Java assignment about an Address Book v

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Introduction to Programming System Design CSCI 455x (4 Units)

CSE 143: Computer Programming II Spring 2015 HW2: HTMLManager (due Thursday, April 16, :30pm)

Homework 2: Imperative Due: 5:00 PM, Feb 15, 2019

CSC209 Review. Yeah! We made it!

Circular Linked List Assignment

Tips from the experts: How to waste a lot of time on this assignment

CSE 143: Computer Programming II Summer 2017 HW5: Anagrams (due Thursday, August 3, :30pm)

CSIS 10B Lab 2 Bags and Stacks

Shell Interface Assignment

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

CS 4218 Software Testing and Debugging Ack: Tan Shin Hwei for project description formulation

EECE.2160: ECE Application Programming

Project 5 Handling Bit Arrays and Pointers in C

ENGR 3950U / CSCI 3020U (Operating Systems) Simulated UNIX File System Project Instructor: Dr. Kamran Sartipi

CS 116. Lab Assignment # 1 1

CS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM

CMSC 341. Nilanjan Banerjee

Comp Assignment 4: Commands and Graphics

CS354/CS350 Operating Systems Winter 2004

CS18000: Programming I

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

CSCI544, Fall 2016: Assignment 2

Hands on Assignment 1

Program 1: Generating Summation Puzzles

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

CSCI 1301: Introduction to Computing and Programming

1. Introduction. 2. Project Submission and Deliverables

Lab 4: Tracery Recursion in C with Linked Lists

CS451 - Assignment 8 Faster Naive Bayes? Say it ain t so...

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Computer Science E-50a: Introduction to Computer Science Using Java, I Handout #7 part 2

Safety SPL/2010 SPL/20 1

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CS Homework 11 p. 1. CS Homework 11

CSE 1325 Project Description

Imperative and Object Oriented Programming. Tutorial 1. Charlie Abela Department of Artificial Intelligence

CMSC 201 Fall 2018 Lab 04 While Loops

ECE 3574: Applied Software Design

Transcription:

EE 422C HW 6 Multithreaded Programming 100 Points Due: Monday 4/16/18 at 11:59pm Problem A certain theater plays one show each night. The theater has multiple box office outlets to sell tickets, and the box offices sell tickets to clients on a first come, best seat basis. That is, the next client in line always gets the best available seat. Your program will simulate the box offices and the theater. You will process a line of clients, determine the next-best available seat for each client, acquire that particular seat and finally print the ticket. Processing Requirements Allowed assumptions: the lines are never empty at the start each client can buy only one ticket clients waiting in line are numbered sequentially starting at 1 client numbers are unique even across multiple lines when the show sells out you can stop processing clients when there are no more clients you can stop selling tickets Clients are processed according to the following pseudocode: Repeat for each client until show is sold out or no more clients Seat <- find the best available seat If there is an available seat, then mark the seat as taken print the ticket End repeat if (sold out) Output to the screen only once Sorry, we are sold out! Theater configuration The theater can have N rows and M seats for each row. Rows are ordered sequentially using letters (A, B, C,, Z, AA, AB, AC,..., AAA) and so on for a total of N number of rows). Seats are numbered from 1 to M. The best seat is the least combination of seat row and seat number. Best seat order example for N = 2 and M = 2: [ A1 > A2 > B1 > B2 ] Concurrency Requirements 4/13/18 10:04 AM 1

Since waiting in a single line is inefficient, the theater manager has multiple box offices working to sell tickets simultaneously. Each box office is represented as a separate thread of execution and has its own queue of clients. Remember that there is still only 1 theater and 1 show that is being booked. Concurrency constraints Only one ticket may be printed for a seat at a show. Ticket class (can be an inner class) The tostring() method should return the string that prints to console like the one below. You need not worry about overly long show names, ID's, seat numbers, etc. that won't fit into the bounding box as shown below. Box Office ID: BX1 Seat: D104 Client: 4 Seat class (can be an inner class) The tostring() method should return a string with the row letter appended with the seat number like in the ticket example above D104. Theater class Seat bestavailableseat() This method calculates the next best available seat according to the theater configuration. For example, consider a theater with 2 rows, 2 seats per row and 2 tickets have been sold. This method would return B1 since A1 and A2 have been reserved. Ticket printticket(string boxofficeid, Seat seat, int client) This method prints the ticket as if the box office physically processed and printed a ticket for a particular seat. Also print each ticket sold to the console with a small delay for human readability (50 ms). Return null if a box office failed to reserve the seat. List<Ticket> gettransactionlog() This method returns a list of all tickets sold for the current show in the order in which they were purchased. BookingClient 4/13/18 10:04 AM 2

List<Thread> simulate() This method starts the multithreaded simulation. Create your threads in this method and also start them. Return a list of all the threads you create. We will test your program by instantiating BookingClient with different parameters, and then invoking simulate. Main method Your BookingClient class file must have a main method. This main method must initialize the offices and theater with the same data as the example output shown below, and must call simulate(). Example Console Output Newlines may be slightly different from the data below, although you should try to reproduce the output as shown. You may assume that show names are short. Simulation Parameters: office: {BX1=3, BX3=3, BX2=4, BX5=3, BX4=3} theater: {3 rows, 5 seats per row, show: Ouija"} Box Office ID: BX1 Seat: A1 Client: 1 Box Office ID: BX4 Seat: A2 Client: 5 Box Office ID: BX2 Seat: A3 Client: 3 Box Office ID: BX5 Seat: A4 Client: 4 4/13/18 10:04 AM 3

Box Office ID: BX4 Seat: A5 Client: 7 Box Office ID: BX1 Seat: B1 Client: 6 Box Office ID: BX2 Seat: B2 Client: 8 Box Office ID: BX2 Seat: B3 Client: 12 Box Office ID: BX5 Seat: B4 Client: 9 Box Office ID: BX4 Seat: B5 Client: 10 4/13/18 10:04 AM 4

Box Office ID: BX5 Seat: C1 Client: 14 Box Office ID: BX2 Seat: C2 Client: 13 Box Office ID: BX1 Seat: C3 Client: 11 Box Office ID: BX3 Seat: C4 Client: 2 Box Office ID: BX3 Seat: C5 Client: 15 Sorry, we are sold out! (You may print this line just once overall). Process finished with exit code 0 (not required in your output) What to submit: 1. The package directory assignment6 and all Java files it contains *** Zip these two item together and name the zip file Project6_EID.zip *** 4/13/18 10:04 AM 5

When unzipped, the folder structure should be: project6_eid(folder) ->assignment6(folder) --->Theater.java --->BookingClient.java --->other.java Grading details: Your assignment will be graded first by compiling and testing it for correctness. After that, we will read your code to determine whether all requirements were satisfied, as well as judge the overall style of your code. Points will be deducted for poor design decisions and un-commented, or unreadable code as determined by the TA. Here is the point breakdown: Correctness of the program - 48 points Correct usage of concurrency constructs - 28 points Console output 12 points Coding style - 12 points Code structure FAQ Q1: Should the client ID's match the ones in the sample output? A1: No. The client ID's should be unique, that's all. You should use some sort of reasonable ordering scheme, so that in most cases, no numbers in a sequence will be altogether skipped, although they might be printed out of order. The seat ID's should be in order of sale. Q2: Where do I implement the pseudo-code listed on page 1? A2: Wherever it is suitable. Q3: What should we print out if the number of clients run out before the show is sold out? A3: Print out no final message. Just exit the program. Q4: How should we input the initial parameters for the booking offices and the theater? A4: You may hard-code these values in your code when submitting. Q5: Are we allowed to add fields to the classes? Any restrictions (like static, private, etc.)? A5: Don't use static variables in BookingClient or Theater. You may use non-static variables in Theater, for example to hold client ID. Don t change the number or type of arguments passed into the constructor. Don t change method declaration (except as described further down in this document). You are allowed to add helper methods (but make them private), except for getters and setters. Q6: May we use System.exit()? A6: No. 4/13/18 10:04 AM 6

Q7: Is it ok to add a variable inside the static seat class? Is it ok to add an extra line to the constructor of the static seat class? A7: You may add variables to the class and lines to the constructor, just not change the number or type of arguments passed into the constructor. Q8: If there are N seats, should we print "Sold Out" as soon as N tickets are sold? A8: Yes, you should, but only after the last ticket has been printed. Don't wait for client N+1 to be processed. Q9: Are we allowed to change the method header to add 'synchronized'? A9: Yes. Q10: Is a class diagram sufficient for the UML diagram requirement? A10: You don t need to turn in a UML document. Q11: How do I debug multiple threads using Eclipse? A11: Search the web. For example http://stackoverflow.com/questions/5375538/debugging-multiple-threads-in-eclipse Q12: In my program, each box office gets processed completely before other unprocessed ones. Is this OK? A12: No, this is not, as you are not treating them all fairly. Q13: No src folder this time under assignment6? A13: No. (However, this requirement is subject to change. Please watch Piazza announcements.) Q14: Do we get a grading script and test files? A14: Yes, we will post those also. Q15: Are we allowed to make our classes implement interfaces? A15: Yes. Q17: Are we allowed to add other inner classes? A17: Y es. Q18: (4) What is the purpose of the the BookingClient Constructor? A18: List<Thread> simulate() starts the multithreaded simulation. Create your threads in this method and also start them. Return a list of all the threads you create. We will test your program by instantiating BookingClient with different parameters and then invoking simulate. 4/13/18 10:04 AM 7

Q19: In the lab descriptor, it says the gettransactionlog method "returns a list of all tickets sold for the current show in the order in which they were purchased." Does this mean the most recent purchase is the first in the list, or would it be the last? A19: Use list/queue, the first one sold is the first one in the list. Q20: What would be a good way to compare Seats? A20: You could make a Comparator<Seat> class, and then pass it to some sort function. CHECKLIST Did you remember to: Work on the assignment on your own? Re-read the requirements after you finished your program to ensure that you meet all of them? Make sure that your program passes all your test cases? Ensure that all your.java files have the proper header? Upload your solution to Canvas in a zip file with the proper filename? Download your uploaded solution into a fresh directory and re-run all test cases? 4/13/18 10:04 AM 8