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

Lab 2 Oop

This document is the lab manual for the Object Oriented Programming course CSL-210 at Bahria University in Pakistan. It contains details for 6 exercises to be completed by the student, including prompts for programs to write involving sales calculation, wind chill calculation, loan eligibility checking, color conversion, a number guessing game, and calculations for pulley systems. The student is Ayesha Tahir in the BS(IT)2-A program for the fall 2024 semester.

Uploaded by

shoaib tahir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lab 2 Oop

This document is the lab manual for the Object Oriented Programming course CSL-210 at Bahria University in Pakistan. It contains details for 6 exercises to be completed by the student, including prompts for programs to write involving sales calculation, wind chill calculation, loan eligibility checking, color conversion, a number guessing game, and calculations for pulley systems. The student is Ayesha Tahir in the BS(IT)2-A program for the fall 2024 semester.

Uploaded by

shoaib tahir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

OBJECT ORIENTED PROGRAMMING

(3+1 Credit Hours)

CSL-210
LAB MANUAL

DEPARTMENT OF COMPUTER SCIENCE

BAHRIA UNIVERSITY, KARACHI, PAKISTAN


OBJECT ORIENTED PROGRAMMING
CSL-210
(Spring-2024)

Student Name: Ayesha Tahir

Registration Number: 02-235232-020

Class & Section: BS(IT)2-A


Year: FALL-2024

Lab Day & Timing: Tuesday 8:30 to 11:30


Exercise 1: Suppose you are part of a team running a TCS Boxes manufacturing business.
Your team produces quality boxes in batches, and you're responsible for managing the inventory
and sales. Your task is to develop a Java program called TCS Boxes Sales Calculator that takes
the total number of boxes produced as input and calculates the following:
• The number of full boxes sold at the regular price of $1.14 each.
• The number of cartons sold.
• The number of leftover boxes sold at the discounted price of 57¢ each.
• The total revenue generated from the sales.
Write a Java program that implements given scenario.

SOURCE CODE:
OUTPUT:

Exercise 2: You're developing a weather application in Java for outdoor enthusiasts, and
you want to incorporate a feature that calculates the wind chill factor. Users can input the
current temperature (`t`) in Fahrenheit and the wind speed (`v`) in miles per hour, and your
program will calculate the wind chill accordingly.
w = 35.74 - (0.6215 * 20) + ((0.4275 * 20) - 35.75) * 15^0.16
Now, let's break it down:
t = 20°F (temperature)
v = 15 mph (wind speed)
Write a program that takes two double command-line arguments t and v and prints out the wind
chill. Use Math pow(a, b) to compute ab.
(Note: The formula is not valid if t is larger than 50 in absolute value or if v is larger than 120 or
less than 3 (you may assume that the values you get are in that range)).
SOURCE CODE:

OUTPUT:
Exercise 3: Imagine you're developing a budgeting application for a personal finance
company. One feature of the application is to help users determine their eligibility for a loan
based on their income and expenses.
You're tasked with implementing a loan eligibility checker in a Java program. The program
should prompt users to input their monthly income and total monthly expenses. Based on these
inputs, the program will determine whether the user is eligible for a loan.
The eligibility criteria are as follows:
- To be eligible for a loan, the user's monthly income should be at least three times their total
monthly expenses.
- Additionally, the user's monthly income should be greater than $1,000.
If the user meets both criteria, the program should display a message indicating that they are
eligible for a loan. Otherwise, it should display a message stating that they are not eligible.
Based on this scenario, write a Java program that implements this loan eligibility checker. Use
arithmetic operations and conditional statements to determine eligibility based on the user's
input.

SOURCE CODE:
OUTPUT:

Exercise 4: Your part of a team developing a mobile app for photography enthusiasts. One
feature of the app is a tool that allows users to analyze and convert colors between different
formats.
Imagine you're tasked with implementing a color conversion feature that converts colors from the
RGB format (used in digital cameras and web pages) to the CMYK format (used in printing).
Your task is to write a Java program called RGBtoCMYK that takes three integers representing
the levels of red (R), green (G), and blue (B) respectively, and converts them to equivalent
CMYK values. The CMYK format specifies the levels of cyan (C), magenta (M), yellow (Y),
and black (K) on a scale from 0.0 to 1.0.
Your program should handle edge cases such as when all RGB values are 0, in which case the
CMY values should be 0 and the K value should be 1. Otherwise, it should use the provided
formulas to calculate the CMYK values based on the RGB inputs.
SOURCE CODE:
OUTPUT:
Exercise 5: You're developing a number guessing game in Java for a coding
workshop. The game challenges players to guess a randomly generated number
within a specified range. Here's how it works:
The program generates a random number between a lower and upper bound,
inclusive.
The player is prompted to guess the number.
If the player's guess is within a certain threshold (let's say ±5) of the random
number, the program displays a message like "Well done! You're close!".
Otherwise, the program displays a message indicating whether the guess was too
high or too low.
The game continues until the player guesses the correct number or decides to quit.
Your task is to write a Java program called `NumberGuessingGame` that
implements this game logic. The program should prompt the player to input the
lower and upper bounds for the range of numbers to guess from, as well as the
number of rounds they want to play. Then, for each round, it should generate a
random number within the specified range, prompt the player to guess the number,
and provide feedback based on the rules described above. After each guess, the
program should indicate whether the guess was correct or not, and if not, whether it
was too high or too low.
SOURCE CODE:
OUTPUT:

Exercise 6: Imagine you are part of a team developing a robotics project for a high school
science fair. Your project involves building a robotic arm capable of lifting objects using a pulley
system. Your team decides to organize a workshop for fellow students interested in robotics and
engineering. During the workshop, you introduce them to the concept of pulley systems and
demonstrate how they can be used to lift heavy objects with minimal effort. In this regard, show
the team how this all works by:

calculate the speed of one pulley if there are 2 pulleys connected with a belt:
RPM2 = diameter1/diameter2 * RPM1
calculate the amount of weight that can be lifted with a multiple pulley
system: weight lifted = force exerted * number of up ropes
SOURCE CODE:
OUTPUT:

You might also like