0% found this document useful (0 votes)
23 views20 pages

Assignment 3-Instance Method and Method Overloading

Uploaded by

ibtehajr27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views20 pages

Assignment 3-Instance Method and Method Overloading

Uploaded by

ibtehajr27
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Lab Assignment 03

Course Code: CSE111

Course Title: Programming Language II

Topic: Instance Method and Method Overloading

Number of Tasks: 11

[Submit all the Coding Tasks (Task 1 to 8) in the Google Form shared on buX
before the next lab. Submit the Tracing Tasks (Task 9 to 11) handwritten to your
Lab Instructors at the beginning of the lab]
[You are not allowed to change the driver codes of any of the tasks]

Task 1
Design the BankAccount class in such a way so that the following code
provides the expected output.

Driver Class Output

public class BankAccountTester{ Account No: 0


public static void main(String args[]){ Type: Not Set
BankAccount acc1 = new BankAccount(); -----1-----
System.out.println(acc1.printDetails()); Account information updated!
System.out.println("-----1-----"); -----2-----
acc1.setInfo(1456890,"Salary"); Account No: 1456890
System.out.println("-----2-----"); Type: Salary
System.out.println(acc1.printDetails()); -----3-----
System.out.println("-----3-----"); Account information updated!
BankAccount acc2 = new BankAccount(); -----4-----
acc2.setInfo(1765498,"Student"); Account No: 1765498
System.out.println("-----4-----"); Type: Student
System.out.println(acc2.printDetails());
}
}

Task 2
Design the Shape class with necessary properties to produce the given
output for the provided driver code.

Driver Class Output

public class ShapeTester{ Shape Name: Circle


public static void main(String args []){ Area: 78.54
Shape circle = new Shape(); 1---------------
Shape triangle = new Shape(); Shape Name: Triangle
Shape rectangle = new Shape(); Area: 14.0
2---------------
circle.setParameters("Circle", 5); Shape Name: Rectangle
triangle.setParameters("Triangle", 4, 7); Area: 10.56
rectangle.setParameters("Rectangle", 2.4, 4.4);
System.out.println(circle.details());
System.out.println("1---------------");
System.out.println(triangle.details());
System.out.println("2---------------");
System.out.println(rectangle.details());
}
}

Task 3
Design the “Shelf” class with necessary properties, so that the given
output is produced for the provided driver code.

Driver Class Output

public class ShelfTester{ Shelf capacity: 0


public static void main(String [] args){ Number of books: 0
Shelf shelf = new Shelf(); 1---------------
shelf.showDetails(); Zero capacity. Cannot add books.
System.out.println("1---------------"); 2---------------
shelf.addBooks(3); 3 books added to shelf
System.out.println("2---------------"); 3---------------
shelf.capacity = 7; Shelf capacity: 7
shelf.addBooks(3); Number of books: 3
System.out.println("3---------------"); 4---------------
shelf.showDetails(); Exceeds capacity
System.out.println("4---------------"); Shelf capacity: 7
shelf.addBooks(5); Number of books: 3
shelf.showDetails(); 6---------------
shelf.capacity += 4; 5 books added to shelf
System.out.println("6---------------"); Shelf capacity: 11
shelf.addBooks(5); Number of books: 8
shelf.showDetails();
}
}

Task 4
Design the Library class with the necessary properties so that the
given output is produced for the provided driver code.
Driver Code Output

public class Tester{ 1-------------


public static void main(String[] args) { Book 'Ice' added to the library
Library a1 = new Library(); 2-------------
Maximum Capacity: 3
a1.setBookCapacity(3);
Total Books: 1
System.out.println("1-------------"); Book list:
a1.addBook("Ice"); Ice
System.out.println("2-------------"); 3-------------
a1.printDetail(); Book 'Emma' added to the library
System.out.println("3-------------"); Book 'Wings' added to the library
a1.addBook("Emma"); Maximum capacity exceeds. You can't add
more than 3 books
a1.addBook("Wings");
4-------------
a1.addBook("Next"); Maximum Capacity: 3
System.out.println("4-------------"); Total Books: 3
a1.printDetail(); Book list:
Library a2 = new Library(); Ice
a2.setBookCapacity(4); Emma
System.out.println("5-------------"); Wings
5-------------
a2.addBook("Onnobhubon");
Book 'Onnobhubon' added to the library
a2.addBook("Ami"); Book 'Ami' added to the library
System.out.println("6-------------"); 6-------------
a2.printDetail(); Maximum Capacity: 4
System.out.println("7-------------"); Total Books: 2
a2.addBook("Deyal"); Book list:
Onnobhubon
a2.addBook("Himu");
Ami
a2.addBook("Megher Upor Bari"); 7-------------
System.out.println("8-------------"); Book 'Deyal' added to the library
a2.printDetail(); Book 'Himu' added to the library
} Maximum capacity exceeds. You can't add
} more than 4 books
8-------------
Maximum Capacity: 4
Total Books: 4
Book list:
Onnobhubon
Ami
Deyal
Himu
Task 5
Design the TaxiLagbe class with necessary properties to produce the
given output for the provided driver code.

