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
ResourcesJava Concepts 6th Edition - Java - Cay HorstmannAP Java - Maria Litvin
online Java Course eImacs www.eimacs.comLink to Power Point: Class Procedures, Schedules, and Assessments For Students and Parents: Object Oriented, Java and Alice Programming Schedule and Assessments
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
- Lesson 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
- Lesson 2 - Class Procedures
Lecture - Objective-Introduce class to Web site and class procedures
- Finish up Asteroid Design
First we spend a good portion of the year learning java so that we know enough java to start making games. The more you understand in the beginning the better the games.- Power Point Link to Power Point: Class Procedures, Schedules, and Assessments
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
- Run Hello World - Introduction to Eclipse Steps to Running Eclipse and Writing Hello World
- Compile and run our first Hello World program
- Log on to eimacs http://eimacs.com/ and start working
- Lesson 3
- Lecture
- Demo how to go though eimacs content and link to list of eIMACs material we will be covered
- Cover Basic Programming Concepts
The file name must be the same name as the class name. For example, in the following case the class name is Sum10, so the corresponding filename is Sum10.java. All class names by convention begin with a capital letter.
All code in java is put in classes, and for the most part each class is in it's own file./**
* Computes the sum of the first ten positive integers,
* 1 + 2 + ... + 10. (comments)
*/
public class Sum10 // class definition public is it's scope
{
public static void main(String[] args)// every java application must have one main method
{System.out.println(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10);// every java statement ends in with a semi-colon
}//brackets are delimiters in Java
} //Note indent is very important for readingSystem.out (Object Name) . println (method name) ("Hello World") (parameters); // break down of the statement to print out Hello World to the console with a newline.
- It is assumed you have finished reading Chapter 1 and 2.
- Computer
- For reference: Chapter 1 Link to Power Point of Chapter 1
- Complete Chapter 1 of Cay Horstmann Java Programming- Programming Exercises P1.1 through p1.11
- Begin and go through eIMACs text and exercises through to Test 1 http://eimacs.com/
- Take eIMACs Test1
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
- Lesson 4
- Lecture
- Chapter 2 Link to Power Point of Chapter 2 - Using Objects
- Types of Variables in Java - link to java.sun.com tutorials
- Instance Variables (Non-Static Fields)
- Class Variables (Static Fields)
- Local Variables
- Parameters
- A type's fields, methods, and nested types are collectively called its members.
- Using Objects - How to move and translate objects.
- "Transformations are used to convert coordinates in the coordinate system used to describe the world into the coordinate system used by the display screen as seen from the eye point. The world tends to be described in units like feet or millimeters while the screen is measured in pixels." From Doing it Fast - on Game Programming by Bob Pendleton
- Computer
- Copy and run the Graphical Applications on page 56 from Java Concepts the code that displays two Rectangle in a Frame Viewer.
- Next add a color to the rectangle and add a string containing your initials. Use the following commands to add the functionality:
- g2d.setColor(Color.BLUE);
- g2d.drawString("VG", 10, 25);
- Next add an Ellipse and its Bounding Box. Follow instructions on pg 59 of the Java Concept Book
- Review Exercises R2.1 through 2.20 - This can be done with a partner, but will be handed in for a grade.
- Chapter 2 - of the Cay Horstmann Java Text Book Programming Exercise p2.3
- continue with eimacs http://eimacs.com/
- Week of 9/20
Finish up
Week of 9/27 Make sure all your work is on the H driveCreate an OO Directory move your workspace to H://OO/workspace/ - This is where I will be grabbing your work to grade.
- All chapter 1 programming exercises
- eimacs Test1
- 2 Rectangles on page 56
- Draw an Ellipse enclosed in a rectangle pg 59
- All chapter 2 Review examples - (We will review some in class)
- Do programming exercise p2.3 and p2.4
Lesson 9
Finish up from the previous week Continue on to Chapter 3 - Do all Review Questions and programming problems p3.6, p3.10, p3.11, p3.15 through p3.22. A test is coming soon to classroom 222Week of 10/5
- Progress Reports -
- Grading criteria - Link to grading percentages
- Writing Across The Curriculum on instantiating an object (quiz 5%)
- Chapter 1 programming problems (lab assignment 20%) -
- Did you do all the problems
- Are the problems in individual projects
- Did you include the two Rectangles and the Bounding Rectangle around an Eclipse
- Chapter 2 Review questions
- Lecture go over Review questions 2.9 through 2.15
- Continue working on Chapter 3 exercises
Week of 10/17
Test on Tuesday Oct 25
Term One Grades will be based on chapters 1,2, and 3 programming problems, and tests.
- Continue working on programming problems in Chapter 2 and Chapter 3
- Specifiy Public Interface
- If stuck work on eimacs.com
- Finish up All Chapter 2 and 3 problems
- Go over the test on Wed Nov 3
- if everyone can pass short quizzes on the week of Nov 8 we will take a break and start Alice
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
- Do some Alice and complete Chapter 3 programming problems Alice tutorials 135 -180
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.
- Start Chapter 4 on Conditionals
- Chapter 5 on Arrays
(Wiki Liki's was not done this year although cyber safey and importancy and to become an intelligent producer and voter is crucial!)
Technology Discussion on WikiLeaksProgram 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.
- 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?)
- 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?)
- Research Digital Rights Organization such as the Electronic_Frontier_Foundation
- What do they have to say about WikiLeaks
- 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)
- 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.
*******************************************************************************************************************************************************
Finish up because I will be grading the following:
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 ListenersImplement 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
Programming Problems on page 364 p9.21,p9.22, p9.23 and p9.303) Including p9.30 moving the car (The car will not move without implementing an ActionListener use the Rectangle example on page 419 as a model)How to use a timer to repaint the screen ** This is a new and improved articles
Assignments for Week of February 27, 2011Hierarchy of a Simple Applet
- 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 14thYou 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
- Each Class Must Start with your Name and a description of the class- (Minimum documentation)
- Proper indentation for each class
- Meaningful class and for the most part meaningful variable names (Or NO POINTS)
- Runs without compilation errors
- Ball class
- Paddle class
- Pong class - this is the Applet
30 points
- Ball moves around the screen well and bounces off all 4 walls
- At least one Paddle moves up and down with a keyListeners
- 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.
- In your OO Folder create a ReviewExercise's Folder called ReviewExercises
- 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.
- In addition, you are responsible for exercises ->Arrays 1 to 8 and Test 4. Test 4 MUST be completed by Friday May 6rd
- 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.
***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
Asteroid gameCode 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.
- Each Player will be a different Size
- Each Player will be a different Color
- Each Player will be at a different position
- and one Player will only move up and down to whatever keys you like
- This MUST be implemented with the new KeyListener Methods.
Collisions -
Link to simple Collision Code -
Ball.java and Paddle.java
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
CommentsTop of program should includeYour 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 commentedOn top of each method -A explanation of purpose of the methodexplain each of the parameters and return valuesIn addition, comment all important lines of code.
Conventions To Follow
Start class names with a Capital LetterStart variable names with a lower case letterAlways camelCase - it's easy to type and easy to readAlways indent - code that is not indented I will not be debugged or gradeAlways comment - non-commented code will not be graded
Object Oriented and Computer Programming Vocabulary List
- Encapsulation
- Polymorphism
- API Documentation
- accessor and mutator
- class
- constructor
- implicit parameter
- parameter
- methods - accessors and mutators
- new - instantiation
- object and object reference
- overloading
- primitive type
General Java Programming Vocabulary List
- Applets vs. Java Applications - Applet runs from a Browser and a Java Application runs as a standalone application
- JVM - Java Virtual Machine
- JRE - Java Runtime Environment
General Programming Vocabulary List
- Browser (Internet Explorer, firefox/Mozilla, Safari)
- Web Servers (IIS, Apache, Mongrel)
- HTML, XML
- PHP, CGI, Perl, Python, JavaScript
- ASP, .Net
- Ruby-on-the-Rails
Helpful Links
Contents we will cover in eIMACS
- up to and including test1
- Variables and Expressions
- Relational Operators
- Logical Operators
- Arrays
- Program Control
- While Loops
- For Loops
- Methods
- Main
- Comments
- Class Definitions Revisited
- Abstractions
- Abstract Classes
- Interfaces
Java Game Tutorial - DOWNLOAD THE SOURCE CODE - The code on the Web pages are NOT always correct, but the downloaded source code will work!!
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
Sun Tutorials
- Java Phenomenon Trail http://java.sun.com/docs/books/tutorial/getStarted/intro/index.html - Do the whole trail on Lesson: The Java Technology Phenomenon
- A closer look at Hello World Trail http://java.sun.com/docs/books/tutorial/getStarted/application/index.html
- What is a Class http://java.sun.com/docs/books/tutorial/java/concepts/class.html - try Lesson: A Closer Look at the "Hello World!" Application - through to the end of the trail
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/3Reciprocal of 4/5 is 5/4
Change to a fraction --> 5/2, then flip --> 2/5