20111031

20111031 - Office of Instructional and Research Week 9...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Office of Instructional and Research Week 9 Object-Oriented Programming Intro to Inheritance ITI 202 Office of Instructional and Research This week: Monday The second fundamental idea of OOP Introduction to Inheritance Wednesday Quiz on methods More about OOP Fundamentals (Inheritance & Polymorphism) Office of Instructional and Research Announcements Week 9 Blog Inheritance in the Real World Pick two examples from your every day life and consider the inheritance paths for those items. What common traits are shared with the superclass? What is distinct to the item? Can something else inherit from the item you are considering? Blogs should be submitted by 11:59pm, Sunday November 7rd. Office of Instructional and Research Classes A class is a user-defined data-type Our old friend String is a class. By convention (not necessity) Classes are indicated by the first letter being in Upper case, like String Office of Instructional and Research the syntax Office of Instructional and Research Review Random Number Game Write a new program that will Pick a Random Number Collect an (integer) guess Compare the guess to the random number Output if the guess is Too High!, Too Low!, Right! Allow multiple guesses until the guess is Right! Track the number of guesses for each player for each player for each player Office of Instructional and Research The Random Number Game Knowing that we need to track a number of variables for each player int playerTarget, playerGuess; playerTarget = new int [ MAXPLAYERS ]; playerGuess = new int [ MAXPLAYERS ]; boolean playerWin; playerWin = new boolean [ MAXPLAYERS ]; Office of Instructional and Research Classes in the Random Number Game Knowing that we need to track a number of variables for each player public static class Player{ private int playerNumber; private int randomNumber; private int guessedNumber; private boolean winner; } static Player players [ ] = new Player[ MAXPLAYERS ]; Office of Instructional and Research Classes in the Random Number Game But how do we access the variable? static Player players [ ] = new Player[maxPlayers]; players[n].playerNumber = lastPlayer + 1; players[n].randomNumber = getRandomNumber(1,100); players[n].guessedNumber = getGuessNumber(1,100); players[n].winner = getResult(players[n].guessedNumber, players[n].randomNumber); Office of Instructional and Research Design for a bank account program What kind of public interface to a class? Behavior of bank account (abstraction): deposit money withdraw money get balance Office of Instructional and Research Design for a bank account program Methods of BankAccount class: deposit withdraw getBalance We want to support method calls such as the following: harrysChecking.deposit(2000); harrysChecking.withdraw(500); System.out.println(harrysChecking.getBalance()); Office of Instructional and Research...
View Full Document

Page1 / 45

20111031 - Office of Instructional and Research Week 9...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online