Week 6 Practice Questions
Week 6 Practice Questions
Paradigm
1. Packages
Q1: You are working on a Java project for a software company that
specializes in data analysis tools. Your task is to implement two common
sorting algorithms—Bubble Sort and Selection Sort.
Create two different packages:
bubblesort: This package will contain the implementation of the Bubble
Sort algorithm.
selectionsort: This package will contain the implementation of the
Selection Sort algorithm.
Create a main class:
SortTest: This class will demonstrate the use of both sorting algorithms. It
should import the necessary classes from the bubblesort and
selectionsort packages and provide methods to sort an array using both
Bubble Sort and Selection Sort.
2.Single Thread
Q1: You are developing a simple task processing system where a list of tasks
needs to be processed sequentially. Each task involves performing a calculation,
such as squaring a number, and then generating a report based on these results.
Create an application so that all tasks will be processed one after the other in a
single thread.
Q2: You are developing a monitoring system for a network service that
periodically checks the status of the service. To simulate this, you need to create
a Java program that does the following:
• Simulate a Network Check: The system will run a task that simulates a
network check, which involves putting the thread to sleep for a certain
period.
• Thread Management: After the sleep period, the thread should change its
name to reflect its updated status or role.
3.Multi Thread
Q1: Write a program that implements a multi-thread application that has three
threads. First thread generates random integer every 1 second and if the value
is even, second thread computes the square of the number and prints. If the
value is odd, the third thread will print the value of cube of the number.
Q2: Imagine you are developing a simulation for a coffee shop where a barista
(producer) makes coffee, and a customer (consumer) buys and consumes the
coffee. The system must ensure that the customer can only consume a coffee
after it has been produced. The barista should wait until the customer has
consumed the coffee before making the next cup. Use threads for producer and
consumer.