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);
}
}
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);
    }
}
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
watching Jailer
movei_time 630
watching leo
movei_time 7
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;
}
}
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;
    }

}
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
Unit30
total300
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);
}
}
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);
    }
}
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
40
-40
7200
10
40 -40 7200 10

Enter fullscreen mode Exit fullscreen mode

原文链接:Task-22/01/2025

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
Someone to love, something to do, and something to hope for.
有爱的人,有喜欢的事业,有梦想
评论 抢沙发

请登录后发表评论

    暂无评论内容