OK. This is going to be my first lesson. Please notice that i want everyone to download bluej from bluej.org. This is recommended. Please test it out and practice the codes listed below. Learn everything about bluej to make your life and my life easier. I have added gpdraw.jar. Please add this file to your bluej library in perferneces. The codes below might not work so please add them. Some of my pictures didn't load so please download the document file below.
all copyright belong to their rightful owner
UPLOAD GPDRAW.JAR AND A BETTER VERSION OF MY LESSON HERE IS THE files
gpdraw.jar
http://www.mediafire.com/?2zkezwwyzyj
Lesson A1
http://www.mediafire.com/?2wyj2nh2mwm
_________________________________________________________________
A1 – Introduction to Object-Oriented Programming (OOP)
1. Object-oriented programming (OOP) attempts to make programs more closely model the way people think about and deal with the world. In OOP, a program consists of a collection of interacting objects. To write such a program you need to describe different types of objects: what they know, how they are created, and how they interact with other objects. Each object in a program represents an item that has a job to do.
2. The world in which we live is filled with objects. For example, an object we are all familiar with is a drawing tool such as a pencil or pen. A drawing tool is an object, which can be described in terms of its attributes and behaviors. Attributes are aspects of an object that describe it, while behaviors are things that the object can do. The attributes of a pencil are its drawing color, width of the line it draws, its location on the drawing surface, etc. Anything that describes an object is called an attribute. Its behaviors consist of drawing a circle, drawing a line in a forward or backward direction, changing its drawing direction, etc. Anything that an object does is called a behavior. Another aspect of an object has to do with creation, which determines the initial state of an object.
3. In order to use an object within a program, we need to provide a definition for the object. This definition is called a class. The class describes how the object behaves, what kind of information it contains, and how to create objects of that type. A class can be thought of as a mold, template, or blueprint that the computer uses to create objects.
4. When building a house, a construction crew uses a blueprint to define the aspects of the house. The blueprint gives the specifications on how many bedrooms there are, how to position the electrical wiring, the size of the garage, etc. However, even two houses built from the same blueprint may have different paint colors and will have different physical locations. Clients who are buying a house may make slight modifications to these blueprints. For example, they may want a bigger garage or a smaller porch. We can see the houses built from the blueprint as objects since they are all similar in structure, but each house has its own unique attributes. In the world of programming, we can view the blueprint just like a class, i.e. a tool for creating our objects.
B. Methods
1. While a program is running, we create objects from class definitions to accomplish tasks. A task can range from drawing in a paint program, to adding numbers, to depositing money in a bank account. To instruct an object to perform a task, we send a message to it.
2. In Java, we refer to these messages as methods.
3. An object can only receive a message that it understands, which means that the message must be defined within its class.
4. Suppose we take the DrawingTool class (provided by this curriculum in the package gpdraw.jar) and create an object myPencil. In OOP terminology, we say the object myPencil is an instance of the DrawingTool class. An object can only be an instance of one class. We can visually represent an object with an object diagram, as shown in Figure 1.1.
5. These are some of the behaviors that the DrawingTool class provides:
• forward
• turnLeft
• getColor
6. To draw a line of a specified length, we call the method forward along with passing the distance to move the pencil. A value we pass to an object’s method is called an argument. A diagram of calling a method is shown below in Figure 1.2.
7. If we need to change the direction myPencil is facing, we can call the turnLeft method. This will bring a ninety-degree turn to the left. Two left turns can give us a complete reversal of direction, and three left turns essentially gives us a right turn. Notice that we do not need to send any arguments with the turnLeft method. A left turn is simply a left turn and does not need any additional information from the user. A diagram calling turnLeft is shown below in Figure 1.3.
8. The diagrams shown in Figures 1.2 and 1.3 illustrate situations in which an object carries out a request by the user but does not respond to the sender. Figure 1.2 requires arguments from the user because the user must specify how far to move, whereas Figure 1.3 operates without any specific details. However, in many situations we need an object to respond by returning a value to the sender. For example, suppose we want to know the current color that is being used for drawing. We can use the getColor method to return the value. The getColor method is illustrated returning a value to the sender in Figure 1.4 below.
C. Objects in Software
1. A program is a collection of instructions that performs a particular task on a computer. Software is a collection of one or more programs. Code refers to the actual symbols that a programmer types in that tell the computer what instructions to execute. Individuals who write programs are called programmers, software-engineers, software-architects, and coders among many other terms.
2. OOP is a strategy often employed by software developers. A programmer using an OOP strategy begins by selecting objects that can collectively solve the given problem.
3. To develop a particular program in an OOP fashion, the software developer might begin with a set of program requirements. For example:
Write a program to draw a square on a piece of paper with a pencil.
4. A way to determine the objects needed in a program is to search for the nouns of the problem. This technique suggests that the above program should have three objects: a pencil, a piece of paper, and a square.
5. Ideally, a programmer reuses an existing class to create objects, as opposed to writing code for a new class. For the purposes of our drawing example, we will use the preexisting DrawingTool and SketchPad classes for the pencil and paper objects. However, we don’t have a class for a square that is pre-made, so we must make our own.
6. Programming languages can be compared to a foreign language – the first exposure to a written example is bound to seem pretty mysterious. You don't have to understand the details of the program shown below. They will be covered in more detail in the next lesson.
import gpdraw.*;
public class DrawSquare{
private DrawingTool myPencil;
private SketchPad myPaper;
public DrawSquare(){
myPaper = new SketchPad(300, 300);
myPencil = new DrawingTool(myPaper);
}
public void draw(){
myPencil.forward(100);
myPencil.turnLeft();
myPencil.forward(100);
myPencil.turnLeft();
myPencil.forward(100);
myPencil.turnLeft();
myPencil.forward(100);
}
}
7. In OOP, we concern ourselves mostly with the objects themselves and how they relate to the other objects in the program. However, there must be a starting point for the program to begin creating objects, as the objects would obviously not be able to do anything if they did not exist. Code Sample 1.1 has no starting point and would therefore not be able to do anything by itself. Later on, we will learn how to utilize this code in an actual program.
8. The state of an object depends on its components. The DrawSquare object includes one DrawingTool object declared in the line that begins with the word DrawingTool and a SketchPad object declared in the line that begins with SketchPad. The DrawingTool object is given the name myPencil and the SketchPad object is given the name myPaper.
9. A constructor is a method with the same name as the class. The first instruction will construct a new SketchPad object named myPaper with dimensions of 300 x 300 (read as 300 by 300). The next instruction will cause a new DrawingTool object named myPencil to be constructed using the SketchPad object named myPaper.
10. An object’s behavior is determined by instructions within its methods. When the method draw() for a DrawSquare() object is called, the instructions within the draw method will execute in the order they appear. There are seven instructions in the draw method. The first instruction will cause the myPencil to move forward 100 units drawing a line as it goes. The next line tells myPencil to turn left. The remaining 5 steps repeat the process of steps to draw the remaining three sides of the square.
11. The DrawSquare example illustrates the tools that a programmer uses to write a program. A program is built from objects and classes that a programmer writes or reuses. Classes are built from instructions, and these instructions are used in such a way that they manipulate objects to perform the desired tasks.
D. Compiling and Running a Program
1. A programmer writes the text of a program using a software program called an editor. The text of a program in a particular programming language is referred to as source code, or you can simply use source or code individually. The source code is stored in a file called the source file. For example in the DrawSquare example given above, source code would be created and saved in a file named DrawSquare.java.
2. Compiling is the process of converting a program written in a high-level language into the bytecode language the Java interpreter understands. A Java compiler will generate a bytecode file from a source file if there are no errors in the source file. In the case of DrawSquare, the source statements in the DrawSquare.java source file would be compiled to generate the bytecode file DrawSquare.class. Classes inside a package, such as the gpdraw.jar, have already been compiled into bytecode for you.
3. Errors detected by the compiler are called compilation errors. Compilation errors are actually the easiest type of errors to correct. Most compilation errors are due to the violation of syntax rules. These are the basic rules of languages that programmers must follow so that the interpreter understands what to do. It is similar to grammar in a spoken language and varies from language to language.
4. The Java interpreter will process the bytecode file and execute the instructions in it.
5. If an error occurs while running the program, the interpreter will catch it and stop its execution. Errors detected by the interpreter are called run-time errors. Run-time errors are usually caused by a fault in the logic of the program, such as accidentally causing the computer to try and divide a number by zero.
SUMMARY/ REVIEW: One can think of an OOP application as a simulated world of active objects. Each object has a set of methods that can process messages of certain types, send messages to other objects, and create new objects. Programmers can either define new classes for use in their program, or they can use pre-existing classes to create the objects for their application.
HANDOUTS AND
ASSIGNMENTS: Handout A1.1, DrawingTool Class Specifications
Lab Assignment A1.1, DrawHouse
Worksheet A1.1, Object-Oriented Programming
WORKSHEET A1.1
OBJECT-ORIENTED PROGRAMMING
The following object declarations and initializations will be used for all questions. This code will create a DrawingTool object called marker and a SketchPad object called poster. The poster will have dimensions of 600 x 600, and the marker will be constructed and used on the poster. Each drawing will begin at the center of the poster at the point (0,0).
DrawingTool marker;
SketchPad poster;
poster = new SketchPad(600,600);
marker = new DrawingTool(poster);
1. Draw the figure generated by the following code segment:
marker.forward(120);
marker.turnRight(45);
marker.forward(80);
marker.turnLeft(90);
marker.forward(80);
marker.turnLeft(90);
marker.forward(80);
marker.turnLeft(90);
marker.forward(80);
2. Draw lines A and B as described by the following – note the move() method is introduced here for line B. It allows you to draw lines with fewer commands:
marker.up();
marker.turnRight(90);
marker.forward(100);
marker.down();
marker.drawString(" A");
marker.move(-100,0);
marker.up();
marker.move(-175,100);
marker.down();
marker.move(175,100);
marker.drawString(" B");
3. Write code that will draw the following figure. The lower left corner is at the point (0,0), and the length of each side of the square is 200 units. The upper left part of the mouth begins at (40,60), and the upper part of the nose begins at (100,100). The eyes each have a radius of 10 units and are centered at (60,150) and (140,150). The other key points are left for you to decide. Have fun! (Write the code on the back of this sheet)
LAB ASSIGNMENT A1.1
DrawHouse
Background:
You will be provided with a file named gpdraw.jar, which contains the code needed to implement the graphics tools to draw objects. The specifications of the drawing tools are provided in Handout A1.1 – DrawingTool. Simply place the gpdraw.jar file in the appropriate folder location so the Java compiler can find it. Then add this line of code at the top of your program and the drawing tools are available for use.
import gpdraw.*;
Assignment:
Write a program that creates a drawing area of appropriate size (try 500 x 500) and draws a house similar to the one shown below and with these specifications:
1. The house should fill up most of the drawing area, i.e. draw it big.
2. The house should be centered horizontally on the screen.
3. The house must have a sloped roof. It can be of any slope or configuration. But you cannot have a flat roof on the house.
4. Adding a door (centered) and windows is optional.
Instructions:
1. Include your name as a documentation statement and also a brief description of the program.
2. You will need to turn in (either on paper or electronically) a copy of your code and a picture of the house that resulted.
HANDOUT A1.1
DrawingTool Class Specifications
These classes are not part of Java but are available through the library named gpdraw. You must have the file gpdraw.jar in the appropriate directory where Java can access it. To have these classes available in your program, use this command:
import gpdraw.*;
Other features of gpdraw will be covered in later lessons.
DrawingTool
protected double xPos
protected double yPos
protected double direction;
protected int width;
protected boolean isDown;
protected Color color;
...
<<constructors>>
DrawingTool()
DrawingTool(SketchPad)
...
<<accessors>>
public Color getColor()
public double getDirection()
public int getWidth()
public String toString()
...
<<modifiers>>
public void down()
public void drawString(String)
public void drawCircle(double)
public void forward(double)
public void home()
public void move(double, double)
public void setColor(Color)
public void setDirection(double)
public void setWidth(int)
public void turn (double)
public void turnLeft(double)
public void turnRight(double)
public void up()
...
Invariant
A DrawingTool object
• Appears in a SketchPad Window (this window is 250 pixels wide and 250 pixels high initially, but can be constructed with different dimensions.)
• The origin (0, 0) is at the center of the drawing window.
• Is directed either up, down, left, or right.
• Is either in drawing mode or in moving mode.
Constructor Methods
public DrawingTool()
postcondition
• A new DrawingTool is created and placed in the center (0, 0) of a SketchPad window that is 250 pixels wide and 250 pixels high.
• This object is set to drawing mode.
• The direction for this object is up (90º).
• The DrawingTool color is set to blue.
• The DrawingTool width is 1.
public DrawingTool(SketchPad win)
postcondition
• A new DrawingTool is created and placed in the center (0, 0) of the SketchPad window win.
• This object is set to drawing mode.
• The direction for this object is up (90º).
• The DrawingTool color is set to blue.
• The DrawingTool width is 1.
Accessor Methods
public String toString();
postcondition
result = color
public Color getColor();
postcondition
result = color
public double getDirection();
postcondition
result = direction
public int getWidth();
postcondition
result = width
Modifier Methods
public void down();
postcondition
• This object is set to drawing mode.
public drawString(String text);
postcondition
• The string text is drawn at the current location using the current color.
public drawCircle (double r);
postcondition
• If the object is in drawing mode, a circle of radius r is drawn around the current location using the current width and color.
public forward(double distance);
postcondition
• This DrawingTool object is moved in the current direction by distance pixels from the old (previous) location.
• If this object is in drawing mode, a line segment is drawn across the distance path just traversed.
• A 0.5 second delay occurs following this method’s execution.
public home();
postcondition
• The location of the DrawingTool object is set to the center of the SketchPad window.
• The drawing direction of the object is up.
public move(double x, double y);
postcondition
• This DrawingTool object is moved from the current position to the position specified by the coordinates x and y.
• If this object is in drawing mode, a line segment is drawn from the old (previous) position to the absolute position specified by x and y.
public setColor(Color c);
precondition
• c is a valid Color
• requires the following at the beginning of your program to set the color to red
import java.awt.Color;
.
.
setColor(Color.red);
postcondition
• The color of the DrawingTool object is set to c.
public setDirection(double d);
postcondition
• Sets the direction to d degrees. The orientation is d degrees counterclockwise from the positive x-axis
public setWidth(int w);
precondition
• w is >= 1
postcondition
• The width of the DrawingTool object is set to w pixels.
public turn(double d);
postcondition
• Changes the current direction counterclockwise by d degrees from the current direction.
public turnLeft(double degrees);
postcondition
• Changes the current direction counterclockwise by d degrees from the current direction.
public turnRight(double degrees);
postcondition
• Changes the current direction clockwise by d degrees from the current direction.
public up();
postcondition
• This object is set to moving mode.
Video soon coming
I know this is way to long please wait for the video i will take it step by step. Video will be released soon today.
Holy crap this brings back memories. I failed java programming a couple of years ago.
oh boy, this sure seems familiar... Java Curriculum for Advanced Placement™ Computer Science
Does the ICT have a paypal site I can donate to, since it is their lesson plans?
**NOTE** if you are indeed the creator of the ICT AP Java Lesson plans, I apologize and will remove this post. I just somehow...doubt it.
double check your bluej link it's headin' to .com,
thanks i'm going to read through this later on
I didn't flunk, but I dropped out of the middle of java courses in college (real life caught up with me XD), but I did have some C++ and BASIC experience (what they teach you in HS), plus my Java classes (on 1.2 back in the day), plus my own hobbyist work on javascript, java applets for webpages and HTML, the last three were all self taught, same as I'm teaching myself now Android programming. I'm looking forward to this course. I could look at that page, but I'll follow the course with the rest of the noobs here [lol]
Fared said:
oh boy, this sure seems familiar... Java Curriculum for Advanced Placement™ Computer Science
Does the ICT have a paypal site I can donate to, since it is their lesson plans?
**NOTE** if you are indeed the creator of the ICT AP Java Lesson plans, I apologize and will remove this post. I just somehow...doubt it.
Click to expand...
Click to collapse
BUSTED!!!
Just my thoughts. I found it most useful to modify and rebuild apps from existing Android code. This is rewarding and instructive in a way a noob tutorial can never match, IMO.
Modifying android code still wont teach you programming. You might be able to do simple things like change the number of home screens or the wallpapers in java, but developing an idea you have might be hard without a basic understanding of programing paradigm.
You might already know how to program, so in that case yeah, jumping straight into new code and figuring out how it works might be easier, but there are those who don't, so they'll benefit from a basic programing course.
Also, I'm sure the op is using the provided link as refference, but for some people a visual approach is better. That link lacks visual aids (video) so the op will make vids and those who need a visual go-over will benefit
OK, point taken. I do have some programming experience, so it may be reasonable to start way earlier for some folks.
Just to throw it out there for anyone that actually wants to learn Java try AppDev. I had the AppDev J2SE and AppDev J2ME but I lost them due to a hard drive failure. I also lost any spare time to actually continue with learning but I did get a basic understanding from the chapters that I completed. Basically its like your in a class room. There is a guy that teaches everything and there are quizzes tests and exercises. If you actually want to learn I would try to find them some where. I would find it pretty hard to try and learn java from a post on a forum, no offense to the OP who is just trying to help.
So you found the kernel and you plagiarize...
Enough has been said.
/end thread
Which version of the JDK is it recommended to get?
So do u guys want me to continue and make videos??? I will make a video teaching how to fix errors and summerize the reading(9 min limit by youtube) if u don't want me to just tell. And so what if I did get from website. I bet a lot of the people here didn't even know the website..........well that is out the way please submit your post if u want me to explane or summarize the text...
mohsinkhan47 said:
So do u guys want me to continue and make videos??? I will make a video teaching how to fix errors and summerize the reading(9 min limit by youtube) if u don't want me to just tell. And so what if I did get from website. I bet a lot of the people here didn't even know the website..........well that is out the way please submit your post if u want me to explane or summarize the text...
Click to expand...
Click to collapse
You can go ahead and stop making videos. Anyone who can't read that isn't in a position to be learning Java.
I don't like being the jerk (some may disagree), but it's just weak that you'd say something was your's then ask for donations for it.
If you want to help people, great. Do it because you want to help people and you feel you have something to give.
mohsinkhan47 said:
And so what if I did get from website. I bet a lot of the people here didn't even know the website..........
Click to expand...
Click to collapse
If you don't see a moral error in stealing someone's work and asking for money from that theft there's something wrong with you.
If I were a mod, I would ban you.
I didn't mean to steal someone else work it just that I wanted to help people because I myself could learn java so when I started to take class it helped me out. I really don't care if u donate or not just want u guys to tell me that u care about me doing all of this. I could have just give u a website and u could have done this all by urself but instead I took my time uploading the gpdraw and the lesson. I just want ur though on what I am doing. Is it right or wrong
hi guys,
i have just launched my new game save the animal from ninja its a exciting physics based puzzle game
you can try it from android market :-
market.android.com/details?id=com.TigerCubStudio.SaveTheAnimal&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5UaWdlckN1YlN0dWRpby5TYXZlVGhlQW5pbWFsIl0
features :-
30 levels in increasing difficulty
realistic or real time physics
standrad physics based puzzles
support for android 1.6+
hd graphics
runs at full speed
realistic jungle music
easy to play but very hard to solve all levels
blast mode and fruit mode is coming soon for more enjoyment
highly optmized only 3 mb
how to play
you have to drag and drop objects from top right corner in such a way that it will cover the animal when you have dropped all the objects test now button and two ninja will come on the clicking of that button ninja will throw their weapons randomly at any place if that will touch animal you will lost else level cleared
Hi,
I've tried your game a little bit and would like to point out some things, which, in my opinion could be improved:
* main menu text is really hard to read in colorful background, maybe adding an background views, rounding them and making white with transparency, would help. I'm not a big fan of that font either, but that's a matter of taste.
* ad area view is larger than the ad itself, doesn't look good
* what's the point of having to drop all the obstacles from fixed height? It looks like it's only to demonstrate that there is physics in the game and make the construction more difficult than it needs to be
* first time playing I had no idea about ninjas and where are they attacking from maybe some in-game guide lines would help or maybe a way to try their attack angles before placing all objects
* I can't scroll level list if I start scrolling on a level button (that fires an event to go to the level)
* Some animal animations (hurt/happy/falling) would be nice
SnottyApps said:
Hi,
I've tried your game a little bit and would like to point out some things, which, in my opinion could be improved:
* main menu text is really hard to read in colorful background, maybe adding an background views, rounding them and making white with transparency, would help. I'm not a big fan of that font either, but that's a matter of taste.
* ad area view is larger than the ad itself, doesn't look good
* what's the point of having to drop all the obstacles from fixed height? It looks like it's only to demonstrate that there is physics in the game and make the construction more difficult than it needs to be
* first time playing I had no idea about ninjas and where are they attacking from maybe some in-game guide lines would help or maybe a way to try their attack angles before placing all objects
* I can't scroll level list if I start scrolling on a level button (that fires an event to go to the level)
* Some animal animations (hurt/happy/falling) would be nice
Click to expand...
Click to collapse
1) ya right i will add something like button behind this text
2)on which device you are i have test it in three devices in none it is outside of actual ad
3) thats necessary just imagine how it would be if you have to directly put the object where you want also that can create some weird issue what if one put object on top of other object also by doing this it will make some what accuracy to drop the object as because of physics you have to calculate little bit
4) i had written it clearly in android market description seems no one is reading that may be one extra screen shot in instruction can help
5) that's why there is no button at right side
6) not possible because that needs designer and with my current earning it is even hard to afford dog or cat even dare to say mouse so no chance for designer
Hajsaaaaaaa
Sent from my GT-S5660 using Tapatalk
tigercubstudio said:
2)on which device you are i have test it in three devices in none it is outside of actual ad
3) thats necessary just imagine how it would be if you have to directly put the object where you want also that can create some weird issue what if one put object on top of other object also by doing this it will make some what accuracy to drop the object as because of physics you have to calculate little bit
4) i had written it clearly in android market description seems no one is reading that may be one extra screen shot in instruction can help
5) that's why there is no button at right side
6) not possible because that needs designer and with my current earning it is even hard to afford dog or cat even dare to say mouse so no chance for designer
Click to expand...
Click to collapse
2. I've tested it on Galaxy Tab 7 and then on Galaxy Tab 10 (in this case ad area is even more "outside of ad"
4. Well, still, I mean there's no indication of possible danger to poor animal when you start your first game And, it's true, no one reads market descriptions and I don't think many are looking for game play instructions there either.
5. Wrong answer, really. I'll write a bit more below.
6. I completely understand you there
So, to elaborate more on points 4 and 5, I think you should give your game to as many friends as possible (and it's best if they haven't tried it yet) and just let them try to play. You'll see how differently they think and behave in a game environment being there for the first time. In my case (simple running/jumping game) I was surprised to see them just blindly tapping all over the screen trying to do "anything" and, despite the fact that there's instructions in the start of every level, they had a hard time finding out that game character can do double jumps and will jump higher if they hold finger instead of tapping it.
In your game, gameplay is much more complex, so tutorial with clear instructions is a must, in my opinion.
As for game level select, I can asure you, that 9 of 10 will try to scroll the button list, not the side, where is no indication that it's scrollable and nothing to scroll there.
Also, I've experienced, that in the start of some levels animals are being affected by physics (or maybe a wind?) and starts to roll, sometimes falling from the platforms. I don't know if it's intentional or not, but it makes level unnecessary hard.
Ah, one more thing.. I'm not sure that asking users for a 5 star rating is a good idea. In many levels.
And, lastly, take my advice with a grain of salt, since I'm just an amateur developer, still learning all these little things: what can annoy your app user and what can make them happy.
2) ya may be i cant see that is out side of ad because i have all device with small screen 3.2 to 3.5 inch so in large screen it will totally visible.
3) yup i will add extra screenshot to with ninja and darts to show animals are in danger from ninja
4) well thinking to add scroll bar somewhat like in browser to move how will be that
also the idea to try game on friends will be much better i will definitely. use that from now
"
Also, I've experienced, that in the start of some levels animals are being affected by physics (or maybe a wind?) and starts to roll, sometimes falling from the platforms. I don't know if it's intentional or not, but it makes level unnecessary hard."
yup 100% intentional need to be fast to solve those levels
"Ah, one more thing.. I'm not sure that asking users for a 5 star rating is a good idea. In many levels."
well i am not giving popup in middle of the game so definitely it will not annoy user but i am asking every time at the time of exit to give rate until they give rate thought user will give rating if they dont like this just crazy experiment with not much good result
one more game
guys you can also try my other game "feed fruit to the animal'
http://goo.gl/frGXN