Skip to content

raeef96/Rafael-task-4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Deadline

This work should be completed before the exercise on Friday 25th September.

Instructions

For instructions on how to do and submit the assignment, please see the assignments section of the course instructions.

Preparation

You must read and answer the questions in the OLI material:

You may wish to also read Chapter 3 from, Objects First with Java.

Github Task:

Please complete the exercises listed below:

  • 3.9--3.12
  • 3.21
  • 3.26--3.27
  • 3.30
  • 3.31

Please commit any written answers to the docs folder, and if indicated, commit any full Java code developed to the src folder of your KTH Github repo. Remember to push to KTH Github.

Exercise 3.9

Which of the following expressions return true?

! (4 < 5)
! false
(2 > 2) || ((4 == 4) && (1 < 0))
(2 > 2) || (4 == 4) && (1 < 0)
(34 != 33) && ! false

After writing your answers on paper, open the Code Pad in BlueJ and try it out. Check your answers.

Assistant's note: While you can easily get the correct answers for this exercise by simply using the code pad, trying to work out how each expression is evaluated beforehand is a good mental exercise! An alternative to BlueJ is jshell and might be more useful in the long run.

Exercise 3.10

Write an expression using boolean variables a and b that evaluates to true when a and b are either both true or both false.

Assistant's note: Note that if-statements is not expressions. Use only variables and operators such as &&, ||, !, ==, etc. when answering questions asking for expressions.

Exercise 3.11

Write an expression using boolean variables a and b that evaluates to true when only one of a and b is true, and that is false if a and b are both false or both true. (This is also called an exclusive or.)

Assistant's requirement: Any sane programmer would use the XOR operator (^) for this, and present the solution a^b. However, this is an exercise in boolean logic using AND, NOT and OR, so you are not allowed to be a sane programmer for this particular exercise!

Exercise 3.12

Consider the expression (a && b). Write an equivalent expression (one that evaluates to true at exactly the same values for a and b) without using the && operator.

Exercise 3.21

Rewrite the increment method without the modulo operator, #using an if statement. Which solution is better? For a reminder of the NumberDisplay sourcecode, see ClockDisplay project.

Exercise 3.26

Write the signature of a constructor that matches the following object creation instruction:

new Editor("readme.txt", –1)

Assistant's note: Refresh your knowledge of the method signature by having a look at the assistant's note on exercise 1.33 from week 1!

Exercise 3.27

Write Java statements that define a variable named window of type Rectangle, and then create a rectangle object and assign it to that variable. The rectangle constructor has two int parameters.

Assistant's note: Please note that you do not need to create the Rectangle class, but can assume it has already been provided to you.

Exercise 3.30

Given a variable Printer p1; which currently holds a reference to a printer object, and two methods inside the Printer class with the headers

public void print(String filename, boolean doubleSided)
public int getStatus(int delay)

write two possible calls to each of these methods.

Assistant's note: That makes four method calls in total!

Exercise 3.31 (src)

Assistant's note: When you see src in the exercise title, make sure you add the code to the src folder.

Change the clock from a 24-hour clock to a 12-hour clock. Be careful: This is not as easy as it might at first seem. In a 12-hour clock, the hours after midnight and after noon are not shown as 00:30, but as 12:30. Thus, the minute display shows values from 0 to 59, while the hour display shows values from 1 to 12!

You can copy the source code from the ClockDisplay project into your src folder as a starting point. Your solution must be in src and compile.

Grading Criteria

Each week we will communicate grading criteria through the issue tracker. Grading criteria set the basic standards for a pass, komp or fail, so it is essential you review them each week. These will change over time as your skills develop, so make sure you read the grading criteria issue carefully and tick off all the requirements.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages