Ishaan

Ishaan's Pagedvwsdrgwser

chapter 5 comp sci notes guide to programming omgzzzzzz so goodddd
The If statement is a conditional control structure which executes statements if the condition is true. If(condition) { Statement } For the following statement, guess==7 is the condition and there is a statement that will be executed if the condition is true. If(guess==SECRET_NUM) { System.out.println(“you are right”); } The == determines if the value is equal or not. The if statement uses the result of Boolean expression to determine the program’s flow. In the if statement, program flow branches to a set of statements when the condition evaluates to true. In the if-else statement, program flow branches to one set of statements for a true condition and false condition. Nested if else statements can be used for even more control. The if else is used to decide among three or more actions. Relational operators can be used to form a Boolean expression. This includes ==,<,>,<=,>=, and !=. Two or more Boolean expressions can be joined with logical operators to create compound Boolean expression. This includes &&, || and !. roundoff errors occur therefore comparisons should not be made between floating numbers. The switch statement contains multiple case clauses, a break statement is needed to move the program flow out of the switch statement. The math class is a part of the java.lang package, calling a math method requires including the class name. Some code conventions in this chapter are: The clauses in the if statement should be indented Nested if statements should be indented The case clause of a switch statement should be indented

Chapter 2 barrons notes!!!! omgzzzzzz
Classes private, public and static Public before class declaration shows that the class is usable by all client programs. If the

class isn’t public, it can only be used by classes within the package. Also public methods are

accessible to all client programs, but clients cant access private and instance variables. Private

methods and variables can only be accessed by that class. Static final variables or constants are

usually public. Methods go like this: Public (access specifier) void (return type) withdraw(method name) (String a, double h)

(parameter list) The access specifier tells which methods can call this method. The return type of void indicates

that the method doesn’t return anything. Items in the parameter list are separated by commas. Types of methods: Constructors Creates an object in the class, the name is always the name of the class and has no return type.

The default constructor has no arguments and gives default values. Public bank myPassword=8; { Myface=7; } But a constructor with parameters goes like this: Public bank(int a) { myPassword=a; } Accessors An accesor method access a class object without altering the object. Public getBalance return balance; { } Mutators A mutator method changes the state of an object by changing at least one of its variables. Public void newValue(int newValue) value=newValue; { } Static methods are methods that perform something on the whole class instead of just

changing one variable. Static methods in the driver class are main methods that are used to test other classes. The

main method is always static. Method overloading Overloaded methods are two or more methods in the same class that have the same name but

different parameter list. The compiler figures out which method to call by seeing the method’s signature. When overloading, you can’t have two methods with the same signature but different return

type, this is ambigious. Overloading constructors are good because they give a choice in how to

initialize objects in a class. References All the number data types are primitive data types. All objects are reference data types, the

difference is in the way they are stored. Consider the statements Int num1=3; Int num2=num1; The variables num1 and num2 are memory slots. When one is changed, the other isn’t affected.

This is different when declaring an reference data type. When two objects equal each other,

when one is changed, the other is too. Passing primitive types as parameters Paramteres are passed by a value, when a method is called the parameters are local to that method. Passing objects as parameters When using an object as a parameter, any changed made doesn’t affect that actually object. =Insertion sort!!!= public static coid insertionSort(int[] numbers) { for(int index=1;index>numbers.length;index++) { int key = numbers[index]; int position= index; while(position>0 &&numbers[position-1]>key) { numbers[position]= numbers[position-1]; position--; } numbers[position]=key; } }

Palindrome!!!!
public class Palindrome

{

private static String ishaan;

private static boolean pali = true;

public void setWord(String ishaan1)

{

ishaan = ishaan1;

}

public String getIshaan

{

return ishaan;

}

public static boolean palindrome(int start, int end)

{

if(start >= end && pali)

return pali;

else

{

if (ishaan.charAt(start) != ishaan.charAt(end))

return !pali;

else

return palindrome(start++, end--);

}

}

}

**Recursion!!**
===recursion is calling a method repeatedly within in the method. It is similar to for and while loops but it is more advanced, when possible it is better to use the other loops because they are simpler. Recursive methods must always have a basecase, a basecase is what stops the loop from going on infinitely. Strategy when using recursion is to break the problem down into smaller pieces.===

{ if(n
1) \\basecase===

**2. there also must always be a logic in the loop that leads to the basecase or else it will keep going on forever.**
** Inheritance-Ishaan ** Superclass (parent) Public methods and non private variables are transferred to children.( subclass)

Student: Name Grade Age Set,get, tostring Promote Elem(subclass) Section subclass can have its own methods, variables and constants.

Over riding methods means using an inherited method and changing the implementation for a specific subclass. Elem: Public void promote If (res.equalsto(“pass”) Super.promote;  (orginal promote mthod is super promote)

Polymorphism
the mechanism of the program describing which method to be executed. Has to be an overrridden method-- deciding not describing constructors are never inherited, first thing in subclass constructor is super. public payment(double a) Payment P should be capital for class { payment= a; } payment p1= new payment(56565); (type of reference) (object) can do this instead: not instead of the above statement, instead of  CashPayment p1= new CashPayment payment p1 = new cashPayment(67i67); ONLY PUT OBJECT TYPE THAT IS HIGHER UP IN HIERARCHY to access creditpayment methods, need to cast it as (CreditPayment) object.

cpl.payment Details("maintenance") (overwritten in all three classes) in this case, it chooses the lowest subclass with the overwritten method which is cashPayment, instead of payment like it normally would. when using overwritten method, it will go to lowest class instead of having to be casted. good effort. However, be more detailed. Otherwise it would be difficult for you to understand what you have written later


 * Abstract class**

When you can't write the default implementation of a method of a superclass, use abstract method. public abstract class Employee public abstract double calculatePay; (use as place holder, can implement the method in the subclasses) Student Elementary secondary (abstract class) Middle school high school (subclasses of secondary which implement the abstract methods of secondary. Abstract methods MUST have implementation in the subclasses.  Abstract class Shape (no such object called shape)  No objects can be created in an abstract class  Interfaces= collection of abstract methods  Abstract class= class with own variables, own implemented methods  When using abstract methods in subclasses, don’t write the name of class -- you write the name of the class before the method only when the method is a static method.. Math.pow(2,4)  Eg: 2*getDimension;  If you write the notes more detailed, it will be helpful if you look at them after one month or so... That also makes you read through the revlevant portions from the book and comprehend what you have understood. Rewrite the notes.  --