Driver Code Output

public class TaxiTester{ 1-------------


public static void main(String[] args) { Taxi number: 1010-01
TaxiLagbe taxi1 = new TaxiLagbe(); This taxi can cover Dhaka area
Total Passenger: 0
taxi1.storeInfo("1010-01", "Dhaka");
Passenger Lists:
System.out.println("1-------------"); Total collected fare: 0 Taka
taxi1.printDetails(); 2-------------
System.out.println("2-------------"); Dear Wilson! Welcome to TaxiLagbe
taxi1.addPassenger("Wilson", 105); 3-------------
System.out.println("3-------------"); Taxi number: 1010-01
taxi1.printDetails(); This taxi can cover Dhaka area
Total Passenger: 1
System.out.println("4-------------");
Passenger Lists:
taxi1.addPassenger("Walker", 100, "Wood", 200); Wilson
System.out.println("5-------------"); Total collected fare: 105 Taka
taxi1.printDetails(); 4-------------
System.out.println("6-------------"); Dear Walker! Welcome to TaxiLagbe
taxi1.addPassenger("Karen", 200); Dear Wood! Welcome to TaxiLagbe
taxi1.addPassenger("Donald", 130); 5-------------
Taxi number: 1010-01
System.out.println("7-------------");
This taxi can cover Dhaka area
taxi1.printDetails(); Total Passenger: 3
System.out.println("8-------------"); Passenger Lists:
TaxiLagbe taxi2 = new TaxiLagbe(); Wilson Walker Wood
taxi2.storeInfo("1010-02", "Khulna"); Total collected fare: 405 Taka
taxi2.addPassenger("Don", 115, "Parker", 215); 6-------------
Dear Karen! Welcome to TaxiLagbe
System.out.println("9-------------");
Taxi Full! No more passengers can
taxi2.printDetails(); be added
} 7-------------
} Taxi number: 1010-01
This taxi can cover Dhaka area
Total Passenger: 4
Passenger Lists:
Wilson Walker Wood Karen
Total collected fare: 605 Taka
8-------------
Dear Don! Welcome to TaxiLagbe
Dear Parker! Welcome to TaxiLagbe
9-------------
Taxi number: 1010-02
This taxi can cover Khulna area
Total Passenger: 2
Passenger Lists:
Don Parker
Total collected fare: 330 Taka

Task 6
Design the Student class with the necessary properties to produce the
given output for the provided driver code.
Hint:
- A student having cgpa>=3.5 and credit>10 is eligible for
scholarship.
- A student with cgpa>=3.5 but <3.7 is eligible for Need-based
scholarship.
- A student having cgpa >=3.7 is eligible for Merit based
scholarship

Driver Code Output

public class StudentTester{ Name: Not Set


public static void main(String[] args) { Department: CSE
Student std1 = new Student(); CGPA: 0.0
Credits: 9
std1.showDetails();
Scholarship Status: Not Set
System.out.println("1---------------"); 1---------------
std1.updateDetails("Alif", 3.99, 12); 2---------------
System.out.println("2---------------"); Alif is eligible for Merit based
std1.checkScholarshipEligibility(); scholarship
System.out.println("3---------------"); 3---------------
std1.showDetails(); Name: Alif
Department: CSE
Student std2 = new Student();
CGPA: 3.99
std2.updateDetails("Mim", 3.4); Credits: 12
Student std3 = new Student(); Scholarship Status: Merit based
std3.updateDetails("Henry", 3.5, 15, "BBA"); scholarship
System.out.println("5---------------"); 5---------------
std2.checkScholarshipEligibility(); Mim is not eligible for scholarship
System.out.println("6---------------"); 6---------------
Henry is eligible for Need based
std3.checkScholarshipEligibility(); scholarship
System.out.println("7---------------"); 7---------------
std2.showDetails(); Name: Mim
Department: CSE
System.out.println("8---------------");
CGPA: 3.4
std3.showDetails(); Credits: 9
} Scholarship Status: No scholarship
} 8---------------
Name: Henry
Department: BBA
CGPA: 3.5
Credits: 15
Scholarship Status: Need based
scholarship

Task 7
Complete the following Cart class to generate the given output from the tester code:
● A cart will have a cart number which will be assigned in create_cart() method.
● Each cart can hold up to 3 items (at max).
● Each cart must have two arrays to store items and their respective prices.
● The items inside a cart will be added in addItem() method only if the cart items do
not exceed 3.
● The giveDiscount() method saves the discount given to that cart object and
updates the price accordingly.

Driver Code Output

public class CartTester{ ====1====


public static void main(String [] args){ Table added to cart 1.
Cart c1 = new Cart (); You have 1 item(s) in your cart now.
Cart c2 = new Cart (); Chair added to cart 1.
Cart c3 = new Cart (); You have 2 item(s) in your cart now.
Television added to cart 1.
c1.create_cart(1); You have 3 item(s) in your cart now.
c2.create_cart(2); You already have 3 items on your cart
c3.create_cart(3); ====2====
System.out.println("====1===="); Stove added to cart 2.
c1.addItem("Table", 3900.5); You have 1 item(s) in your cart now.
c1.addItem("Chair", 1400.76); ====3====
c1.addItem(5400.87, "Television"); Chair added to cart 3.
c1.addItem(5000.0, "Refrigerator"); You have 1 item(s) in your cart now.
Chair added to cart 3.
System.out.println("====2===="); You have 2 item(s) in your cart now.
c2.addItem("Stove",439.90); ====4====
Your cart(c1) :
System.out.println("====3===="); Table - 3900.5
c3.addItem("Chair",1400.5); Chair - 1400.76
c3.addItem(3400.0, "Chair"); Television - 5400.87
Discount Applied: 0.0%
System.out.println("====4===="); Total price: 10702.130000000001
c1.cartDetails(); ====5====
Your cart(c2) :
System.out.println("====5===="); Stove - 439.9
c2.cartDetails(); Discount Applied: 0.0%
Total price: 439.9
System.out.println("====6===="); ====6====
c3.cartDetails(); Your cart(c3) :
c1.giveDiscount(10); Chair - 1400.5
Chair - 3400.0
System.out.println("====7===="); Discount Applied: 0.0%
c1.cartDetails(); Total price: 4800.5
} ====7====
} Your cart(c1) :
Table - 3900.5
Chair - 1400.76
Television - 5400.87
Discount Applied: 10.0%
Total price: 9631.917000000001

Task 8
Design the Reader class in such a way so that the following code provides the expected
output.
● A reader will have a name, capacity to read and an array of books they are reading.
● The initial capacity of a reader will be 0. The initial name will be “New user”.
Driver Code Expected Output

public class Reader_tester { 1 ==========


public static void main(String[] args){ A new reader is created!
Reader r1 = new Reader(); A new reader is created!
Reader r2 = new Reader(); 2 ==========
Name: Messi
System.out.println("1 =========="); Capacity: 2
System.out.println(r1.createReader("Messi", 2)); Books:
System.out.println(r2.createReader("Ronaldo", 3)); No books added yet
3 ==========
System.out.println("2 =========="); Name: Ronaldo
r1.readerInfo(); Capacity: 3
Books:
System.out.println("3 =========="); Book 1: Java
r2.addBook("Java"); Book 2: Python
r2.addBook("Python"); Book 3: C++
r2.addBook("C++"); 4 ==========
r2.readerInfo(); No more capacity
5 ==========
System.out.println("4 =========="); No more capacity
r1.addBook("C#"); 6 ==========
r1.addBook("Rust"); Name: Messi
r1.addBook("GoLang"); Capacity: 2
Books:
System.out.println("5 =========="); Book 1: C#
r2.addBook("Python"); Book 2: Rust

System.out.println("6 ==========");
r1.readerInfo();
}
}

Task 9

1 public class Task9 {


2 public int temp = 4;
3 public int sum;
4 public int y;
5 public int x;
6 public void methodA(int m){
7 int [] n = {2,5};
8 int x = 0;
9 y = y + m + this.methodB(x,m++)+(temp)+y;
10 x = this.x + 2 + (++n[0]);
11 sum = sum + x + y;
12 n[0] = sum + 2;
13 System.out.println(n[0] + x + " " + y+ " " + sum);
14 }
15 public int methodB(int m, int n){
16 int [] y = {1};
17 this.y = y[0] + this.y + m;
18 x = this.y + 2 + temp - n;
19 sum = x + y[0] + this.sum;
20 System.out.println(y[0]+ x + " " + y[0] + " " +sum);
21 return y[0];
22 }
23 }

public class Tester9 { Outputs


public static void main(String [] args){
Task9 t1 = new Task9();
t1.methodA(5);
t1.methodA(3);
Task9 t2 = new Task9();
t2.methodA(4);
}
}

Task 10

1 public class Maze{

2 public int x;

3 public void methodA(){

4 int m = 0, x = 9;

5 m = methodB(m-3)+x;

6 this.x = ++x;

7 System.out.println(this.x+" "+m);

8 methodB(x,m);

9 System.out.println(x+" "+(m+this.x));

10 methodB(m);

11 }

12 public int methodB(int y){

13 x=y*y;

14 System.out.println(x+" "+y);

15 return x-11;

16 }

17 public void methodB(int z, int x){

18 z=z-2;

19 x=this.x-2*x;

20 System.out.println(z+" "+this.x);
21 }

22 }

DRIVER CODE OUTPUTS

public class MazeTester{


public static void main(String args []){
Maze m1 = new Maze();
m1.methodA();
}
}

Task 11

1 public class Test11 {


2 int x = 2, y = 4, z = 5;
3 double p = 0.0;
4 public void methodA(int x, int m) {
5 this.x = methodC(this.x);
6 p = x + this.x % m * 3.0;
7 y = y + methodB(x++, this.x);
8 System.out.println(this.x +" " + x + y + " " + p) ;
9 }
10 public int methodB(int q, int n) {
11 int arr[] = {3,4,5};
12 arr[0] = arr[0] + this.x + n;
13 arr[1] = q + arr[1];
14 System.out.println(arr[0] +" " + arr[1] + " " + arr[2]) ;
15 return arr[1] + arr[2];
16 }
17 public int methodC(int y) {
18 if(y % 2 == 0) {
19 int temp = methodB(2, y);
20 return temp;
21 }
22 else{
23 return 4;
24 }
25 }
26 }

Driver Code Output


public class Tester11 {
public static void main(String [] args){
Task11 t1 = new Task11();
t1.methodA(2,3);
t1.methodB(5,4);
}
}
Ungraded Tasks (Optional)
(You don’t have to submit the ungraded tasks)

Task 1
You are building a tracker system that will keep track of a person’s income and expenses.
● When the createTracker() method is invoked it sets the balance to 1.0 taka.
● The info() method returns a String with the trackers information.
● If the total balance becomes 0 after the expense() method is called it prints
“You’re broke!” . Again if the available balance is less than the expense it prints
“Not enough balance.”. Otherwise the method prints “Balance updated” after
updating the balance.
● The last expense and income history can be seen by using the history() method.
Driver Code Output

public class Tester4{ Name: null


public static void main(String[] args) { Current Balance: 0.0
MoneyTracker tr1 = new MoneyTracker(); 1 ==========
System.out.println(tr1.info()); Name: John
tr1.createTracker("John"); Current Balance: 1.0
2 ==========
System.out.println("1 ==========");
Balance Updated!
System.out.println(tr1.info()); Name: John
System.out.println("2 =========="); Current Balance: 1001.0
tr1.income(1000); 3 ==========
System.out.println(tr1.info()); Balance Updated.
System.out.println("3 =========="); Balance Updated.
tr1.expense(800); Name: John
tr1.expense(100); Current Balance: 101.0
System.out.println(tr1.info()); 4 ==========
System.out.println("4 =========="); Last added: 1000.0
Last spent: 100.0
tr1.showHistory();
5 ==========
System.out.println("5 =========="); You're broke!
tr1.expense(101); 6 ==========
System.out.println("6 =========="); Not enough balance.
tr1.expense(200); 7 ==========
System.out.println("7 =========="); Balance Updated!
tr1.income(200); Last added: 200.0
tr1.showHistory(); Last spent: 100.0
System.out.println("8 =========="); 8 ==========
}
}
Task 2

