0% found this document useful (0 votes)
0 views3 pages

301 Assignment

The document contains Java code examples demonstrating the use of visitor design patterns, container classes, and data structures. It includes implementations for printing cubes of integers, course registration, and transferring courses from a stack to a queue. Each example showcases object-oriented programming principles and the manipulation of custom data structures.

Uploaded by

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

301 Assignment

The document contains Java code examples demonstrating the use of visitor design patterns, container classes, and data structures. It includes implementations for printing cubes of integers, course registration, and transferring courses from a stack to a queue. Each example showcases object-oriented programming principles and the manipulation of custom data structures.

Uploaded by

mustaphaasalam7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q1a

public class CubePrinterVisitor implements MyContainerVisitor {

@Override

public void visit(MyContainer container) {

for (Object item : [Link]()) {

if (item instanceof Integer) {

int cube = (int) [Link]((int) item, 3);

[Link](cube);

[Link]

public class Main {

public static void main(String[] args) {

MyContainer myContainer = new MyContainer();

[Link](2);

[Link](3);

[Link](4);

CubePrinterVisitor cubePrinterVisitor = new CubePrinterVisitor();

[Link](cubePrinterVisitor);

1b.
public class TestMyCubePrinterVisitor {

public static void main(String[] args) {

// Create a MyContainer instance and add even numbers between 0 and 20

MyContainer myContainer = new MyContainer();

for (int i = 0; i <= 20; i += 2) {

[Link](i);

// Create a CubePrinterVisitor instance and visit the MyContainer instance

CubePrinterVisitor cubePrinterVisitor = new CubePrinterVisitor();

[Link](cubePrinterVisitor);

Q2

public class TestCourseRegistration {

public static void main(String[] args) {

// Create a MySearchableContainer instance called registeredCourses

MySearchableContainer<Course> registeredCourses = new MySearchableContainer<>();

// Insert three courses into the registeredCourses container

[Link](new Course("CSC101", 3));

[Link](new Course("PHY101", 4));

[Link](new Course("MAT101", 3));

// Create a Student instance and an Association object to associate the student with the
registeredCourses

Student student = new Student("2021001");


Association<Student, MySearchableContainer<Course>> association = new Association<>(student,
registeredCourses);

Q4.

public class TestStackAsLinkedList {

public static void main(String[] args) {

StackAsLinkedList stack = new StackAsLinkedList();

[Link](new Course("CSC101", 3));

[Link](new Course("PHY102", 4));

[Link](new Course("MAT205", 3));

QueueAsLinkedList queue = new QueueAsLinkedList();

while(![Link]()) {

Course course = (Course) [Link]();

[Link]([Link]());

[Link]("Courses in Queue:");

while(![Link]()) {

[Link]([Link]());

You might also like