Archive for October, 2007
Chapter 5
5-11. A class is a software package or template that describes the characteristics of similar objects.2.The object will then be delected from the memory storage.3. three important behavior of object- an object has a behavior as defined by the methods of its class- an object has a state, which is another way of saying that at any particular moment instance variables have particular values.- an object has its own identity, which distinguishes it from all other objects in the computer’s memory 4. two object is involve when two objects is sent- the sender and the receiver, also called he client and the server. 5. the interface of a class is the list of method supported by the server. 5-2 1.Message that change an object’s state are called mutators. The accessors is another access the object’s state if the mutators worked correctly. 2.List two visibility modifiers and describe when they are used.-(1)private: specify that data or method to only be used in certain cirtaintance, within {}.-(2)public: the data or imformation after such a modifier can be seen or used by anybody and anywhere.3.A constructor method is one or more methods that indicate how to initialize a new object.4.It can returns a string containing the student’s name and test score.5. First, we have to assign the variables an initial values.Then we set the object ’s data attributes by sending the same message. Additionally, we add a object with variable2 . Last, the variable 1 and 2 is refer to the same object. 6. the different between the primitive types and the reference types are in memory. The primitive type’s variable is best viewed as a box that contains a value of that primitive type. A variable of a reference type is thought of as a box that a contain a pointer to an object.the example for the primitive type is (int, double)the example for the reference type ( all classes, for instance)7. it is possible to break the connection between a variable and the object it reference by simply assign the value null to the variable. 8.When a program attempts to run a method with an object that is null, Java throws a null pointer exception. ex) String str = null; System.out.println (str. length ()); 9. Default parameter is parameter list, this constructor initializes numeric variables to zero and object variables to null, thus indicating that the object variables currently reference no, objects.10.If a class template contains no constructors, the JVM provides a primitive default constructor behind the scenes. This constructor initialized numeric variables to zero and the object variables to null. thus indicating that the object variables currently reference no object.11.) A class can include more than one constructor, provided each has unique parameter list, but all the constructors must have the same name, that is, the name of the class. 5.41. Formal parameter is a parameter that listed in a method’s definition. Actual parameter is values passed to method when it is invoked.2. When a method is called, the value of the actual parameter is automatically transferred to the corresponding formal parameter immediately before the method is activated.3.public int Sum() {int sum;sum= (int) Math.round ( a+b);debug(“Sum:”,average);return sum;}4. local variable is temporary working storage for data in a method5.51. Local variable and formal parameters exist during a single execution of a method. Instance variables, on the other hand, last for the lifetime of an object.2. shadowing method that the programmer uses the symbols this to refer to the current instance of a class within that class definition.EX) this.iAMVariable = IAMAVariable; Shadowing is considered a dangerous programming practice because it greatly increases the likelihood of making a coding error.
Add comment October 22, 2007
HW 4.7,4.8,4.9
1a)Variable i is equal to 1 and i is less than and equal to limit , add 1 operator to i variable If i remainder is equal 2 b) Use Random generator to operate the java file myNumberVariable x is equal to 0Variable is your numberProgram will print ”i am guessing a number between 1 to 10″”Which number is it” and your number is equals to my number than the program will print” That’s it!” if your guess is wrong the program will print ” sorry, try again”2.a) variable is always system.out.print (x^2% 2)System.out.printin (x^3 % 2)b)public class interger{ public class void main ( String [] args){ 1.) we use this to create a scanner object by opening it on a file rather than the keyboard object. That is a equation for opening a scanner on my file.1a)there were no odd number reminder when i % 2 equals 0 because 1 divide by 2 is has a reminder of 0 and can’t be printed cause it is not an odd #b) There are more than one operator in the equation
Add comment October 11, 2007
4.3
1. Jill use while statement in her instructions to Jack because she wants to tell him to do the stuff repeatedly as long as the condition holds true .
2. Jill use the if-else statement because she mean to tell jack if some condition iis true,do stuff 1, and if it is false, do stuff
a) if ( a checker piece is red) {
put it on a red square;
}else{
put it on a black square;
}
b)if ( your shoes are muddy) {
take them off ;
leave them outside the door ;
}
c) pick up all the marbles on the floor;
put them into a bag;
3.a)if x is larger than y then temp = x,x = y and y = temp;
otherwise temp= y,y= x and x= temp
b)as long as count is less than or equal to sum, then an interger will continue read as x and sum =sum + Math (abs) x
Add comment October 1, 2007