CS100, Spring 2000, Part 2 of Review questions for Prelim 2 Note: These questions each test a wide range of concepts. On the actual prelim, the questions will be shorter; the review questions cover a superset of the tasks that could be required of you in a prelim version of the same question. We have given you longer review questions to give you practice on as many concepts as possible. 7. Note: Prelim 2 will have a box/scope diagram question. The instructions below are (almost) exactly the instructions for the question on Prelim 2. ########################################################################## # Draw the box/scope diagram for the program point marked below. # # # # For non-reference variables ($int$, $double$, $boolean$, etc.), write # # the value in the corresponding box. For reference variables, write # # $null$ or draw an arrow from the reference variable to the object box. # # Fill in all default values for instance variables. If a variable has # # undetermined contents, draw a question mark ("?"). To update the # # contents of a variable, cross off the old contents and write the new # # contents nearby. "Cross off" means "draw a single, tidy X over the # # value or on the arrow." # # # # You MUST use only the boxes we've drawn for you # # Note: We have provided a surplus of object boxes. You must cross off # # the unused object boxes. # ########################################################################## [NOTE: this is too involved for a Prelim 2 question. Also, on prelim 2, we would give you an extra set of boxes for scratch work.] class Frippy { int x; Frippy F; } class Boingo { String a; Frippy b; } public class Problem7 { public static void main(String[] args) { Frippy F1 = new Frippy(); Frippy F2 = new Frippy(); Boingo B1 = new Boingo(); Boingo B2 = new Boingo(); B2.a = "grok"; B1.b = new Frippy(); F2.F = B1.b; B1.b.F = F1; ++B1.b.F.x; Boingo B3; F2 = null; // ****draw the box/scope diagram up to this point*** } } class Problem7 +-------------------------------------------------------------------+ | +---+ +---+ +---+ +---+ +---+ +---+ | | args | | F1 | | F2 | | B1 | | B2 | | B3 | | | | +---+ +---+ +---+ +---+ +---+ +---+ | +-------------------------------------------------------------------+ class Frippy +--------------------------------------------------------------------------+ | | | +----------+ +----------+ +----------+ +----------+ +----------+ | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | | x | | | | x | | | | x | | | | x | | | | x | | | | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | | | | | | | | | | | | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | | F | | | | F | | | | F | | | | F | | | | F | | | | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | +----------+ +----------+ +----------+ +----------+ +----------+ | | | +--------------------------------------------------------------------------+ class Boingo +--------------------------------------------------------------------------+ | | | +----------+ +----------+ +----------+ +----------+ +----------+ | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | | a | | | | a | | | | a | | | | a | | | | a | | | | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | | | | | | | | | | | | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | | b | | | | b | | | | b | | | | b | | | | b | | | | | | +----+ | | +----+ | | +----+ | | +----+ | | +----+ | | | +----------+ +----------+ +----------+ +----------+ +----------+ | | | +--------------------------------------------------------------------------+ 8. [This is too long for a Prelim 2 question.] Write a program to read in test and project scores for students and print the max course score of all the students. The input is in the following format: + the first number is the number of tests. + the second number is the number of projects. + for each student, the test scores are listed, then the project scores. + a 0 terminates the input. To compute the course score, use the following facts (NOTE: this is NOT how CS100 course scores are computed.): + all tests are out of 100 points + all tests are weighted equally + tests account for 80 points of the course score + all projects are two-digit numbers representing the correctness and style points, e.g. 35 means 3/5, i.e. "3 correctness points, 5 style points". + all projects are weighted equally + projects account for 20 points of the course score. Example: 2 5 80 70 55 44 45 46 30 90 85 00 55 44 44 35 0 This means there are 2 tests, 5 projects. The first student got 80 and 70 on exams, and 5/5, 4/4, 4/5, 4/6, and 3/0 on projects, and hence course score 76. The second student got 90 and 85 on exams, and 0/0, 5/5, 4/4, 4/4, and 3/5 on projects, and hence course score 83.6. The 0 indicates there are no more students. The output would be: "The max course score is 83.6" 9. [This is too long for a Prelim 2 question.] Consider the structure of folders (directories) in a computer file system. Each folder has a $name$. Each folder can contain 0 or more immediate sub-folders. If a folder contains any immediate sub-folders, it is called the folder *enclosing* the immediate sub-folders. The "top-most" enclosing folder is called the *desktop*. (By this definition, there can be multiple desktops.) Design and implement a class Folder for representing folders. It should have instance variables and methods for the following: + an instance variable for its name + an instance variable for its enclosing folder, if any + instance variables for access to its immediate subfolders + a method that returns the desktop + a method that prints the names of its immediate subfolders + a method to return the pathname -- the concatenation of the sequence of enclosing folders from the desktop down to the folder, e.g. if "CS100" is inside "Courses" is inside "MyDisk", which is the desktop, then the path is "MyDisk/Courses/CS100". You may define and use a constructor, but do not have to. Write a main class Question8 to create the directory structure below and print the pathname of CS100 and the names of its subfolders. MyDisk / \ / \ / \ TV Courses / | / \ / | / \ / | / \ Buffy Angel CS100 Psych 101 / | | \ / | | \ / / \ \ P1 P2 P3 P4 / \ / \ old new