CS 1401, Exam #3, MWF version

Date: Friday, April 4, 2008
Name (please type legibly, ideally in block letters): ______________________________________________________________________

On April 4, 1975, a new company called Microsoft was founded by Bill Gates and Paul Allen. At present, most computers in the world run operating systems designed by Microsoft. As computers acquire more and more memory, operating systems are able to get more and more features.

1a. Write a method named percent that, given the size m (in Megabytes) of the computer memory and the size o taken by the operating system, returns the percentage of the memory taken by the operating system.

1b. Call (invoke) your method percent in the main method to compute the percentage of memory taken by 100 Meg operating system in a 250 Meg computer. You do not need to write the entire main method, just the part that assigns values to m and o and calls your method.

1c. Trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct. You should get 100 * (100 / 250) = 40%.




































2a. Define a class Computer whose elements are different computers; each computer is characterized by its total memory (in Megabytes) and the memory taken by the operating system. Your class should contain a constructor method, accessor methods, mutator methods, and a method for computing the percentage of memory taken by the operating system.

2b. Use your class in the main method to define a new object "cheapPC" of type Computer which has 250 Megs of memory, of which 100 Megs are taken by an operating system. Compute the percentage of memory taken by the operating system; then, assume that the user upgraded his computer to 500 Megs, and compute and print the new percentage.

2c. Trace your program step-by-step.
















































3a. Write a piece of code that, given an array m of memory sizes and the array o of the corresponding operating system sizes, computes and prints percentages taken by the operating systems of different computers.

3b. To check the correctness of the code you wrote in Part 3a, write a piece of code that defines a new array m with elements 250 and 500 and a new array o with elements 100 and 100.

3c. Trace step-by-step how the piece of code you wrote in Part 3a will compute the corresponding energies. Hint: the percentages should be 40% and 20%.


















































4a. Write a method that, given an array m of memory sizes, finds the index of the computer with the largest size memory.

4b. To check the correctness of your method, write a piece of code that defines a new array memories consisting of 3 elements 250, 500, and 100.

4c. Trace step-by-step how the piece of code you wrote in Part 4a will compute the index of the computer with the largest memory size. Hint: computer No. 1 has the largest memory -- of 500 Megabyte.


















































5. Name main GUI components, and briefly explain their use.