Static Methods

The aim of this lab is give you practice with:

  1. Writing and Calling Static Methods
  2. Use all java constructs to write methods: Expressions, Statements, Control Structures (Conditionals and loops)

Exercise 1

Download Toolkit.java and complete it so each method behaves according to its documentation. Test each method individually use the interaction pane. Make sure to compile before typing the interactions (do not hit the Run button - as there is no main method implemented yet). Sample Dr Java interactions:

> Toolkit.isOdd(3)
true
> Toolkit.isOdd(2)
false

> Toolkit.sum(1,5) 15 > Toolkit.sum(100,200) 15150 > Toolkit.pow(3,2) 9 > Toolkit.pow(2,10) 1024 > Toolkit.pow(5,0) 1


Exercise 2

Add a main method to Toolkit class. Then test each method by calling the methods with some input parameters in main method. Print the outcome of what test you perform. Remember to compile and run your program this time.


Exercise 3

Add a method called testPow in Toolkit class that will print the values 2^0 to 2^10. Note: The pow method is already implemented in Exercise 1, so the idea is to reuse the method in testPow. Hint: What is the return type of this method?