Presentation is loading. Please wait.

Presentation is loading. Please wait.

The last lesson of this term!

Similar presentations


Presentation on theme: "The last lesson of this term!"— Presentation transcript:

1

2 The last lesson of this term!
PC01 Term 2 Consolidation The last lesson of this term!

3 Today we are going to consolidate everything we’ve learnt so far
Introduction Today we are going to consolidate everything we’ve learnt so far Feel free to pick any topic you want All work should be done in the same solution

4 Index Loops Static methods Classes Fixing Errors Click me Click me

5 The smallest perfect number is 6, which is equal to 3+2+1
Loops A perfect number is a positive integer that is equal to the sum of its proper divisors The smallest perfect number is 6, which is equal to 3+2+1 The next perfect number is 28: 28= Let’s find first four perfect numbers!

6 Declare two variables: number and numbersFound
Loops Declare two variables: number and numbersFound Create a while loop that keeps going while numbersFound is less than 4 Inside the loop, declare a variable and call it sum Then, make a for loop that goes from 1 up to number/2 (inclusive!) and uses i as a counter

7 This for loop should check the remainder of dividing number by i
If the result is zero, then add i to the sum Once the for loop is finished, compare number and sum If they’re the same, increase numbersFound by one and print number to the console Regardless of the result, add one two number

8 Create a function that finds the sum of all digits of a number
Static Methods Create a function that finds the sum of all digits of a number Call it “digitSum” It should accept one argument – a number And return a number as well

9 Declare a variable called answer Add a while loop
Static Methods Declare a variable called answer Add a while loop It should carry on while the number is not zero Inside, find the last digit of the number using the modulus operator And add it do answer Then, divide number by 10

10 Go to main and test your function
Static Methods Go to main and test your function Make sure the number it returns is correct

11 Create a class called Superhero
Classes Create a class called Superhero Each superhero should have a name, a superpower, an attribute for checking whether or not they are a villain and an integer attribute for awesomeness Create a constructor which accepts four parameters It should print “A new superhero is created!” to the console Then, it should assign parameters to the Superhero’s attributes (nameParam to name, isVillanParam to isVillain, etc)

12 Go to main() and create two superheroes
Classes Add a method called print() for printing all information about the superhero It should display all of their attributes Go to main() and create two superheroes Both should have random awesomeness One should be a villain Use whatever name and superpower you want

13 Call print() on both superheroes Then, compare their awesomeness
Classes Call print() on both superheroes Then, compare their awesomeness Work out which superhero is more awesome and print a message like this to the console: “Ballistic Bat is more awesome than superBen”

14 Everyone’s favourite section – debugging!
Fixing errors Everyone’s favourite section – debugging! Click here: … or type this link: goo.gl/QFGzVD You will need to unzip the folder (right click -> Extract all…) and double click on FixMe.sln Download the program

15 Enjoy your summer break!
That’s it for this term! Enjoy your summer break!


Download ppt "The last lesson of this term!"

Similar presentations


Ads by Google