| CSC 207 | Grinnell College | Spring, 2015 |
| Algorithms and Object-Oriented Design | ||
Supplemental Problems extend the range of problems considered in the course and help sharpen problem-solving skills. Problems numbered 8 or higher may be turned in for extra credit.
In turning in any programs for the course, please submit the following materials, in the order specified (so the program with you name and box will be on top).
Print and submit a paper copy of each Java class (copying and pasting from Eclipse is ok)
/*****************************************************************
* Henry M. Walker *
* PO Box Science II *
* Program for CSC 207 *
* Gambling Simulation *
* Assignment for Monday, February 20 *
*****************************************************************/
/* ***************************************************************
* Academic honesty certification: *
* Written/online sources used: *
* [include textbook(s), *
* CSC 207 labs or readings; *
* complete citations for Web or other written sources] *
* [write "none" if no sources used] *
* Help obtained *
* [indicate names of instructor, class mentors *
* or evening lab tutors, consulted *
* according to class policy] *
* [write "none" if none of these sources used] *
* My signature below confirms that the above list of sources *
* is complete AND that I have not talked to anyone else *
* [e.g., CSC 161 students] about the solution to this problem *
* *
* Signature: *
*****************************************************************/
/*** * equals is a method * @param first is a String * @param last is a String * @returns a boolean value */ equals (String first, String last)
Include within your code javadoc documentation for
In particular, print and submit the javadoc documentation for your files.
A printed copy of relevant test runs (copying and pasting ok)
Commentary (typed or handwritten) regarding your testing of the code, including:
Email lab each class, test plan, test runs, and statement of correctness as separate attachments to grader-207-01@cs.grinnell.edu. Please include the assignment title (e.g., Lab 2) and the name of all co-authors in the Subject line.
if ((no_comments)
|| (missing pre- or post-conditions)
|| (formatting_does_not_show_structure)
|| (long_methods_not_divided_into_sections_with_clarifying_comments)
|| (no_evidence_of_compilation)
|| (no_test_plan___no_listing_of_circumstances__OR__no_listing_of_test_cases)
|| (no_test_runs)
|| (no_commentary_on_correctness))
|| (no_signed_certification_regarding_sources_and_help)
return (no_grade);
When a program is submitted according to the instructions specified above, it should be understood that the various pages reflect the same program. That is, the javadoc listings should have been generated by Eclipse from the code printed, and Eclipse should have run the code to generate the printed output. With this understanding, editing of a javadoc file or an output file is strictly forbidden and will result in automatic failure on the assignment. Such editing also may raise questions of academic dishonesty; and, by College policy, any evidence of academic dishonesty must be turned over to the Academic Standing Committee for action.
Summary: Don't even think about editing a javadoc file or an output listing.
Two grading forms will be used in the grading of each supplemental problem.
This problem introduces some simplified elements related to a program to track shopping in a grocery store. Many details would be expanded greatly for a real application, but this problem might make a [small] start.
Items available in a grocery store might be categorized as produce (e.g., vegetables, fruit, cheese, meat, etc.), beverages (bottled water, milk, soft drinks, energy drinks, etc.), and packages (boxes of crackers, noodles, tea, etc.). A class hierarchy to model this categorization of items follows:
To clarify,
All materials in a store fall within a general category of a class Item.
Class Produce is a subclass of Item of fresh, uncooked ingredients.
A Beverage is an Item for drinking.
A Package is a subclass of Item that comes in a rectangular box.
For this problem, you should implement the following:
Class definitions for Item and its subclasses Produce, Beverage, and Package
A ShoppingCart class, modeled upon the SchoolDirectory class from the CSC 207 lab Generalization, Polymorphism, and Exceptions. The ShoppingCart class should have these features:
Students taking courses at Grinnell College may be considered to fall into one of four main categories: regular, alum, employee, and special. The following descriptions bend the rules somewhat, but provide a basic outline of each category.
Note: The actual rules for Alum, Employee, and Special students involve courses, not credits. Alum and Employee students may take 1 course; Special students may take 2 courses. In the interests of sanity for this problem, however, the above rules will be considered in effect.
Observations:
| Minimum Credits for Standing | ||
|---|---|---|
| Year | Semester 1 | Semester 2 |
| First Year | 0-11.5 | 12-27.5 |
| Second Year | 28-43.5 | 44-59.5 |
| Junior | 60-75.5 | 76-91.5 |
| Senior | 92-107.5 | 108-123.5 |
For example, a Regular student with 65 total credits would have class standing as "Junior, Semester 1".
(Note that various details and limits are ignored in the above table, so this problem can be moderately manageable.)
Directions for this Problem:
Note that the idea of the Registrar class is to provide a mechanism for testing the various other classes. In most (all?) cases, careful design of tests for the Registrar class may cover testing for this entire assignment.
When a printer serves multiple users, users may sent several print requests to the operating system, but only one file can be printed at a time. Thus, the operating system can direct a file from one print request to the printer, but the other requests must be stored in some type of data structure. The simplest approach involves a single queue. Each user sends one or more files to the operating system, and the operating system places the print requests on a queue. The operating system then sends the files to the printer one-at-a-time from the print queue. Of course, once a printer starts to print a file, the printer must complete that job before moving onto the next print request. Although this approach is simple and treats all jobs equally, this approach has the disadvantage that many short printing jobs (of only a few pages) may have to wait substantial amounts of time for a large print job (hundreds of pages) to finish.
One way to give some preference to certain print jobs is to create multiple queues of varying priorities. For convenience of notation, suppose a system has n queues, labeled q0, q1, q2, ..., qn-1. Suppose qi has priority i, where priority 0 is top priority, priority 1 is the next highest priority, ..., and priority n-1 is the lowest priority. That is requests in q0 are chosen before print requests in any other queue, and requests in qn-1 must wait until requests from all other queues have been printed.
The division of print requests into queues of varying priorities can work well in many cases, but this approach has the drawback that low priority print requests may never be printed if a steady stream of higher priority requests enter the system. In operating-systems jargon, this situation is called starvation; some work is never done because the system spends all of its time on other processing.
To avoid the possibility of starvation, a typical approach is to periodically move a print request from a low-priority queue to the next higher priority queue, as this would cause any print request to eventually move up to the head of the highest priority queue. To specify this promotion from one queue to the next more precisely, suppose that every time k requests from queue qi have been sent to the printer, the system removes a request from queue qi+1 and enqueues the request on queue qi.
The Printing Protocol
The following diagram provides an overview of the process of user submission of print requests, their placement on an appropriate queue, and their subsequent transmission to the printer for printing:
The formal protocol follows:
At any time, a user may send a print request to the operating system.
The operating system uses an enqueue operation to place the print request on a queue, based on the number of pages to be printed
If the printer is idle, the operating system will select a print request from the highest priority non-empty queue.
If the printer is busy, the operating system simply collects print requests in its queues.
If the printer completes a print request, the operating system processes print requests as follows:
Determining Initial Print-request Priority
The print-queue protocol above requires the operating system to determine which queue should be used for each new print request submitted by the user. Three assignment approaches follow:
Problem to be Solved
Supplemental Problem 3 is to investigate the extent to which multiple queues and different assignment algorithms have an impact on the average waiting time for users' print requests.
For the purposes of this problem, suppose that printing one page requires one unit of time. The simulation described below will cover 1000 units of time, and the simulation will need a "clock" variable that keeps time units 0, 1, 2, ..., 999.
To investigate the impact of different queue-selection strategies, testing should include each of the queue-selection approaches and several loads (numbers of Print Requests entering over the simulation).
Draft problem-specific grading form
This document is available on the World Wide Web as
http://www.walker.cs.grinnell.edu/courses/207.sp13/suppl-prob.shtml
|
created 22 May 2008 last revised 23 April 2013 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |