OO Java Assignments
 

  Ms Gold's

Computer Science Classes at Marshfield High School

last updated January 23, 2012

Object Oriented Programming

How to Calculate a Weighted Average

 

Link to Lesson Plans

Resources
Java Concepts 6th Edition - Java - Cay Horstmann

Important Information:
Improper use of the Internet during class time will result in the loss of computer use for the day, the student will have to make up lost class time and work after school. Improper use is defined as visiting an internet site that has not been sanctioned by the school or teacher. This includes but is not limited to all types of games that are not related to class work.

In addition, adding unrelated files to the school's computer network will result in immediate loss of all internet privileges.

 

Homework Assignment

Read chapters 1,2 and 3 of your text book - Java Concepts

Section 1

Lecture

  • Name, web-site, and email address on the board
  • Objective - Start thinking how to design an Asteroid Game in an Object Oriented Way
    • On a piece of paper write down ideas for designing a Asteroid Game -
    • Brain Storm the Class structure of a basic Asteroid Game
    • Break into groups to plan out class design
    • Go over with class the design
    • Compare the class design to how it would be designed in Game Maker
  • Time Permitting - Start Class procedures
  • Class can sign on
  • Lecture - Objective-Introduce class to Web site and class procedures
    • Show Web page and links
    • Give out Textbooks - OO
    • Create an MO folder that looks like the following:
      • MO_Java
        • Java
          • Project1
        • Alice
          • Project1
        • WebSite
    • Create Shortcuts
      • Create a short-cut to Alice in C -> Documents and Settings- > your account\desktop\Alice\Alice.exe
      • Create a short-cut to Eclipse C-> Eclipse\Eclipse.exe
    • Demo how to run a program in Eclipse and how to make a workspace
    • Demo Run Hello World - Introduction to Eclipse Steps to Running Eclipse and Writing Hello World
  • Computer
Week of 9/13
  • Finish ALL of Chapter 1 Exercises - Note I changed it to all Programming Exercises p1.1 to p1.11
  • Read up through Test 1
  • Take Test 1 - I want you to keep taking Test 1 till you get 100%
Week of Nov 1st

Week of Nov 7th- By Dec 18th ALL Chapter 3 programming problems MUST be completed

If you can demonstrate to me a deep understanding of Chapter 2 and 3 you can move ahead to graphics without completing the entire problem set. Speak to me to arrange a demonstration of knowledge

Those of you who are doing Alice you are responsible for completing the Alice tutorial 135 through 180

3 minute questions you are responsible for knowing the answers to
  • What is the concatention operator and what does it do?
  • If a variable is declared within a method is it a local or an instance variable?
  • Explain the difference between the lifetime of a local and an instance variable.
Technology Discussion on WikiLeaks

Program or Be Programmed, Ten Commands for a Digital Age by Douglas Rushoff

"Digital networks were built for the purpose of sharing computing resources by people who were themselves sharing resources, technologies, and credit in order to create it. This is why digital technology is biased in favor of openness and sharing. Because we are not used to operating in a realm with these biases, however, we often exploit the openness of others or end up exploiting ourselves. By learning the difference between sharing and stealing, we can promote openness without succumbing to selfishness."

Start thinking about the implications the preceding quote has on what is happening today with WikiLeaks.

Research Questions

Wiki Leaks was not done this year, but it is important to show the imporance of becoming an producer and knowledgeable consumer of the WWW.

Save your research findings, and resources in a word document. Use a number of resources to ensure that your research is balanced and fair.

