CS 55  Java Programming

Week 6

Agenda

  • Chapter 6 - Methods

Examples

LotteryOdds.java
MultipleApplet.html  MultipleApplet.java

References

  1. The Java Tutorial  Implementing Methods
  2. The Java Tutorial  Passing Information into a Method - explains Pass by Value
  3. Cafe au Lait Java - Java Course Notes Methods

 

Lab06

  1. Exercise 6.14  Write a method
       int integerPower(int base, int exponent)
    that returns the value of baseexponent. There is a  Math.pow() method in the Java API that does this. Do not use it. The idea is to write your own method, not call the existing method. Write an applet that gets values for base and exponent from the user using JTextFields, and calculates the result using your integerPower() method.
    • classname: IntegerPowerApplet
  2. Exercise 6.18  Write a method
       void squareOfAsterisks(int side, Graphics g)
    that displays a solid square of asterisks with side rows and side columns. Write an applet that uses a  JOptionPane  in init() to get a value for side from the user. Then in  paint(), call your squareOfAsterisks()method to display the square. You should pass your method both the value for side and the applet's Graphics object in the argument list.
    • classname: SquareOfAsterisksApplet
 < CS 55  > Home Email Last Modified October 1, 2004