Unformatted text preview:

University of Maryland College Park Dept of Computer Science CMSC131 Fall 2018 Exam 1 FIRSTNAME LASTNAME PRINT IN UPPERCASE STUDENT ID e g 123456789 Instructions Please print your answers and use a pencil Do not remove the staple from the exam Removing it will interfere with the Gradescope scanning process To make sure Gradescope can recognize your exam print your name write your directory id at the bottom of each page provide answers in the rectangular areas provided and do not remove any exam pages Even if you use the provided extra pages for scratch work they must be returned with the rest of the exam This exam is a closed book closed notes exam with a duration of 50 minutes and 200 total points You don t need to use meaningful variable names however we expect good indentation Grader Use Only 1 2 3 Total Problem 1 Miscellaneous Problem 2 Military Time Problem 3 Diagram Total 20 90 90 200 GraceLoginId 1 2 3 pts Which of the following could be used to name variables in Java We are not asking if they are good style just whether or not they are permissible Circle all that apply Problem 1 Miscellaneous 1 2 pts Java compilers produce a Assembly code b Byte Code c Machine code can run on the computer CPU d None of the above space while horizon car component 3 3 pts Write the binary representation of 19 4 3 pts Write the decimal representation of the binary number 10111 5 3 pts Write the output generated by the following statements int y 10 int x y System out println y x 6 6 pts Answer the two questions below based on the following code where x and m are integer variables boolean y x 0 m 1 System out println y y System out println x x System out println m m a b 3 pts What is the output when x 0 and m 100 3 pts What is the output when x 20 and m 100 GraceLoginId 2 Problem 2 Military Time Complete the implementation of the program below The program reads hours minutes and the string am or pm and prints the military time associated with that time To compute military time you multiply the number of hours that have passed since midnight by 100 and add the number of minutes For example military time for 5 20 pm will be 17 17 hours since midnight 100 20 This will generate 1720 For this program use the following messages to read data hours minutes and am or pm To display the result use mil You can assume the user will provide correct values for hours and minutes however you need to check whether am or pm is provided If something other than am or pm is provided the program will not perform any computation Below we are providing an example of running the program Underlined text represents input provided by the user Remember your program must work for other values hours 5 minutes 20 am or pm pm mil 1720 public class Hour public static void main String args Scanner scanner new Scanner System in GraceLoginId 3 Problem 3 Diagram Complete the program below that prints a square The program will read the size an integer value of the square and a character It will then generate a square with a number of rows and columns that corresponds to size and where the character is used for the square border The provided character will be used for the rest of the diagram Use the message Enter size and Enter character to read data You can assume users will provide correct data and a size value larger than or equal to 3 Notice you must read the character as a character and not as a string Below we have provided two examples of running the program Underlined text represent input provided by the user Remember your program must work for other values Enter size 4 Enter character Enter size 5 Enter character public class Diagram public static void main String args Scanner scanner new Scanner System in GraceLoginId 4 EXTRA PAGE IN CASE YOU NEED IT SUBMIT WITH THE EXAM GraceLoginId 5 EXTRA PAGE IN CASE YOU NEED IT SUBMIT WITH THE EXAM GraceLoginId LAST PAGE 6


View Full Document

UMD CMSC 131 - Exam #1

Documents in this Course
Set #3

Set #3

7 pages

Exam #1

Exam #1

6 pages

Notes

Notes

124 pages

Notes

Notes

124 pages

Load more
Download Exam #1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exam #1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exam #1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?