While you are researching keep a list of what you think are the bigger digital issues. We will expand on the Bigger Digital Issues next.

  1. WikiLeak General Research
    • Background of (How did it start, What was it's purpose.)
    • Current Events (What has recently happened and where do we stand today. Make a calendar of events)
    • The Future Events (Who is going to do what?)
  2. World Wide Web Research
    • Background (Who started it, What was it's purpose. Who funded the project)
    • How it is architected ? ( Can you bring down the Internet?)
  3. Research Digital Rights Organization such as the Electronic_Frontier_Foundation
    • What do they have to say about WikiLeaks
  4. Research our Governments/Securities Concerns
    • Background (How security leaks were handled before the internet)
    • Security with online material pre 9/11 to the present (What has changed)
  5. Research How Secure can online information ever be?
    • How do hackers hack?

Before Presentation

Create a WikiLeaks folder in your OO directory

Write a Writing Across the Curriculum on your thoughts on the following statements. Save it in your WikiLeaks folder and print it out when you are finished. We will follow up the WAC with our presentations.

The current WikiLeaks incident has brought to light the many unresolved issues and yet uncharted territory surrounding the big questions of digital media and digital life. Government, for-profit and non-profit organizations, and individuals have been storing, sharing, securing, and disseminating information on the internet without long-range plans for security, privacy, or even personal freedom. The process has been ad hoc leaving us with security leaks, a vibrant hacker community thriving on easy access, personal information is just a cookie away, even the stability of the internet has been questioned by recent hacker attacks.

While all of this is going on around us life continues, and we continue to play our games and buy our iPods and iPads. The digital revolution will continue to unfold with or without your participation. The challenge for students is yours for the taking. Are you ready for the challenge?
Please write to this challenge and include the types of information, knowledge, and background you think you need to be ready for the future.

Program or Be Programmed, Ten Commands for a Digital Age by Douglas Rushoff

"Digital networks were built for the purpose of sharing computing resources by people who were themselves sharing resources, technologies, and credit in order to create it. This is why digital technology is biased in favor of openness and sharing. Because we are not used to operating in a realm with these biases, however, we often exploit the openness of others or end up exploiting ourselves. By learning the difference between sharing and stealing, we can promote openness without succumbing to selfishness."

Start thinking about the implications the preceding quote has on what is happening today with WikiLeaks.

 

Groups will Give their WikiLeaks Presentations

*******************************************************************************************************************************************************

January 23, 2012

 

Soon - Test Chapter 2, 3 through Arrays and Mouse Listeners

Beginning Graphics Lesson - Read all of the first section Chapter 6.1

Key and Mouse Listeners

Implement and run the following code-http://goldclasses.com/java/Lessons/KeyListener.htm

In Horstmann book Chapter 9- read pages 347 -358 -Events, Event Sources, and Event Listeners.

on page 360 answer R9.16, R.19, R9.23, R9.24 (put the questions and answers in a file called EventListenerQuestions in your OO folder)

Programming Problems on page 364 p9.21, p9.24, and p9.23 moving the car

Read, Implement and run Link to Mouse Listener Code

Assignments for the Week of February 13, 2011

How to use a timer to repaint the screen ** This is a new and improved articles

Assignments for Week of February 27, 2011

Timers and Threads faqs

Hierarchy of a Simple Applet

About Applets

  • Move on to Game tutorial Java Game Tutorial
    • Read and implement page one on the basic structure of an applet
    • Implement the Moving the ball example- DOWNLOAD THE SOURCE CODE - The code on the Web pages are NOT always correct, but the downloaded source code will work!!
    • Move onto double buffering.
    • On your own implement a second ball that moves up and down. The new ball will start at mid-screen and move to the bottom of the screen and will bounce back and forth. This second vertically moving ball will start in mid-screen so as not to collide with the horizontally moving ball.
    • Continue with tutorial - adding Sound, and Pictures.
    • Test your program thoroughly.
    • Make a pong game
        Assignment for the Week Starting March 14th

        You can use this code as your foundation for Pong

        Assessment for Pong Game- READ CAREFULLY

        You have a choice to make Pong a Lab Assignment worth 20% or a Project worth 35% vs

        Lab Assignment Requirements

        Minimum Requirements 50 points

        1. Each Class Must Start with your Name and a description of the class- (Minimum documentation)
        2. Proper indentation for each class
        3. Meaningful class and for the most part meaningful variable names (Or NO POINTS)
        4. Runs without compilation errors
        5. Ball class
        6. Paddle class
        7. Pong class - this is the Applet

        30 points

        1. Ball moves around the screen well and bounces off all 4 walls
        2. At least one Paddle moves up and down with a keyListeners
        3. Ball bounces off the paddles

        Fulfilled Lab Assignment Requirements Move on to Asteroid Project for April 4 -if not talk to me about requirements for Pong as a project

        Use this code for collisions

        public void testAstCollision(int x, int y, int r)
        {
             /*
              * a is the bounding box for the Sprite1
              * b is the bounding box for the Sprite2
              */
              Rectangle a = new Rectangle(x_pos, y_pos, radius*2, radius*2);
              Rectangle b = new Rectangle(x, y, r*2, r*2);

              if (a.getBounds().intersects(b)){
                 x_pos = -100; // temporary solution is to move asteroid off screen
                 y_pos = -100;
                  System.out.println("GONE");
              }

    Use this code as your foundation

    Term 4 - Asteroids

    All Games are ONLINE

    Download files 5 files and compile and run them from http://goldclasses.com/java/Asteroids/

    Get familiar with the code - concentrate how the classes work together and how the laser arrays work. Feel free to change code. You can always refresh your code from the web Site and start again.

    Loops (Chapter 6) and Arrays (Chapter 7) from Horstmann Book

    You are responsible for reading Chapter 6 for Loops and completing the following Review Exercises R6.3, R6.4, R6.6, R6.8, R6.11 - Loops

    and

    For Arrays Eimacs Variables and Expressions -> Arrays 1 to 8 through Test 4

    Assignments are due by the end of the month

    April 25, 2011 work for end of month Assignments Due Date will be downloaded for grading on end of day Friday May 6th.

    1. In your OO Folder create a ReviewExercise's Folder called ReviewExercises
    2. In the OO/ReviewExerciases place a document called FirstInitialREChapter6.doc (ie ALovellREChapter6.doc)- in this document you place the questions and answers to R6.3, 6.4, 6.6, 6.8 and 6.11 from the Horstmann book. If you have done these questions in Eclipse copy and paste your work into the document for grading.
    3. In addition, you are responsible for exercises ->Arrays 1 to 8 and Test 4. Test 4 MUST be completed by Friday May 6rd
    4. Test on Loops, Arrays

    Students should take down the Asteroids Class code from Asteroids.java and the space ship sprite called ss1.png . Copy the png code into the src and bin folder of your workspace and you should see a space ship. You job is to make the space space move with keycodes.

    Link to test with Answers

    Link to Asteroid Assessment

    ***June 3***

    What to include in your MO folder -

    Create an MO folder under your OO folder so it looks like OO/MO

    Paragraph One- describe what you learned in the class. Include in this paragraph your description of Object Oriented Programming.

    Paragraph Two- describe the difference between Using Objects and Implementing Classes.

    Paragraph Three - describe the difference between a class and an instance of an object.

    (for all these paragraphs you may use examples)

    In addition, include links to your pong and asteroid game. This includes making the necessary jar files and separate html files.

    How to include your jar files

    <p align="center"><font color="#9933FF">Rachel's Asteroids Game</font></p>
    

    <p>
    <applet code = Asteroids.class archive="RHahnAsteroid.jar" width= 200 height = 200> </applet>
    </p>
    <h1 align="center"><a href="http://goldclasses.com/Block10-11/BlockA/htm/RHahn.htm" title="Rachel's Game"> </a></h1>
    < p>
    <applet code = RachelBall.class archive="RHahn.jar" width = 200 height = 200> </applet>
    </p>

    Feel Free to change width and height to what you need

    Mastery Objectives Assessment

     

Asteroid game
Game Ideas

Code for re-sizable Ellipse

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

/**
A component containing an ellipse filled with your favorite
color that touches the component boundaries.
*/
public class EllipseComponent extends JComponent
{
public void paintComponent(Graphics g)
{
// Draw a large ellipse that touches the boundaries of this component.

Graphics2D g2 = (Graphics2D) g;

double width = getWidth();
double height = getHeight();
// it's that easy.

Ellipse2D oval = new Ellipse2D.Double(0, 0, width, height );

g2.setColor(Color.RED);
g2.fill(oval);

g2.setColor(Color.BLACK);
g2.draw(oval);
}
}

Lesson 9 - Three Players One Class How one Laser Class Download the following java files and Main.java Load these files into Eclipse and create 3 Players. Create Four Players from only ONE Class that does the following.
  1. Each Player will be a different Size
  2. Each Player will be a different Color
  3. Each Player will be at a different position
  4. and one Player will only move up and down to whatever keys you like
  5. This MUST be implemented with the new KeyListener Methods.

Collisions -

Link to simple Collision Code -

Ball.java and Paddle.java

Link to Test Collision Code

Better Collision Testing Code

/*
* Ms Gold - test to see if Asteroid is hit by a beam
* x is the x position of the beam
* y is the y position of the beam
* r is the radius of the beam
*/

public void testAstCollision(int x, int y, int r)
{
     /*
      * a is the bounding box for the Asteroid
      * b is the bounding box for the beam
      */
      Rectangle a = new Rectangle(x_pos, y_pos, radius*2, radius*2);
      Rectangle b = new Rectangle(x, y, r*2, r*2);

      if (a.getBounds().intersects(b)){
         x_pos = -100; // temporary solution is to move asteroid off screen
         y_pos = -100;
          System.out.println("GONE");
      }

*************************************************************************************************************

 

Before you hand in code

Code Requirements

Comments
Top of program should include
Your name -
any parameters -
the date -
A description of what the program does -
How to deploy your program outside of Eclipse. I want this tested and don't forget about images.
All instance variables are to be commented
On top of each method -
A explanation of purpose of the method
explain each of the parameters and return values
In addition, comment all important lines of code.

Conventions To Follow

Start class names with a Capital Letter
Start variable names with a lower case letter
Always camelCase - it's easy to type and easy to read
Always indent - code that is not indented I will not be debugged or grade
Always comment - non-commented code will not be graded

 

Object Oriented and Computer Programming Vocabulary List

General Java Programming Vocabulary List

General Programming Vocabulary List

Helpful Links

Java online Course eimacs.com

Contents we will cover in eIMACS

Java Game Tutorial - DOWNLOAD THE SOURCE CODE - The code on the Web pages are NOT always correct, but the downloaded source code will work!!

Eclipse and Java Tutorials

List of Open Source Projects

List OO Vocabulary List

JavaBat- Java Practice Problems

Sun Java API's 5

Java cscie160 -For Distributed Programming

Sun the Really Big Index

Sun OO Tutorials

Sun Java Package Tutorial

How to Write Doc Comments for the Javadoc Tool

Partial list of Character ASCII translations

Link to Horstmann Chapter 1 power point

Java Coding Style Guidelines

Sun Tutorials

KeyListener http://goldclasses.com/java/Lessons/KeyListener.htm

Mouse Listener. In this exercise the a box will follow your Mouse. Follow instructions on pg 422 -425 of the Big Java Book Link to Mouse Listener Code on page 422-425

Mathematical Definition of reciprocal is a number that you multiply by so that the result equals 1. The easiest way to find it is to just flip the fraction over.

Here's an example: What is the reciprocal of 3?
3 is the same as 3/1, so we flip and the reciprocal is 1/3

Reciprocal of 4/5 is 5/4
Change to a fraction --> 5/2, then flip --> 2/5