1 public class Test2 {

2 int x = 3, y = 1, z = -4;

3 double p = 2.5;

4 public void methodA(int n, int x) {

5 this.x = methodB(x, n);

6 p = this.x + n % x * 2.0;

7 y = (z++) + methodB(z, (int) p) + (++z);

8 System.out.println(this.x + " " + (n + y) + " " + (x + z)) ;

9 }

10 public int methodB(int q, int n) {

11 int arr[] = {2, -5, 6};

12 arr[0] = arr[2] - this.x + n;

13 arr[1] = q - arr[1];

14 arr[2] = arr[q % 3] + arr[n % 2];

15 System.out.println(arr[0] + " " + arr[1] + " " + arr[2]) ;

16 return arr[1] + arr[2] - arr[0];

17 }

18 }

public class Tester2{ Outputs


public static void main(String [] args){
Test2 t = new Test2();
t.methodA(3, 4);
}
}
Task 3

1 public class Test3 {

2 int x = 2, y = 4, sum = 3;

3 int arr[] = {x, y, sum};

4 public void methodA(int x) {

5 arr[0] += methodB(y, this.x) + methodC(x);

6 System.out.println(x + " " + this.x + " " + sum);

7 arr[1] += this.x * (++y) / (sum % x);

8 System.out.println(y + " " + sum + " " + this.x);

9 arr[2] += methodC(x) + methodB(this.x, sum);

10 System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);

11 }

12 public int methodB(int q, int n) {

13 int arr2[] = {7, 8};

14 int a = (arr2[0]++) - q;

15 int b = (++arr2[1]) - n;

16 return a + b;

17 }

18 public int methodC(int z) {

19 z = sum + methodB(x, sum) - z;

20 return z/2;

21 }

22 }
public class Tester3{ Outputs
public static void main(String [] args){
Test3 t3 = new Test3();
t3.methodA(7);
}
}

Task 4

Driver Code Output

public class CustomerTester { 1=====================


public static void main(String[] args) { Customer: John
Customer c1 = new Customer(); 2=====================
c1.createCustomer("John"); Apple added to cart
System.out.println("1====================="); Orange added to cart
c1.showCart(); Bread added to cart
System.out.println("2====================="); Milk added to cart
c1.addItem("Apple", 2); Cart is full
c1.addItem("Orange", 5); 3=====================
c1.addItem("Bread", 5); Customer: John
c1.addItem("Milk", 3); Item: Apple Price: 2
c1.addItem("Eggs", 2); Item: Orange Price: 5
System.out.println("3====================="); Item: Bread Price: 5
c1.showCart(); Item: Milk Price: 3
System.out.println("4====================="); 4=====================
c1.calculatePrice(); Total: 15
System.out.println("5====================="); 5=====================
Customer c2 = new Customer(); Apple and Orange added to cart
c2.createCustomer("Jane"); Chocolates and Bread added to cart
c2.addItem("Apple", 2, "Orange", 5); Cart is full
c2.addItem("Chocolates", 15, "Bread", 5); 6=====================
c2.addItem("Milk", 3); Customer: Jane
System.out.println("6====================="); Item: Apple Price: 2
c2.showCart(); Item: Orange Price: 5
System.out.println("7====================="); Item: Chocolates Price: 15
c2.calculatePrice(); Item: Bread Price: 5
} 7=====================
} Total: 27

Task 5
Driver Code Sample Output

public class CalculatorTester { 1=============


public static void main(String[] args) { 30
Calculator calc = new Calculator(); 2=============
45
System.out.println("1============="); 3=============
calc.add(10, 20); 42
System.out.println("2============="); 4=============
calc.add(5, 15, 25); 24
System.out.println("3============="); 5=============
calc.multiply(6, 7); Hello-Hello-Hello
System.out.println("4============="); 6=============
calc.multiply(2, 3, 4); Java-Java-Java-Java-Java
System.out.println("5=============");
calc.multiply("Hello", 3);
System.out.println("6=============");
calc.multiply("Java", 5);
}
}

Task 6

Driver Code Sample Output

