0% found this document useful (0 votes)
17 views

Week 6 Practice Questions

app week assignment

Uploaded by

pk6048
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)
17 views

Week 6 Practice Questions

app week assignment

Uploaded by

pk6048
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/ 2

Week 6 Practice Questions - Object Oriented Programming

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.

Q2: You are part of a team developing a comprehensive arithmetic library


for a new software tool. Your task is to organize arithmetic functions into
different packages and then integrate them into a single class for usage.
Create separate packages for different arithmetic operations:
addition: This package will contain the functionality to perform addition.
subtraction: This package will handle subtraction operations.
multiplication: This package will be responsible for multiplication
functions.
division: This package will include functions for division operations.
Integrate and test the functions:
Create a main class:
Class Name: ArithmeticOperations
o This class should import the classes from the addition, subtraction,
multiplication, and division packages. Implement methods to utilize
the functions from each package and perform various arithmetic
operations. Test the integrated functionality by calling these
methods with sample inputs and displaying the results.

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.

You might also like