OO Java Assignments
![]()
Ms Gold's
Computer Science Classes at Marshfield High School
last updated August 28, 2010 4:59 PM
Object Oriented Programming
ResourcesJava Concepts 6th Edition - Java - Cay HorstmannLink 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 and 2 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.8
- Begin and go through eIMACs text and exercises through to Test 1 http://eimacs.com/
- Take eIMACs Test1
- 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.
- Computer
- Copy and run the Graphical Applications on page 58 from Java Text Book 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 66 of the Big Java Book
- Review Exercises R2.1 through 2.19 - 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.11 to p2.19
- continue with eimacs http://eimacs.com/
Date to be Decided
Complete Chapter 3 Worksheet Link to Study Guide for Test
- Link to Practice Test's Study Guide
- Chapter 3 Horstmann -Implementing Classes
- Link to Review/power point of Chapter 3 - Implementing Classes
- Assignments - Complete all programming exercises at the end of the chapter that start with a G
- Chapter 4 Horstmann- Fundamental Data Types
- Link to Chapter 4 Power Point
- Complete the following assignments P 4.1, P4.2, P4.4, and 4.6
Lesson 5
- Students are to continue to do problems from Horstmann Java Book - Chapter 3 and 4 -
- The Secret Life of Data
- link to video on Variables and Objects
Lesson 6
- Finish problem sets 3 and 4 from Horstmann Java Book - Chapter 3 and 4 -
- Code must be have your name and dated and commented
- Refer to Code Requirements before you finalize your code
- link to video on Variables and Objects
- Key and Mouse Listeners (if time continue with)
- Learn how to add a Mouse Listener. In this exercise the a box will follow your Mouse. Follow instructions on pg 426 of the Big Java Book
Lesson 7
Assignment -Determine that a collision has happened when the the ball collides with each boundary of the window. Use this code as your foundation
The Tutorials are now working, but through Internet Explorer Only! Eclipse and Java Tutorials
- Key and Mouse Listeners
- Learn how to add a 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
- Continue onto 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.
- If you get stuck keep moving on with the tutorial.
- Continue with tutorial - adding Sound, and Pictures.
- Test your program thoroughly.
Eclipse and Java Tutorials (Only with Internet Explorer)- Key Listeners - 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
- Java Game Tutorial - DOWNLOAD THE SOURCE CODE - The code on the Web pages are NOT always correct, but the downloaded source code will work!!
Lesson 8
The answer to move the ball will be posted here
- Review how to fill out your daily accomplishment sheets.
- Review the move the Ball code
- Game Ideas
Code for resizable 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!!
Link to Java Reserve Words - Warning - Do Not use these words as Variable Names
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