| CS 261 | University of Puget Sound | Spring, 2020 |
|
Computer Science II
|
||
|
Abstract Data Types and their Implementations,
Some Basic Algorithms,
Object-oriented Problem Solving, and Efficiency |
||
Warning:
This course is under development.
Although the basic structure of this course is largely established,
nothing on this Web site should be considered official or even possibly
correct.
DO NOT MAKE PLANS BASED ON THE CONTENTS OF THIS SITE UNTIL JANUARY, 2020.
Supplemental Problems extend the range of problems considered in the course and help sharpen problem-solving skills.
Each program for a supplemental problem must follow these instructions:
Include within your code, javadoc documentation for
/***
* equals is a method
* @param first is a String
* @param last is a String
* @returns a boolean value
*/
equals (String first, String last)
/*****************************************************************
* Henry M. Walker *
* PO Box CS/Math Officein Thompson *
* Program for CSCI 261A *
* A Simple Class Hierarchy *
* Assignment for Friday, Tuesday, February 18 *
*****************************************************************/
/* ***************************************************************
* Academic honesty certification: *
* Written/online sources used: *
* [include textbook(s), *
* CSCI 261labs 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., CSCI 261 students] about the solution to this problem*
* *
* Signature: *
*****************************************************************/
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);
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 CSCI 261 lab Generalization, Polymorphism, and Exceptions. The ShoppingCart class should have these features:
Classes NameList with ListStringNode from the lab on linked lists in Java using Iteration contain a framework for maintaining a singly-linked list of names. The program has these features:
main
Method addName allows names to be added anywhere on the list.
This problem asks you to implement two additional functions within this program.
Function removeDuplicates removes duplicates from the current list:
In this processing, duplicate nodes should be removed and space deallocated, but no new nodes should be created.
Function putLast moves a node for a specified name to the end of the list.
In this processing no new node is created and no existing node is freed. Rather an existing node is moved.
Programming Hints:
NameList, you will need to add menu options and option
processing for these new operations.
Grading rubrics and forms follow.
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
|
created 22 May 2008 revised 23 April 2013 revised 31 January 2020 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |