New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Exam 1

by: Jessica Hutchinson

Exam 1 COSC 236

Jessica Hutchinson
GPA 3.5

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

This includes COSC 236's study topics and mock exam!
Introduction to COSC 1
Robert G. Eyer
Study Guide
COSC 236, Computer Science
50 ?




Popular in Introduction to COSC 1

Popular in ComputerScienence

This 7 page Study Guide was uploaded by Jessica Hutchinson on Monday March 7, 2016. The Study Guide belongs to COSC 236 at Towson University taught by Robert G. Eyer in Spring 2016. Since its upload, it has received 553 views. For similar materials see Introduction to COSC 1 in ComputerScienence at Towson University.

Similar to COSC 236 at Towson


Reviews for Exam 1


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 03/07/16
Study Topics 1. Output with System.out.print() and System.out.println() a. An expression that evaluates to a number will be output as a number b. An expression that evaluates to a Boolean will be output as a Boolean (true, false) c. An expression that contains String concatenation will evaluate to a string d. If mathematical types are mixed, the expression will evaluate to the type with the greater precision (int + double = double) 2. Escape sequences are inserted in strings for special character prints, like tabs, backslash, and newline 3. Integer division is in whole numbers only and never returns any fractional part when evaluated 4. Modulus operations (a % b), return only the REMAINDER of a/b 5. JAVA identifiers (class names, method names, and variable names) a. Syntax requirements: i. must contain only letters, numbers, underscore and dollar sign characters ii. may not start with a number b. Conventions: i. the first letter of Class names must be capitalized ii. the first letter of method names and variables must be a lower case letter iii. for identifiers created by joining multiple words, every word after the first must have its first letter capitalized iv. constants (variables declared with the keyword “final” must be in ALL UPPERCASE LETTERS 6. Static Methods in JAVA a. any number and types of parameters can be passed from a calling function. i. These are local variables in the method, but values are copied from caller b. can return any type of value if declared in the Method Header c. any method can call any other method of a class 7. JAVA programs process data using three basic methods a. SEQUENCE – statements are executed in the order written b. REPETITION – loop structures allow a sequence of JAVA statements to be executed a fixed number of times, or as long as some loop condition remains true c. SELECTION – selection structures like if/else allow a program to select alternate paths of execution based on the value of some Boolean expression 8. Repetition Structures: a. For-loops are intended to implement Definite Loops i. uses an initialization section (executed exactly once) ii. uses a loop-condition such that the loop executes so long as the condition evaluates to “true” (evaluates at the beginning of every loop) iii. uses an increment section that can increment local variables (executes at the end of every loop cycle) b. while-loops are intended to implement Indefinite Loops i. uses only a test section that test some Boolean condition at the beginning of every loop and process the loop-code, only if the condition expression evaluates to “true” ii. The code in the loop body may never execute if the loop condition is initially “false: iii. Input values that are used to terminate loops are called SENTINEL Values c. do-while loops are essentially the same as while-loops except that the loop condition is tested at the end of the code block. This means that the body of the loop ALWAYS executes at least once. 9. Selection structures: a. If structures are intended to allow a programmer to determine whether some code block is executed based on some Boolean test condition. If the condition expression evaluates to “true” the code block following is executed b. If/else structures provide either-or code blocks. If the Boolean condition of the if statement is true, the if-block is executed, otherwise the else-block is executed c. Multiple paths can be defined using if/if else/…/else. In these structures, exactly one code block will execute and the rest will be ignored. 10.JAVA math operators a. ( ), [ ], { (Grouping operators, highest precedence, evaluate contents, left to right) b. !, ++, -- (Unary operators for negation, increment, and decrement) c. *, /, % (multiplicative operators, next highest precedence, evaluate left to right) d. +, - (additive OR concatenation when a string is one of the arguments, lowest precedence, evaluate left to right 11.Boolean expressions use Relational operators (lower precedence than math, but greater than logical operators) a. > >= < <= (less than or equal to) b. == != (equality operators, lowest precedence of relational operators) 12.Boolean expressions can be joined with Logical Operators a. && - (an expression of the form <Boolean exp1> && <Boolean exp2> is true, only if both exp1 and exp2 are true b. || - (an expression of the form <Boolean exp1> || <Boolean exp2> is true, if either exp1 OR exp2 are true (Lower precedence than &&) c. ! - (represents the negation of any Boolean expression such that ! exp1 it true, if exp1 is false and !exp1 is false if exp1 is true d. Short-circuit evaluation – the compiler evaluates logically joined Boolean expressions from left to right. If the left element is false in a compound statement joined with && the whole expression is evaluated to false WITHOUT evaluating the right side. Likewise, if the left side is true in a compound statement joined with || the expression evaluates to true without evaluation of the right hand element 13.Assignment operator = += -= *= /= %= &&= ||= (lowest precedence of all operators BECAUSE the right side of any expression needs to be fully evaluated BEFORE its value can be stored in the variable on the left side 14.Built-in Math Class methods a. Math.min(a, b) returns minimum of a and b b. Math.max(a, b) returns maximum of a and b c. Math.sqrt(a) returns square root of a d. Math.pow(a, b) returns a raised to the b power 15.Built-in String methods a. For any defined string, using the dot operator, you can access methods like length(), charAt(), toLowerCase() etc. b. For String s, a to get the length use the call s.length() c. For a string literal like “Hello World” a call like “Hello World”.length() will return the integer 11 16.Input with the Scanner class a. A Scanner variable allows a program to receive input from the keyboard with methods of the Scanner class like: i. next() // next string ii. nextInt() // next integer iii. nextLine() // next whole line as a string iv. hasNextInt() // returns true if there is an integer waiting in the keyboard buffer b. Scanner variables need to be declared and INSTANTIATED with: Scanner scannerName = new Scanner(); Then methods calls look like: scannerName.nextInt(); Mock Exam: Chapters 1 – 5 1. Find the Errors: The following code contains many errors. The errors may be syntax, logic, or violations of conventions discussed in class. Copy this code into DrJava and make any necessary corrections to the code so that it compiles and produces the required output when run. Also, make sure that all naming conventions are followed. // Calculates the area & circumference of a circle & return the area value Public class CircleStats {          public static void main(String[] args) {            Scanner console = new Scanner();           int area = stats(console);     }        // This method prints the      public static String Stats(Scanner console) {           system.out.print("Enter the diameter of a circle: )           int diameter = console.nextDouble;           double radius = diameter/2;           System.out.println("For a circle with Radius ="  + Radius);           System.out.println("  The circumference is: " + PI * diameter);           System.out.println("  and the area is: " + PI * radius ^ 2;      }; } 2. Programming Write a static method named longestName that reads names typed by the user and prints the longest name (the name that contains the most characters) in the format shown below. Your method should accept a console Scanner and an integer n as parameters and should then prompt for n names. The longest name should be printed with its first letter capitalized and all subsequent letters in lowercase, regardless of the capitalization the user used when typing in the name. If there is a tie for longest between two or more names, use the tied name that was typed earliest.  Also print a message saying that there was a tie, as in the right log below.  It's possible that some shorter names will tie in length, such as DANE and Erik in the left log below;  but don't print a message unless the tie is between the longest names. You may assume that n is at least 1, that each name is at least 1 character long, and that the user will type single-word names consisting of only letters. The following table shows two sample calls and their output. Call Scanner console = new Scanner(; Scanner console = new Scanner(; longestName(console, 5); longestName(console, 7); Outpu name #1? roy name #1? TrEnt t name #2? DANE name #2? rita name #3? Erik name #3? JORDAN name #4? sTeFaNiE name #4? craig name #5? LaurA name #5? leslie Stefanie's name is longest name #6? YUKI name #7? TaNnEr Jordan's name is longest (There was a tie!) 3. Programming Write a complete program that plays a coin flipping game, displays the individual flips, reports when a game is “LOST” or “WON” and shows the number of flips needed to complete the game. The algorithm is as follows:  Simulate the flip of a coin using a JAVA random number generator.  Flip the coin once to initialize the flip value and print out the flip  Inside of a loop, repeatedly flip the coin until 3 consecutive flips have the same value (3 heads or 3 tails) a. Display the flip results after each flip  When the game ends, report the total number of flips Note: you can use 0 for heads and 1 for tails, but if you have time, add another method that will convert the integers 0 and 1 to the characters ‘H’ and ‘T’ 4. Programming Write a static method named evenNumbers that accepts a Scanner from the console. The method should repeatedly prompt the user to enter integers until 3 consecutive even integers are entered. When 3 consecutive even numbers are seen, the method should output a message including the total number of entries. You may assume that the user will enter a single integer after each prompt. Here is a sample dialog of user interaction with the program.     Looking for three even numbers in a row.        Type a number: 44    Type a number: 15    Type a number: 23    Type a number: 2    Type a number: 12    Type a number: 34    Three even numbers found after 6 total entries 5. Programming Write a static method named largerDigits that accepts two integer parameters a and b and returns a new integer c where each digit of c gets its value from the larger of a's and b's digit in the same place. That is, the ones digit of c is the larger of the ones digit of a and the ones digit of b, and the tens digit of c is the larger of the tens digit of a and the tens digit of b, and so on. You may assume that a and b are positive integers (greater than 0). For example, suppose a is 603452384 and b is 921782.  Their digits would be combined as follows to produce c: a        603452380 b           920784 ­­­­­­­­­­­­­­­­­­ c           952784      (return value) Notice that if a particular digit place is absent from one number or the other, such as the 603 at the start of a above, no digit is carried over to c.  The following table lists some more calls to your method and their expected return values: Call Value Returned largerDigits(172, 312) 372 largerDigits(21, 3) 3 largerDigits(90, 38906735) 95 largerDigits(56002, 123321) 56322 largerDigits(11223, 4466) 4466 largerDigits(12345, 12345) 12345 largerDigits(1, 34892) 2 Hint: If you are building a result number, you may need to use Math.pow or accumulate a multiplier with each digit. You may not use a String to solve this problem.


Buy Material

Are you sure you want to buy this material for

50 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.