Intro to Java Programming

Course Home
Syllabus
Announcements
Reflections


Related Links

Announcements

October 21, 2017

Today we have a new Quizlet:

Pair Programming: How to access one object from another

Today's pair programming answers the question:

How can I update the score counter whenever an asteroid is destroyed by the rocket?

Don't forget to save your work when you're done. You can compress your project folder and email it to your partner and your instructor.

Independent work period

Independent work period begins when you and your partner are finished with pair programming. During this time, you can:

  • Put on some headphones and do some Joy of Code lessons.
  • Go over the Quizlet cards from last week to get ready for another Quizlet Live
  • Make up your own Quizlet or Kahoot! cards on any of the Java material we've talked about in class.
  • Make a game of your own design.

October 14, 2017

Last week, we talked about methods like getX() that have a return type:

We use these methods when we want to get information.

Other methods that return int values include getY(), getWidth(), and getHeight(). Since these methods return int values, you can use them anywhere you can use int values. For example, you can write things like:

  • getX() ≤ 5
  • getY() ≥ getWorld().getHeight() - 5

The method call getWorld().getHeight() is a special kind of call to get information from the world object. We'll talk more about accessing the world object and other objects when we get to the tutorial called "How to access one object from another".

In today's pair programming, we're going to use a method called Greenfoot.getRandomNumber() to make a lobster move around randomly in an attempt to catch the crab. There are two important things to notice about this method:

  1. Greenfoot.getRandomNumber() is a static method. That means it belongs to a class, not an object. Static methods generally need to be called with the name of class they belong to. The Greenfoot.getRandomNumber() method belongs to the Greenfoot class.
  2. The Greenfoot.getRandomNumber() method needs an argument. The argument needs to be an integer. For example, if you make a method call Greenfoot.getRandomNumber(10) you will get a random number between 0 and 9. In other words, you will get one of these ten numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.

Like all methods that have an int return type, you can use Greenfoot.getRandomNumber() anyplace you can use an integer. For example, you can use expressions like:

  • move(Greenfoot.getRandomNumber(10))
  • turn(Greenfoot.getRandomNumber(90))
  • Greenfoot.getRandomNumber(100) < 10

The driver will need to download this starter code.

The navigator will read from this documentation page.

What do I do when I'm done?

When you finish pair programming, you can:

  • Put on some headphones and do some Joy of Code lessons.
  • Go over the Quizlet cards from last week to get ready for another Quizlet Live
  • Make up your own Quizlet or Kahoot! cards on any of the Java material we've talked about in class.
  • Make a game of your own design.

October 7, 2017

To start things off, we'll make sure everyone is set up with email you can use for saving your work and writing reflections.

Next we will review Tutorial 3 from last week's crab scenario and discuss these terms:

  • class: "cookie cutter" for creating objects
  • object: instance of a class. Many can be created from one class.
  • method: action an object can perform after it has been created.
  • act method: special method invoked once with the Act button and repeatedly by the Run button.
  • instance: another word for object
  • return value: value returned by a method with a non-void return type. For example, the return value of getX() is an integer that tells us the x-coordinate of an actor.
  • return type: Kind of information returned by a method. For example, getX() has a return type of int, since it's an integer. Methods that return true or false have a return type of boolean.
  • void return type: defines a method that doesn't return a value. methods with this return type are like commands. Methods that return values are more like questions.
  • int return type: Methods with int return types are for asking questions that can be answered with a number. For example, getRandomNumber(100) or getY().
  • boolean return type: Methods with boolean return types are for asking questions that can be answered with true or false. For example, isAtEdge().
  • method call: a request sent to an object. If the method has a void return type, the request is like giving a command. If the method has a non-void return type, the request is like asking a question.
  • argument: information passed to a method. For example, when the method call move(4) is made, the information passed is the integer 4.

Then we'll do our first Quizlet Live on classes, objects and return types based on the quizlet below.

After Quizlet Live, you'll be ready to this quiz.

When you're done with the quiz, the Joy of Code page is available to help you do some self-paced work.

Headphones will be made available so you can work through video lessons and try out sound effects without disturbing others.

Pair Programming

If we have time, we'll make random pairs and do some pair programming. We'll pick up with the version of modern crab that was created in today's demo

September 30, 2016

Welcome to Intro to Java Programming: Building & Enhancing Games! Here's what we'll do today:

  • Complete this background survey.
  • Get to know each other.
  • Discuss why we need special languages to communicate with computers.
  • Learn to program a wombat.
  • Learn about pair programming.
  • Use pair programming to start work on a crab game.
  • Writing a short reflection and sending it to tj@tjleone.com (I'll explain reflections later today).

In Between Times

If you've completed your survey, check out the Joy of Code Lessons to learn more about game-building with Java and Greenfoot. To watch the videos, you can ask for headphones or use your own headphones or earbuds if you brought them. If you've already worked with Greenfoot and would like to start on a game of your own, go for it!

At Home

Here are some things you might want to do at home:

  • Download and install Greenfoot on your home computer. Instructions for this are in JoC#2
  • Right click on the Hedgehog class in the Class Diagram. Select Set Image... How do you change the Hedgehog's image?
  • Download some sample projects ( ants, asteroids, fatcat, little-crab, marbles, piano, wave, wombats) and play around with them.

This web page was created to supplement a course offered by The Center for Talent Development. CTD This work is licensed under a Creative Commons Attribution 3.0 Unported License. Creative Commons License Terms of Use. Privacy Policy.