Docsity

Midterm Exam for Computer Programming I | CS 121, Exams of Computer Science

Toggle sidebar
bg1
Ivan G. Seidenberg School of
Computer Science and Information Systems
1 Pace Plaza • New York • NY 10038 • http://csis.pace.edu
GROOVEY CODING
Dr Olly Gotel • [email protected]du
Midterm Exam
SAMPLE • 2 hours
Students should attempt ALL questions
There are 10 questions -- each is worth 10 marks for a maximum total of 100 marks
Show all pseudocode and workings - incomplete answers may still be awarded some marks
No electronic devices may be used
Students are permitted to use a crib sheet, as per specification
Crib sheets must be handed in with exam scripts
DO NOT TURN OVER - UNTIL INSTRUCTED TO DO SO
pf3
pf4
pf5

Partial preview of the text

Download Midterm Exam for Computer Programming I | CS 121 and more Exams Computer Science in PDF only on Docsity!

Ivan G. Seidenberg School of

Computer Science and Information Systems

1 Pace Plaza • New York • NY 10038 • http://csis.pace.edu

GROOVEY CODING

Dr Olly Gotel • [email protected]

Midterm Exam

SAMPLE • 2 hours

Students should attempt ALL questions

There are 10 questions -- each is worth 1 0 marks for a maximum total of 100 marks Show all pseudocode and workings - incomplete answers may still be awarded some marks

No electronic devices may be used

Students are permitted to use a crib sheet, as per specification

Crib sheets must be handed in with exam scripts

DO NOT TURN OVER - UNTIL INSTRUCTED TO DO SO

CSIS DATE

  1. Short Questions: 1 .1 Which company invented Java?
    1. 2 What is the naming convention for a source file in Java (both the name and the extension)? 1.3 What is the difference between the following two Java statements? Assume int x = 10. System.out.println(x++); System.out.println(++x); 1.4 Python is an interpreted language while Java is a compiled language. What does this difference mean? 1.5 In Java you need to declare your variables before you can use them. Explain why you need to do this in Java.
  2. What is the output of the following Java code fragments: 2.1 System.out.println(5+2*3); 2.2 System.out.println(16%3); 2.3 System.out.println(47/3); 2.4 System.out.println("olly\n\tought to get coffee"); 2.5 System.out.println("hello"+there+"world");
  3. Write a Java program which calculates the mortgage interest rate for a home purchaser. Ask the user three questions, the amount they want to borrow, the amount they have as a deposit (as a percentage of the purchase price) and whether it is a co-op apartment or not. Then print out the percentage interest payable on the mortgage using the rules as defined in the following table. (This is purely a test of your conditionals, not of your maths!) 10% or less deposit 20% or less deposit More than 20% deposit Borrow less than $300,

Borrow more than $300, Not available 5.8% 5.6% Co-op Apartment Premium Add 0.25% to base mortgage rate

CSIS DATE

to make it easier to compare them. Once all the times have been entered, print out the time difference between the first and second place in minutes and seconds. Don’t use an array for this question. Instead, just use variables to keep track of the times of the first and second fastest runner as you go along. Example output from the program: Minutes (or 0 to end): 7 Seconds: 14 Minutes (or 0 to end): 5 Seconds: 23 Minutes (or 0 to end): 4 Seconds: 1 Minutes (or 0 to end): 6 Seconds: 58 Minutes (or 0 to end): 0 Fastest wins by 1 minute(s) and 22 seconds(s)

  1. Create a two dimensional array of 12 x 12 elements. Fill it with the values from the times tables (as shown below) using a nested loop. Print out all the elements of the array in the form of a 12 x 12 table. Note, you do not need to print the fancy boxes! 1 2 3 4 5 6 7 8 9 10 11 12 2 4 6 8 10 12 14 16 18 20 22 24 3 6 9 12 15 18 21 24 27 30 33 36 4 8 12 16 20 24 28 32 36 40 44 48 5 10 15 20 25 30 35 40 45 50 55 60 6 12 18 24 30 36 42 48 54 60 66 72 7 14 21 28 35 42 49 56 63 70 77 84 8 16 24 32 40 48 56 64 72 80 88 96 9 18 27 36 45 54 63 72 81 90 99 108 10 20 30 40 50 60 70 80 90 100 110 120 11 22 33 44 55 66 77 88 99 110 121 133 12 24 36 48 60 72 84 96 108 120 132 144

CSIS DATE

  1. Write a Java program to read in 5 names. Print out the first character of each name and the number of characters in each name. The user experience should look like this: Enter 5 names please… Name: Fred Name: Mary Name: Olly Name: Jim Here is my output: F with 4 characters M with 4 characters O with 4 characters J with 3 characters
  2. Write 2 Java methods. One method will convert pounds to kilograms and the other method will convert kilograms to pounds. Each method will accept one double as a parameter and will return one double after the conversion. Show how you would use (i.e. call) these methods in a small program. Note: kilograms = pounds/2.2; so pounds = kilograms*2.2. The user experience should look like this: How many pounds: 100 100 pounds is 45.5 kilograms How many kilograms: 100 100 kilograms is 220.0 pounds ~END OF EXAM~