Language:
Contact Us

Search

Notes : Saanvi Coding Java AP

  • Share this:

12 July 2022

Assignment :

1) Print the following pattern using while loop ( int n = 4 )

1 1 1 1
2 2 2 2 
3 3 3 3
4 4 4 4

2) Print the following pattern using while loop ( int n = 4 )
4 4 4 4
3 3 3 3
2 2 2 2
1 1 1 1

3) Write a program to print following pattern using while loop.


2 2 
3 3 3
4 4 4 4 

4) Write a program to print following pattern using for loop.


* *
* * *
* * * *

5) Print the following pattern using while loop ( int n = 4 )


2 2 
3 3 3
4 4 4 4
3 3 3
2 2
1

Class work: While loop

30 June 2022:

Assignment :

1) Print the following pattern using while loop ( int n = 4 )

1 1 1 1
2 2 2 2 
3 3 3 3
4 4 4 4

2) Print the following pattern using while loop ( int n = 4 )
4 4 4 4
3 3 3 3
2 2 2 2
1 1 1 1

3) Write a program to print following pattern using for loop.


2 2 
3 3 3
4 4 4 4 

4) Write a program to print following pattern using for loop.


* *
* * *
* * * *

5) Print the following pattern using while loop ( int n = 4 )


2 2 
3 3 3
4 4 4 4
3 3 3
2 2
1

6 June 2022:

1) Write a program to get a number using scanner and call function pattern1(). 
Write a function pattern1() to print following pattern using for loop.


2 2 
3 3 3
4 4 4 4 

2) Write a program to get a number using scanner and call function pattern2(). 
Write a function pattern2() to print following pattern using while loop.


2 2 
3 3 3
4 4 4 4 

3) Write a program to get a number using scanner and call function pattern3(). 
Write a function pattern2() to print following pattern using for loop.


* *
* * *
* * * *

4) Combine pattern1(), pattern2(), pattern3() in one Java programme. 

Class work:

Scanner class, function, while loop, for loop

 

24 May 2022

Assignment ::

1) Write a program to printTriangle Star using while loop.

Input : n = 5
Output: 
* 
* * 
* * * 
* * * * 
* * * * * 

2) Write a program to print Right Aligned Triangle with * using while loop. 

Input : n = 4
Output: 
           * 
         * * 
       * * * 
     * * * * 
3) Write a program to print folling triangle pattern using while loop:

Input : n = 7

Output:
      * 
     * * 
    * * * 
   * * * * 
  * * * * * 
 * * * * * * 
* * * * * * * 


7 Apr 2022:

Revise chp 1 to 4 from Runestone.

Complete all MCQs as well.

Will be giving test on chp 1 to 4.

Revise all your notes twice a day.

public class Time
{
private int hrs;
private int mins;
private int secs;

public Time()                                     //default constructor
{ /* implementation not shown */ }

public Time(int h, int m, int s)           //constructor with 3 parameter
{ /* implementation not shown */ }

/** Resets time to hrs = h, mins = m, secs = s. */           / /mutator method
public void resetTime(int h, int m, int s)
{ /* implementation not shown */ }


/** Advances time by one second. */                 / /mutator method
public void increment()
{ /* implementation not shown */ }

/** @return true if this time equals t, false otherwise */           //accessor method
public boolean equals(Time t)
{ /* implementation not shown */ }

/** @return true if this time is earlier than t, false otherwise */   //accessor method
public boolean lessThan(Time t)
{ /* implementation not shown */ }

\/** @return a String with the time in the form hrs:mins:secs */    //accessor method
public String toString()
{ /* implementation not shown */ }
}
 

 

4 Apr 2022:
Assignment :

1) MCQ from Barrons chp 2 and 4.

2) Prepare throughly - mugup from following notes.

Classes

• A class contains the blueprint, or design, from which individual objects are created.

• Classes tend to represent things that are nouns.

