DEV Community

Neelakandan R
Neelakandan R

Posted on

1

Task-22/01/2025

Task 1:
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.
package B14;

public class Theatre {
    String movieName;
    int movie_time;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Theatre movie1 = new Theatre();
        movie1.movieName = "Jailer";
        movie1.movie_time = 630;
        Theatre movie2 = new Theatre();
        movie2.movieName = "leo";
        movie2.movie_time = 7;
        movie1.watch_movie();
        movie2.watch_movie();
    }

    public void watch_movie() {
        System.out.println("watching " + movieName);
        System.out.println("movei_time " + movie_time);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

watching Jailer
movei_time 630
watching leo
movei_time 7
Enter fullscreen mode Exit fullscreen mode

Task 2:
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.
package B14;

public class Eb_reading {
    int unit;
    static int a = 10;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Eb_reading assessor = new Eb_reading();
        int unit = assessor.reading();
        System.out.println("Unit" + unit);
        assessor.calculate(unit);

    }

    private void calculate(int b) {
        // TODO Auto-generated method stub
        int c = a * b;
        System.out.println("total" + c);
    }

    private int reading() {
        // TODO Auto-generated method stub
        return 30;
    }

}
Enter fullscreen mode Exit fullscreen mode

Output:

Unit30
total300
Enter fullscreen mode Exit fullscreen mode

Task 3:

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()

package B14;

public class Calculator {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Calculator calc = new Calculator();
        calc.add(10, 30);
        calc.sub(50, 90);
        calc.multi(90, 80);
        calc.divide(100, 90);
    }

    public void add(int a, int b) {
        int c = a + b;
        System.out.println(c);
    }

    public void sub(int a, int b) {
        int c = a - b;
        System.out.println(c);
    }

    public void multi(int a, int b) {
        int c = a * b;
        System.out.println(c);
    }

    public void divide(int a, int b) {
        int c = a % b;
        System.out.println(c);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

40
-40
7200
10
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more