public class LibraryTest { |---Book Customization---|


public static void main(String[] args) { Updated genre of "The Great Gatsby" to
Classic.
Book book1 = new Book(); Updated pages of "The Great Gatsby" to
book1.createBook("The Great Gatsby"); 180 pages.
Updated genre of "1984" to Dystopian.
Book book2 = new Book(); Updated pages of "1984" to 328 pages.
book2.createBook("1984", "George Orwell"); Updated pages of "To Kill a
Mockingbird" to 281 pages.
Book book3 = new Book();
book3.createBook("To Kill a Mockingbird", "Harper |---Library Inventory---|
Lee", "Fiction"); Title: The Great Gatsby, Author:
Unknown, Genre: Classic, Pages: 180
System.out.println("|---Book Customization---|"); Title: 1984, Author: George Orwell,
book1.customizeGenre("Classic"); Genre: Dystopian, Pages: 328
book1.customizePages(180); Title: To Kill a Mockingbird, Author:
Harper Lee, Genre: Fiction, Pages: 281
book2.customizeGenre("Dystopian");
book2.customizePages(328);

book3.customizePages(281);

System.out.println();

System.out.println("|---Library Inventory---|");
book1.displayDetails();
book2.displayDetails();
book3.displayDetails();
}
}

Task 7

Driver Code Sample Output

public class MovieManagerTest { 1====================


public static void main(String[] args) { Added actor "Leonardo DiCaprio" to
Movie inception = new Movie(); "Inception".
inception.setMovieDetails("Inception", "Christopher Nolan", Added actor "Joseph Gordon-Levitt" to
8.8); "Inception".
Added actor "Ellen Page" to
System.out.println("1===================="); "Inception".
inception.addActors("Leonardo DiCaprio", "Joseph Title: Inception
Gordon-Levitt"); Director: Christopher Nolan
inception.addActors("Ellen Page"); Rating: 8.8
inception.showInfo(); Actors: Leonardo DiCaprio, Joseph
Gordon-Levitt, Ellen Page
System.out.println("2===================="); 2====================
Movie avengers = new Movie(); Added actor "Robert Downey Jr." to
avengers.setMovieDetails("Avengers: Endgame", "Anthony "Avengers: Endgame".
Russo", 8.4); Added actor "Chris Evans" to
avengers.addActors("Robert Downey Jr.", "Chris Evans", "Avengers: Endgame".
"Scarlett Johansson"); Added actor "Scarlett Johansson" to
avengers.showInfo(); "Avengers: Endgame".
Title: Avengers: Endgame
System.out.println("3===================="); Director: Anthony Russo
Movie parasite = new Movie(); Rating: 8.4
parasite.setMovieDetails("Parasite", "Bong Joon-ho"); Actors: Robert Downey Jr., Chris
parasite.addActors("Song Kang-ho", "Choi Woo-shik"); Evans, Scarlett Johansson
parasite.updateRating(8.6); 3====================
parasite.showInfo(); Added actor "Song Kang-ho" to
"Parasite".
System.out.println("4===================="); Added actor "Choi Woo-shik" to
parasite.updateRating(8.9); "Parasite".
parasite.showInfo(); Updated rating of "Parasite" to 8.6
} Title: Parasite
} Director: Bong Joon-ho
Rating: 8.6
Actors: Song Kang-ho, Choi Woo-shik
4====================
Updated rating of "Parasite" to 8.9
Title: Parasite
Director: Bong Joon-ho
Rating: 8.9
Actors: Song Kang-ho, Choi Woo-shik
Task 8

Design the Course class with the necessary properties so that the
given output is produced for the provided driver code.

Driver Class Output

public class CourseTester2{ --------1--------


public static void main(String [] args){ Course details:
Course c1 = new Course(); Course Name: PL II
c1.updateDetails("PL II", "CS11"); Course Code: CS11
System.out.println("--------1--------"); Course Syllabus:
c1.printDetails(); No content yet.
System.out.println("--------2--------"); --------2--------
c1.addContent("Overloading"); Overloading was added.
c1.printDetails(); Course details:
System.out.println("--------3--------"); Course Name: PL II
c1.addContent("Encapsulation"); Course Code: CS11
c1.addContent("Static", "Polymorphism"); Course Syllabus:
c1.printDetails(); Overloading
System.out.println("--------4--------"); --------3--------
c1.addContent("Inheritance"); Encapsulation was added.
System.out.println("--------5--------"); Static was added.
Course c2 = new Course(); Polymorphism was added.
c2.updateDetails("DS", "CS22"); Course details:
c2.addContent("Stack"); Course Name: PL II
c2.addContent("Recursion","Tree"); Course Code: CS11
c2.addContent("Heap","Hashing"); Course Syllabus:
System.out.println("--------6--------"); Overloading, Encapsulation, Static,
c2.printDetails(); Polymorphism
} --------4--------
} Cannot add more content
--------5--------
Stack was added.
Recursion was added.
Tree was added.
Heap was added.
Cannot add more content
--------6--------
Course details:
Course Name: DS
Course Code: CS22
Course Syllabus:
Stack, Recursion, Tree, Heap

You might also like