• A class declaration (or class definition) is the line of code that declares the class.

• By naming convention, class names begin with an uppercase letter and use camel case.

eg. public class Table

• The two access modifiers that are tested on the AP Computer Science A Exam are public and private.

• All classes should be declared public.

• A public class means that the class is visible to all classes everywhere.

 

Instance Variables or Attributes
• Instance variables are properties that all objects from the same class possess.

• Attributes help distinguish one object from another in the same class.

• All instance variables should be declared private.

• A class can have as many instance variables as is appropriate to describe all the attributes of an object from the class.

• By naming convention, all instance variables begin with a lowercase letter and use camel case.

eg. public int tablePrice;

• The current values of all of the instance variables of an object determine the state of the object.

• The state of the object is changed whenever any of the instance variables are modified.

 

Constructors

• Every class, by default, comes with a no-argument (or empty) constructor.

• Parameterized constructors should be created if there are values that should be assigned to the instance variables at the moment that an object is created.

• A class can have as many parameterized constructors as is relevant.

• The main reason to have a parameterized constructor is to assign values to the instance variables.

• Other code may be written in the constructor.

• A parameter is a variable that receives values and is declared in a parameter list of a method or constructor.

 

Methods

• The methods of a class describe the actions that an object can perform.

• Methods tend to represent things that are verbs.

• By naming convention, method names begin with a lowercase letter and use camel case.

eg. public int getPrice()

• The name of a method should describe the purpose of the method.

• Methods should not be multi-purpose. They should have one goal.

• A method declaration describes pertinent information for the method such as the access modifier, the return type, the name of the method, and the parameter list.

• Methods that don’t return a value are called void methods.

• Methods that return a value of some data type are called return methods.

• Methods can return any data type.

• Return methods must include a reachable return statement.

• Methods that return the value of an instance variable are called accessor or getter methods.

• Methods that modify the value of an instance variable are called mutator or modifier or setter methods.

• The data type of all parameters must be defined in the parameter list.

 

Objects

• An object from a class is a virtual realization of the class.

• Objects store their own data.

• An instance of a class is the same thing as an object of a class.

• The word “instantiate” is used to describe the action of creating an object. Instantiating is the act of constructing a new object.

• The keyword new is used whenever you want to create an object.

• An object reference variable stores the memory address of where the actual object is stored. It can only reference one object.

• The reference variable does not store the object itself.

• Two reference variables are equal only if they refer to the exact same object.

• The word null means no value.

• A null reference describes a reference variable that does not contain an address of any object.

• You can create as many objects as you want from one class. Each is a different object that is stored in a different location in the computer’s memory.

 

Passing Parameters by Value

• The parameter variables that are passed to a method or constructor are called actual parameters (or arguments).

• The parameter variables that receive the values in a method or constructor are called formal parameters.

• Passing by value means that only the value of the variable is passed.

• Primitive variables are passed by value.

• It is impossible to change the value of actual parameters that are passed by value.

 

Passing Parameters by Reference

• Passing by reference means that the address of where the object is stored is passed to the

method or constructor.

• Objects are passed by reference (including arrays).

• The state of the object can be modified when it is passed by reference.

• It is possible to change the value of actual parameters that are passed by reference.

 

Overloaded methods or constructors

• Overloaded constructors and methods may have (1) a different number of parameters, (2) the same exact parameter types but in a different order.

• Overloaded methods have the same name; however, their method parameter lists are different in some way.

• They always have same return type.

eg. public int add(int a, int b)

      public int add(double a, double b)                //valid overloading

      public double add(double a, double b)         //invalid overloading

 

static

• Static variables are also known as class variables.

• A class variable is a variable that is shared by all instances of a class.

• Changes made to a class variable by any object from the class are reflected in the state of each object for all objects from the class.

• Static final variables are also called class constants.

• If a method is declared static, it can only call other static methods and can reference static variables.

 

Scope

