[go: up one dir, main page]

0% found this document useful (0 votes)
14 views2 pages

Assignment4 - Core Java

The document outlines assignments completed by Abhay Chauhan in the Java Full Stack module, focusing on pseudocode, flowcharts, modular function design, and bubble sort. Each assignment includes objectives, pseudocode or flow logic, and key concepts used. The assignments emphasize conditional logic, looping constructs, and modular programming practices.

Uploaded by

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

Assignment4 - Core Java

The document outlines assignments completed by Abhay Chauhan in the Java Full Stack module, focusing on pseudocode, flowcharts, modular function design, and bubble sort. Each assignment includes objectives, pseudocode or flow logic, and key concepts used. The assignments emphasize conditional logic, looping constructs, and modular programming practices.

Uploaded by

Abhay Chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME - ABHAY CHAUHAN

ID - 31160
BATCH - JAVA FULL STACK
MODULE - Core Java Programming

Assignment 1: Pseudocode – Even/Odd Logic with Loop and Conditions


Ans.
Objective:
Design a pseudocode that reads an integer input, checks if it’s even or odd, and
processes it accordingly. If even, compute the square; if odd, compute the cube.
Use conditional and looping constructs to handle multiple inputs until the user
enters 0.

Pseudocode:
START
LOOPssss
PROMPT user to enter a number (0 to exit)
READ number
IF number == 0 THEN
BREAK the loop
IF number % 2 == 0 THEN
result = number * number
PRINT "Even number. Square is", result
ELSE
result = number * number * number
PRINT "Odd number. Cube is", result
END LOOP
END

Concepts Used
Conditional Logic (if-else)
Looping (while/repeat structure)

Assignment 2: Flowchart – User Login System with Attempt Limit


ans.
Objective:
Model a secure login flow using a flowchart. The system should allow the user up to
3 attempts to input correct credentials. If login fails in all attempts, the
account is locked. If login is successful, access is granted.

Flow Logic (Textual Representation)


START
→ Initialize attempt = 0
→ LOOP while attempt < 3
→ Prompt for username and password
→ IF credentials are valid:
→ Display "Login Successful"
→ EXIT
→ ELSE:
→ Display "Login Failed"
→ Increment attempt
→ IF attempt == 3
→ Display "Account Locked"
END

Key Elements
Decision-making (valid/invalid credentials)
Attempt counter to restrict retries
Looping construct for retry mechanism
Assignment 3: Modular Function Design – Number Processing
ans.
Objective
Create modular functions to handle the logic from Assignment 1 by separating the
processing and display responsibilities into individual functions.

Function 1: processNumber(int number)


FUNCTION processNumber(number):
IF number % 2 == 0 THEN
RETURN number * number
ELSE
RETURN number * number * number
END FUNCTION

Function 2: displayResult(int number, int result)


FUNCTION displayResult(number, result):
IF number % 2 == 0 THEN
PRINT "Square of", number, "is", result
ELSE
PRINT "Cube of", number, "is", result
END FUNCTION

These functions support modularization and maintain separation of concerns, which


is a good practice in real-world software design.

Assignment 4: Bubble Sort – Pseudocode, Flow, and Dry Run


ans.
Objective:
Develop a sorting routine using bubble sort. Represent its logic via pseudocode and
explain it with a dry run.

Bubble Sort Pseudocode:


START
INPUT array A of size n
FOR i = 0 to n-1
FOR j = 0 to n-i-2
IF A[j] > A[j+1] THEN
SWAP A[j], A[j+1]
OUTPUT sorted array A
END

How It Works:
The largest element "bubbles up" to the end after each inner loop.
Repeats until the array is sorted.
Worst-case time complexity: O(n²), best case: O(n) with optimization.

You might also like