HTW Berlin Fachbereich 4 Internationaler Studiengang Internationale Medieninformatik (Bachelor) Info 1: Informatik I Winter Term 2022/23 |
Laboratory 2: Book Exercise
|
Pre-lab
This week's lab work is intended to acquaint you with the use of methods and values.
Please bring these exercises printed out or written out with you to lab. Please have your name on your page.
P1. Why does the following version of refundBalance not give the same results as what we saw in class?
public int refundBalance() { balance = 0; return balance;
}
P2. What happens if you try to compile the TicketMachine class with the following version of refundBalance?
public int refundBalance()
{
return balance; balance = 0; }
P3. We have seen a few arithmetic operators in Java. Find a table with the Java operators and their priorities. Note down where you found this. What does the ternary operator in x?a:b do?
P4. What do you expect the the following expressions to evaluate to? Do not use a compiler or the codepad, only your head!
Expression | Value | Type |
---|---|---|
99 + 3 | ||
"cat" + "fish" | ||
"cat" + 9 | ||
9 + 3 + "cat" | ||
"cat" + 3 + 9 + "fish" | ||
"catfish".substring(3,4) | ||
"catfish".substring(3,8) |
Lab assignments are due the night before your next lab at 22.00. They may, of course, be turned in earlier. You hand them in by preparing the report in PDF and submitting it to Moodle.
Assignment
CodePad
Making a Book
Writeup
Submit your writeup as your post-lab to the Moodle area by 22.00 the night before your next lab.