• The scope of a variable refers to the area of the program in which it is known.

• The scope of a local variable is in the block of code in which it is defined.

• The scope of an instance variable is the class in which it is defined.

• The scope of a parameter is the method or constructor in which it is defined.

 

Miscellaneous

• Data encapsulation is the act of hiding the values of the instance variables from other classes.

• Declaring instance variables as private encapsulates them.

• Declaring instance variables as public allows instant access to them using the dot operator.

• Use the keyword this when you want to refer to the object itself.

• An IllegalArgumentException error occurs when a parameter that is passed to a method fails to meet criteria set up by the programmer.

1 Apr 2022:Assingment  

From Runestone revise chp 1, 3, 4 including all MCQ and programmes.

25.3 22: Assignment

1) Solve the questions in below link :

Test 1

Barrons Chp 3 including MCQ

17 March 22: Assignment

Barrons Chp 2 including MCQ.

1) Solve the questions in below link :

Test 1

mugup 
class
variable / attributes
methods, parameters, return value, constructors
overloading 
Public methods
Public Variables
Private methods
private Variables
static methods
static Variables
primitive data types vs objects
Pass by value vs Pass by reference.

14 March 22: Assignment

1) Solve the questions in below link :

Test 1

2) Barrons chp 2 including MCQ

11 March 22:

mugup 
class
variable / attributes
methods, parameters, return value, constructors
overloading 

chp 1 from Barrons including MCQ

Revise your notes 3-4 times a day and before going to bed.

08 March 22: Assignment

1) Write a class called Coin|Collection: (as given on 4 March)

2) Chp 4 from Barrons (including MCQs)

Daily 30min of practice 

Class Work:

Constructors, parameters, getters, setters.

MCQ for Stirng 

 

04 March 22: Assignment

Revise your notes daily.

1) Revise DreamVacation class

2) Write a class called CoinCollection

The High School Coin Collection Club needs new software to help organize its coin collections. Each coin in the collection is represented by an object of the Coin class. The Coin class maintains three pieces of information for each coin: its country of origin, the year it was minted, and the type of coin it is. Because coin denominations vary from country to country, the club has decided to assign a coin type of 1 to the coin of lowest denomination, 2 to the next lowest, and so on. For American coins, coinType is assigned like this:

Coin Name

Value

coinType

Penny

$0.01

1

Nickel

$0.05

2

Quarter

$0.25

3

Half Doller

$0.50

4

a. An instance variable for the name, value, and coin type
c. A no-argument constructor
d. A parameterized constructor that takes in coin name, value and coin type
e. Accessor (getter) methods for all 3 instance variables
f. Modifier (setter) methods for all 3 instance variables

3) MCQ from Chp 1 (Barrons)

04 March 22: Class work

DreamVacation class with constructors  (with and without parameters), setters x 2, getters x 2 and driver code.

 

02252022 Assignment :

Revise long book 2 times a day - and before bed ( 5-10min each time)

Write the following programms 

1) Print following pattern using for loop:

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

2) Print following pattern using for loop :
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1

3) Print the following pattern using for loop :
1 1 1 1 1 1
2 2 2 2 2
3 3 3 3
4 4 4 
5 5
6

4) Print following pattern using while loop:

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

5) Print following pattern using while loop :
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1

6) Print the following pattern using while loop :
1 1 1 1 1 1
2 2 2 2 2
3 3 3 3
4 4 4 
5 5
6

02252022 Classwork :

for loop - forward and backwrad movemnt

.length() vs .length (method vs attribute)

while loop - forward and backward

i = i+ 1       i += 1    i++  are all same

i = i + 2       i += 2 are also same

i = i + j       i += j are also same

i = i - 1       i -= 1    i--  are all same

i = i - 2       i -= 2 are also same

i = i - j       i -= j are also same

Arrays: (1D)

String[] name = new String[10];

int[] sNum = new int[10]

Raz Manva

Raz Manva