Task 1:
Assignment - 0: static, non-static
- Create a class Called Theatre.
- Declare below global variables in it. 2.1. String movieName 2.2. int movie_time
- Add main method
- Inside main method, create two instances (objects), 4.1 movie1 4.2 movie2
- For instance movie1, add 'Jailer' as movieName and 630 as movie_time
- For instance movie2, add 'Leo' as movieName and 7 as movie_time
- Create and define a method as below. public void watch_movie() { System.out.println("Watching " + movieName); System.out.println("Show Time is " +movie_time); }
- Call above method using both the instances - movie1, movie2.
- 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);
}
}
Output:
watching Jailer
movei_time 630
watching leo
movei_time 7
Task 2:
return statement
- Create a class called EB_Reading
- Have main method in it.
- Create an object called assessor.
- Using assessor instance, call a method named 'reading'.
- 'reading' method should return consumed units in int.
- Store the returned value as 'consumed_units'.
- Using the same 'assessor' instance, call a method named as 'calculate'.
- Pass 'consumed_units' as argument to calculate.
- Based on the consumed_units value, find out How much Customer should pay.
- 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;
}
}
Output:
Unit30
total300
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);
}
}
Output:
40
-40
7200
10
Top comments (0)