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

Assign 02 PF

This document outlines the assignment for the Programming Fundamentals course at the University of Central Punjab, focusing on problem-solving techniques in Java. It includes instructions for submission, deadlines, and details on four programming questions related to security systems, order status, seal validation, and ticket booking. Each question requires the implementation of specific functions without using arrays or strings, emphasizing validation and logical criteria.

Uploaded by

Ali Baba
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)
2 views

Assign 02 PF

This document outlines the assignment for the Programming Fundamentals course at the University of Central Punjab, focusing on problem-solving techniques in Java. It includes instructions for submission, deadlines, and details on four programming questions related to security systems, order status, seal validation, and ticket booking. Each question requires the implementation of specific functions without using arrays or strings, emphasizing validation and logical criteria.

Uploaded by

Ali Baba
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
You are on page 1/ 4

University of Central Punjab

Faculty of Information Technology and Computer Science

Course Title: Programming Fundamentals


Course Code: CP113

Assignment 02
Name: _______________________________

Registration Number: ___________________

Section: ______________________________

CLO # Course Learning Outcome (CLO) Taxonomy Mapping


Level to PLO

CLO 2 Understand and apply efficient problem-solving C3 P2


techniques including divide and conquer and memory
optimization in Java.

Instructions:
1. Attempt all questions.
2. You can attempt the implementation on any Java compiler but have to submit the
assignment in handwritten form also on Odoo (attach all .java files)
3. The assignment should be submitted on A4 sheets or Assignment sheets only.
Violation will result in a deduction of 1 mark from the scored marks.
4. Each student must attach this front page to his/her assignment. Violation will result in
a deduction of 1 mark from the scored marks.
5. The Due Date for the Assignment on the portal is 29th April, 2025, and the hardcopy
submission deadline will be in the coming class right after 29 th April, 2025.
6. Late submission will result in a 10% deduction in marks.
7. No request for late submissions will be considered this time.
University of Central Punjab
Faculty of Information Technology and Computer Science
Question 01 : Marks: 10
You are working with a tech company that specializes in smart building automation systems.
One of their products is an intelligent elevator system designed to enhance security in
corporate buildings. This system grants access to floors only if a user enters a valid 3-digit
access code that meets specific logic-based criteria.

As a developer, your task is to design and implement a secure validation mechanism using
functions only (no arrays or strings allowed). You must write a program that asks the user for a
3-digit code and evaluates its validity based on the following rules:

Rules:
1. The code must consist of exactly three digits (e.g., 123, 741).
2. The digits must be either in strictly ascending (e.g., 257) or descending (e.g., 841)
order.
3. The middle digit (2nd digit) must be a prime number (2, 3, 5, or 7).
4. The product of all three digits must not exceed 100.

If the code satisfies all of the above rules, access is granted. Otherwise, the system will display
"Access Denied".

Functions to Implement:
1. int readAccessCode()
Prompts the user to enter a 3-digit code. Validates the input to ensure it is
between 100 and 999. Re-prompts if invalid.
2. int extractDigit(int number, int position)
Extracts a digit from the number based on position:
1. 1 = Hundreds (leftmost)
2. 2 = Tens (middle)
3. 3 = Units (rightmost)
3. boolean isPrime(int n)
Returns true if the given digit is a prime number (2, 3, 5, 7); otherwise, false.
4. boolean isAscending(int code)
Returns true if the digits are in strictly ascending order.
5. boolean isDescending(int code)
Returns true if the digits are in strictly descending order.
6. boolean isAccessGranted(int code)
Coordinates the validation by calling the appropriate functions to verify all rules.
7. void showAccessStatus(boolean access)
Displays a message based on the final result:
1. "Access Granted. Welcome!"
2. "Access Denied. Invalid Code."

Note: Do not use array or string datatype


University of Central Punjab
Faculty of Information Technology and Computer Science
Question 02 : Marks: 10
The Middletown Wholesale Copper Wire Company sells spools of copper wiring for $100 each.
Design a program that displays the status of an order. The program should have a function that
asks for the following data:

• The number of spools ordered.


• The number of spools in stock.
• Whether there are special shipping and handling charges.

(Shipping and handling are normally $10 per spool.) If there are special charges, the program
should ask for the special charges per spool.
The gathered data should be passed as arguments to another function that displays

• The number of spools ready to ship from current stock.


• The number of spools on back order (if the number ordered is greater than what is in stock).
• Subtotal of the portion ready to ship (the number of spools ready to ship times $100).
• Total shipping and handling charges on the portion ready to ship.
• Total of the orders ready to ship.

The shipping and handling parameter in the second function should have the default argument
10.00.

Input Validation: Do not accept numbers less than 1 for spools ordered. Do not accept a number
less than 0 for spools in stock or shipping and handling charges.

Question 03: Marks: 10


You are tasked with designing a security system for a hidden chamber that only opens when a
secret 3-character seal is validated based on a series of ancient rules. The first character of the
seal must be an uppercase consonant, ensuring that only valid uppercase letters which are not
vowels (A, E, I, O, U) are accepted. The second character must be a digit that is both even and
greater than 3, meaning it can only be the digits 4, 6, or 8. The third character must be a
lowercase vowel, restricting the choices to only the letters 'a', 'e', 'i', 'o', or 'u'. Once the
individual character checks pass, the final step requires the total ASCII value of the three
characters to be a prime number for the seal to be deemed valid. To determine the validity of
the seal, the program must evaluate each character against the specified rules using separate
functions and then calculate the total ASCII sum. After performing this final check, if all the
criteria are met, the system will grant access to the hidden chamber. If any rule is violated, the
chamber will remain locked. The system should also provide feedback to the user by printing
whether the seal is valid or invalid based on the checks performed. This task requires breaking
down the problem into manageable functions to validate each character's properties and
perform the necessary checks efficiently.
University of Central Punjab
Faculty of Information Technology and Computer Science
Note: Do not use array or string datatype or any built in functions

Question 04 : Marks: 10
A train ticket booking system offers a special discount to passengers whose seat number is
considered "lucky" based on specific criteria. A seat number is 3-digits only, and the luck
criteria are:

Lucky Seat Conditions:

1. The digits must form a palindrome (e.g., 141, 232).


2. The sum of the digits must be a prime number.
3. The middle digit must be greater than or equal to both the first and last digits.
4. The number must not be divisible by 11.

Required Functions:

1. int readSeatNumber()
Reads and validates that the seat number is a 3-digit number.
2. boolean isPalindrome(int number)
Returns true if the number is a 3-digit palindrome.
3. int digitSum(int number)
Returns the sum of digits of the number.
4. boolean isPrime(int n)
Returns true if the sum is a prime number.
5. boolean isMiddleDigitDominant(int number)
Checks if middle digit ≥ first and last.
6. boolean isDivisibleBy11(int number)
Returns false if divisible by 11.
7. boolean isLuckySeat(int number)
Checks all conditions.
8. void showSeatResult(boolean isLucky)
Prints "Lucky Seat! Discount Applied." or "Not Eligible."

Output Example:

 Seat: 232 → Palindrome , Sum = 7 , Mid = 3 ≥ 2,2 , Not div by 11 → Lucky


 Seat: 121 → Palindrome , Sum = 4 → Not Lucky

You might also like