100% tevredenheidsgarantie Direct beschikbaar na je betaling Online lezen of als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

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

Beoordeling
-
Verkocht
-
Pagina's
16
Cijfer
A+
Geüpload op
15-10-2025
Geschreven in
2025/2026

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

Instelling
WLU CP213
Vak
WLU CP213

Voorbeeld van de inhoud

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.

Geschreven voor

Instelling
WLU CP213
Vak
WLU CP213

Documentinformatie

Geüpload op
15 oktober 2025
Aantal pagina's
16
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

€15,58
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Online lezen of als PDF
Geen vaste maandelijkse kosten


Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
smartzone Liberty University
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
3291
Lid sinds
6 jaar
Aantal volgers
2295
Documenten
14607
Laatst verkocht
21 uur geleden
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 beoordelingen

5
266
4
94
3
104
2
31
1
103

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen