100% satisfaction guarantee Immediately available after payment Read online or as PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

CP213 MIDTERM EXAM QUICK TIPS Object-Oriented Programming Wilfrid Laurier University

Rating
-
Sold
-
Pages
16
Grade
A+
Uploaded on
15-10-2025
Written in
2025/2026

CP213 MIDTERM EXAM QUICK TIPS Object-Oriented Programming Wilfrid Laurier University

Institution
WLU CP213
Course
WLU CP213

Content preview

CP213 MIDTERM EXAM QUICK TIPS Object-Oriented Programming 2025-2026 Wilfrid Laurier University

Class (blueprint) → Objects (multiple cars or one car) → Varriables (colour, brand) → methods (start, accelerate)

Quick Tips:

string.charAt() is a method in Java that returns the
character at a specific position (index) in a string

for (int i = 0; i < s.length(); i++): This
loop runs from the first character (index 0) to the last
character of the string.

Character.isLetter(currentChar) is part of
Java's Character class, and it checks whether the given
character (currentChar in this case) is a letter.

string.length(), meaning it will check every character including spaces “,” and “.” etc. in the string.
Returns the length of the string.

Character.isUpperCase() to check if a character is an uppercase letter.

string.toLowerCase() / string.toUpperCase(): Converts the string to lowercase or
uppercase.

\n is an escape sequence used to insert a newline character, which moves the output cursor to the
next line.

\" allows you to include a double quote inside a string literal. Example:
System.out.println("This is \"fun\"!");
Prints This is "fun"!

array.length: Returns the length of the array.
int[] arr = {1, 2, 3, 4};
int len = arr.length; // len will be 4




Common format specifiers:
printf function
System.out.printf(format_string, arguments);

● %d: For printing integers. Adds leading zeros
○ int number = 19;

, ○ System.out.printf("%05d%n", number);
● 00019
● %f: For printing floating-point/decimal numbers.
○ "%6.2f" → This indicates that the output will take 6 characters no more and have
2 decimal places. And in this case it will add spaces and count those as
characters at the beginning of the code.
○ %.2f: Limits to 2 decimal places.
● %s: For printing strings.
○ double number = 19.987;
○ String word = "hi";
○ System.out.printf("%8.2f %s", number, word);
● 19.99 hi
● %c: For printing characters.
● %n: For printing a new line (same as \n but platform-independent)
● %g format specifier in Java is used with the printf method to format floating-point
numbers (like float and double) in a more compact form.


- java.text.NumberFormat is a class in Java used to format and parse numbers, including currency,
percentages, and general numbers.

Common methods:

● getInstance(): Returns a general number formatter for the default locale.
● getCurrencyInstance(): Returns
a currency formatter for the default
locale.
● getPercentInstance(): Returns
a percentage formatter for the default
locale.
● format(): Formats the number into
a string.
● parse(): Parses a string to retrieve
the numerical value.




- Libraries in Java are called packages

DecimalFormat Class
- that allows you to format decimal numbers (like float or double) into strings in a
customizable way.
- Always apply the following to the class; import java.text.DecimalFormat;

, Common Patterns:

● 0: Displays a digit or zero if no digit is present.
● #: Displays a digit but doesn't add zero if no digit is present.
● .: Decimal point.
● ,: Grouping separator (e.g., thousands separator).

Example Patterns:

● "###,###.##": Formats the number with commas and up to 2 decimal places.
● "000.00": Ensures exactly 3 digits before the decimal and 2 after.
○ DecimalFormat moneyFormat = new DecimalFormat("$###,###.##");
System.out.println("Formatted price: " + moneyFormat.format(price));
○ Outcome: Formatted price: $1,234.50

DecimalFormat(“0.00%”) → Prints to 2 decimal places so if the given number is 0.907
the outcome will be 90.70%



Curly Braces {}
Purpose: Curly braces are used to define blocks of code.

Parentheses ()
Purpose: Parentheses are used to pass arguments, group expressions, or control flow statements.

String str = null; // str does not reference any String object
Example: String temp=null; (temp string does not contain anything, empty)

Asking a user for input
- import java.util.Scanner; allows the
program to read user input.
- Scanner scanner = new
Scanner(System.in); creates a scanner to read
from the console. In Java, one of the common
ways to initialize a Scanner is by passing an
InputStream object, like System.in, to the
Scanner constructor.
- String name = scanner.nextLine(); reads
the entire line of text (the user's name) into the
name variable.

Written for

Institution
WLU CP213
Course
WLU CP213

Document information

Uploaded on
October 15, 2025
Number of pages
16
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
smartzone Liberty University
View profile
Follow You need to be logged in order to follow users or courses
Sold
3291
Member since
6 year
Number of followers
2295
Documents
14607
Last sold
17 hours ago
AMAIZING EDUCATION WORLD

GET ALL KIND OF EXAMS ON THIS PAGE ,COMPLETE TEST BANKS,SUMMARIES,STUDY GUIDES,PROJECT PAPERS,ASSIGNMENTS,CASE STUDIES, YOU CAN ALSO COMMUNICATE WITH THE SELLER FOR ANY PRE-ORDER,ORDER AND ETC.

3.7

598 reviews

5
266
4
94
3
104
2
31
1
103

Trending documents

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions