Assignment - 0: static, non-static

  1. Create a class Called Theatre.
  2. Declare below global variables in it.
    2.1. String movieName
    2.2. int movie_time
  3. Add main method
  4. Inside main method, create two instances (objects),
    4.1 movie1
    4.2 movie2
  5. For instance movie1, add 'Jailer' as movieName and 630 as movie_time
  6. For instance movie2, add 'Leo' as movieName and 7 as movie_time
  7. Create and define a method as below.
    public void watch_movie()
    {
    System.out.println("Watching " + movieName);
    System.out.println("Show Time is " +movie_time);
    }
  8. Call above method using both the instances - movie1, movie2.
  9. Go through and record your observations.

Assignment 1: return statement

  1. Create a class called EB_Reading
  2. Have main method in it.
  3. Create an object called assessor.
  4. Using assessor instance, call a method named 'reading'.
  5. 'reading' method should return consumed units in int.
  6. Store the returned value as 'consumed_units'.
  7. Using the same 'assessor' instance, call a method
    named as 'calculate'.
  8. Pass 'consumed_units' as argument to calculate.
  9. Based on the consumed_units value, find out How much Customer should pay.
  10. Print Payment value.

Assignment 2: Add Methods in Calculator

public class Calculator
{

public static void main(String[] args)
{
Calculator calc = new Calculator();
calc.add();

}
public void add()
{
System.out.println(10+20);
}

}

//subtract()

//multiply()

//divide()


Assignment 3: Instance Methods

  1. Create a class Called Theatre.
  2. Declare below global variables in it.
    2.1. String movieName
    2.2. int movie_time
  3. Add main method
  4. Inside main method, create two instances (objects),
    4.1 movie1
    4.2 movie2
  5. For instance movie1, add 'Jailer' as movieName and 630 as movie_time
  6. For instance movie2, add 'Leo' as movieName and 7 as movie_time
  7. Create and define a method as below.
    public void watch_movie()
    {
    System.out.println("Watching " + movieName);
    System.out.println("Show Time is " +movie_time);
    }
  8. Call above method using both the instances - movie1, movie2.
  9. Go through and record your observations.

Assignment 4: instance method, local variable, arguments,return

  1. Create a class called Theatre
  2. Have main method in it.
  3. Create an instance[object] called raja of Theatre class.
  4. Call method bookTicket(200) eg. raja.bookTicket(100)
  5. Have method signature for bookTicket method with necessary arguments for handling the input 200.
  6. Define bookTicket method as below.
    1. Declare a local variable ticket_price in int datatype.
    2. Assign 120 as value for ticket_price variable.
    3. Subtract 120 from method argument (200)
    4. Store result of above line into another variable called balance of int datatype.
    5. return this balance to main method.
  7. In main method, receive this balance as int balance
  8. In main method, print as below.
    System.out.println("After booking ticket " + balance);

Assignment 5: Method Calling, private

Goal:
Learning Method Calling, Accessing static, non-static variables from other classes, private modifier.

Steps:

Create a class Called School.
Have non-static variables as below.
int mark;
private int salary;
Have static variable as below.
static String school_name = "St. Antony's Primary School";
Define non-static methods mentioned below
void conduct_exams()
- Have a print statement inside this method
void publish_results(int mark)
- Have a print statement inside this method to print mark
Now, create another class called Teacher
Create main method inside Teacher class
Create an instance(object) for School class [Object name -> teacher]
Using 'teacher' object, call conduct_exams() method
Using 'teacher' object, call publish_results() method and pass 75 as argument here.
Print school_name
Try to access private variable salary in Teacher class and note down the error message.


Assignment 6:

GOAL: Learning private, default and public Access Modifiers, Creating Package and understanding its usage, Calling Methods with/without arguments.

  1. Check if you can create private class
  2. Check if you can create private main method
  3. Check if you can create Method local variable as private.

Task:

  1. Create a package called bank.chennai.
  2. Create a public class called 'SBI'.
  3. Have default non-static variables String empName, empId.
  4. Have default static variable branch_name = 'chennai'
  5. Create two default, non-static methods
    get_loan(int amount), create_account() with void as return datatype.
  6. Now, in the same package(bank.creditcard), create one more default class called Account_Holder.
  7. Have main method in this class.
  8. Try to access all static, non-static variables and non-static methods in SBI class.
  9. Create another package called bank.madurai.
  10. In this package, create default class called Account_Holder_Madurai.
  11. Have main method in this class.
  12. Try to access all static, non-static variables and non-static methods in SBI class.
  13. Note down the Errors and rectify those errors and make sure this class gives output without any error.

Assignment 7:
Goal: Learning Inheritance, super keyword and Method Overriding
Grandma:

  1. Create a class called 'Grandma'.
  2. Declare Field as below in it.
  3. String name = "Stella";
  4. Have below methods in it.
  5. public void work()
  6. Have print statements as you wish in the above methods' definition.

Mother:

  1. Create a class called 'Mother' as Child class of Grandma.
  2. Declare Field as below in it.
  3. String name = "Arasi";
  4. Have below method in it.
  5. public void work()
  6. Have print statement to print 'name' and super.name in work() definition.
  7. Add 'super.work();' inside work() method.

Kid:

  1. Create a class called 'Kid' as Sub class of Mother.
  2. Declare Field as below in it.
  3. String name = "Suman";
  4. Define main method as 'public static void main(String[] args)
  5. Inside main method, create an instance called 'kid' for Kid class.
  6. Have below methods in it.
  7. public void work()
  8. public void study()
  9. Have print statements as you wish in the above two methods' definition.
  10. Call study() method from main method.
  11. Inside study() method, call work() method.
  12. Print name and super.name inside work() method.

Assignment - 8: Multilevel Inheritance, Abstraction

GOAL: Understanding Multilevel Inheritance, Abstraction

  1. Create an abstract class called HeadOffice.
  2. Have below normal methods in it.
    2.1. public void check_accounts(int amount)
    • Have a print statement inside here
      2.2. public int pay_tax(int amount)
    • return this.amount from here
  3. Have an abstract method as below.
    3.1. public abstract void receive_Customers()
  4. Create another abstract class called Branch_Plan as sub class of HeadOffice
  5. Have main method in it.
  6. Add a print statement inside main method.
  7. Add below method
  1. Create another class 'Branch' as sub class of Branch_Plan
  2. Handle abstract methods here with print statements.
  3. Create an instance called 'branch' for Branch class.
  4. Confirm the below methods can be called.