0% found this document useful (0 votes)
276 views

CS-200, Sample Final 1 PDF

This document contains instructions for a programming final exam. It explains that students should write their name on the first page only and write their student ID number on every page. The exam contains 5 programming problems worth 20 points each. Students must write their answers on the same page as the corresponding problem. The instructions provide formatting guidelines and assumptions that can be made for the problems.

Uploaded by

John Crissman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
276 views

CS-200, Sample Final 1 PDF

This document contains instructions for a programming final exam. It explains that students should write their name on the first page only and write their student ID number on every page. The exam contains 5 programming problems worth 20 points each. Students must write their answers on the same page as the corresponding problem. The instructions provide formatting guidelines and assumptions that can be made for the problems.

Uploaded by

John Crissman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME:____________________________ STUDENT ID# __________________________

(Write your name on THIS PAGE ONLY!!!) (Write your ID# on this and every page!!!)

Programming I FINAL EXAM, Sample 1


CS-200, <SEMESTER> <YYYY>
Saturday, <DATE>, 8:30 a.m. – 10:30 a.m.
Rooms <LWH-1001, LWH-1002>

Instructions:

1. Do not turn this page until told to do so.

2. This exam is closed book and closed notes.

3. Write your STUDENT ID Number on every page. If you do not write your ID Number on a
certain page, you will not receive credit for the question on that page!

4. Do not write your name on any page (except this one). If you write your name on a certain page,
you will not receive credit for the question on that page!

5. There are 5 problems on the exam, one per page. Each problem is worth 20 points.
Once you start, verify you have all 5 problems.

6. You must give your answer to a question on the same sheet of paper that the problem appears
on. If you run out of space on the front of the page, you may continue to the back of that page
only. If you put your answer on a different page, you will not receive credit for that problem!

7. For problems that ask you to write a method, you must use the given method header exactly as
shown, and you do not need to write the main( ) method.

8. For problems that ask you to write code, you should only write the method indicated in the
problem. You can assume the following import statement and keyboard declarations:

import java.util.Scanner;

Scanner keyboard = new Scanner (System.in);


or Scanner kbd = new Scanner (System.in);
or Scanner input = new Scanner (System.in);

9. You may use "SOP" as an abbreviation for "System.out.print" and "SOPln" for
"System.out.println".

10. You do not need to do any error checking of input values, unless the problem specifically asks
you to do so!

11. If you are caught looking at other papers or communicating with other students in any way, you will
receive an F for the course.
WRITE your STUDENT ID# here: ____________________________

Problem 1 In US currency, a quarter is worth 25 cents, a nickel is worth 5 cents, and a penny is worth 1
cent. Write a Java program that prompts the user to enter an integer representing a dollar amount that
consists of all pennies. You may assume the user input value is greater than zero. The program is to
distribute that amount into quarters, nickels and pennies, using as few coins as possible. Note: you may not
use any currency values other than quarters, nickels, and pennies. Here are sample runs:

Enter an integer: 67 Enter an integer: 184

To make 67 cents, you need: To make 84 cents, you need:

2 quarters 7 quarters
3 nickels 1 nickels
2 pennies 4 pennies

public static void main(String[] args) {

}
CS-200, Sample Final 1, Page 2 of 6.
WRITE your STUDENT ID# here: ____________________________

Problem 2 Write the method public static boolean atLeastThreeMatch(int a,


int b, int c, int d) that takes four integer arguments and returns true if and only if at least
three of the four values are the same. For example, if the values passed in are 5, 3, 5, 5, it would return
true. If the values passed in are 7, 3, 7, 9, it would return false.

public static boolean atLeastThreeMatch(int a, int b, int c, int d){

CS-200, Sample Final 1, Page 3 of 6.


WRITE your STUDENT ID# here: ____________________________

Problem 3 Write the method public static void howManyEnteredBeforeSeenBoth(int


a, int b) that takes two integer arguments a and b. The method prompts the user to enter integers on
the keyboard one at a time, until a and b have both been entered. Date entry terminates once both values
have been entered. The method then prints to the console window the number of integers entered. For
example, if a were 25 and b were 17, here are two sample runs of your method:
Enter an int: 6
Enter an int: 948 Enter an int: 25
Enter an int: 49 Enter an int: 10
Enter an int: 17 Enter an int: 25
Enter an int: 0 Enter an int: 25
Enter an int: 25 Enter an int: 109
Enter an int: 25
You had to enter 5 integers Enter an int: 17
before typing both 25 and 17.
You had to enter 8 integers
before typing both 25 and 17.

public static void howManyEnteredBeforeSeenBoth(int a, int b) {

CS-200, Sample Final 1, Page 4 of 6.


WRITE your STUDENT ID# here: ____________________________

Problem 4 Write the method public static int mostFrequentValue(int [] myArray)


that takes an integer array myArray. The method returns the value in array myArray that appears the most.
For example, if myArray were the array below, the method would return the value 39, because 39 appears
five times in myArray and no other integer appears that many times. You may assume that some value in
myArray does appear more frequently than all others.

myArray 81 81 39 17 39 17 17 17 81 81 39 5 39 39

public static int mostFrequentValue(int [] myArray) {

}
CS-200, Sample Final 1, Page 5 of 6.
WRITE your STUDENT ID# here: ____________________________

Problem 5 Write the boolean method public static boolean isSubstring(String x,


String y) that takes two Strings x and y as arguments and returns true if an only if String x is a
substring of String y. String x is a substring of String y if and only if all characters in x appear
consecutively in y. For this problem, the only String methods you may use are length( ) and charAt( ). If
you use any other String methods, you will receive no credit for this problem. Examples:

If y = "BACARAT", then all of the following are substrings of y:


"CAR", "ARAT", "BACAR", "C", and "BACARAT".

However, if y = "BACARAT", then all of the following are not substrings of y:


"CART", "BAR", "CAT", "M", "BACK", and "BACARATION".

public static boolean isSubstring(String x, String y) {

CS-200, Sample Final 1, Page 6 of 6.

You might also like