Fundamentals of Operating Systems and Java Programming

Verified

Added on  2024/04/26

|14
|857
|463
AI Summary
This course covers the fundamentals of operating systems and Java programming. It includes algorithms, source code, and output screenshots for tasks related to floor selection and NIM game. Learn to develop efficient programs.

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Fundamentals of Operating Systems and
Java Programming
1

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
Contents
Task 1:..............................................................................................................................................................3
Algorithm:....................................................................................................................................................3
Source code:.................................................................................................................................................4
Screenshots of the output:...........................................................................................................................6
Task 2...............................................................................................................................................................8
Algorithm:....................................................................................................................................................8
Coding screenshots:.....................................................................................................................................9
NIM game output:......................................................................................................................................12
Output after Adding input validation to your Nim program.......................................................................13
References......................................................................................................................................................14
List of Figures
Figure 1 Source code........................................................................................................................................4
Figure 2 welcome message with menu system................................................................................................6
Figure 3: error message for invalid selection....................................................................................................6
Figure 4 for fire alarm selection........................................................................................................................6
Figure 5 invalid floor selection..........................................................................................................................6
Figure 6 for floor number 15............................................................................................................................7
Figure 7 floor number 10 selection...................................................................................................................7
Figure 8 select fire alarm choice after 10-floor selection.................................................................................7
Figure 9 quit the system...................................................................................................................................7
Figure 10 source code screenshots...................................................................................................................9
Figure 11 NIM game output...........................................................................................................................12
Figure 12 Output after Adding input validation to your NIM program...........................................................13
2
Document Page
Task 1:
Algorithm:
The algorithm describes the logic to solve a program [1]. The algorithm for the task 1 is shown below:
Step 1: Start the program
Step2: Print a welcome message
Step3: print menu system with “s/f/q” choice. ‘s' for the select floor, ‘f' for select fire alarm and ‘q' for quit
the system[3].
Step 4: Ask user to enter a choice
4.1 If user select choice‘s’ then ask user to enter the floor number
4.1.1. if floor number <1 and floor number >100 then print an error message
4.1.2 A. if current floor number is less than previously enter floor number then
Take lift in down direct up to entered floor number
B. else take lift in upward direction up to entered floor number
4.2. if user select choice ’f’ then
4.2.1 check lift is on which floor if it is not on the ground floor then take the lift down to the ground
floor and print a dangerous message.
4.2.2. else print a dangerous message.
4.3 if user select ‘q’ choice then exit the system.
Step 5: end the program
3
Document Page
Source code:
Figure 1 Source code
4

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
5
Document Page
Screenshots of the output:
Figure 2 welcome message with menu system
Figure 3: error message for invalid selection
Figure 4 for fire alarm selection
Figure 5 invalid floor selection
6
Document Page
Figure 6 for floor number 15
Figure 7 floor number 10 selection
Figure 8 select fire alarm choice after 10-floor selection
Figure 9 quit the system
7

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Task 2
Algorithm:
Step1: start the program
Step 2: print N I M game welcome message
Step3: Ask user to enter the number of starting stones
3.1. if stones< 1 print error message and go to step 3
Step4: (A) Ask user whether he wants to go first or not
4.1.1. if yes ask the user to enter how many stones he wants to remove 1 or 2
4.1.1.1. if choice=1 remove one stone
4.1.1.2 if choice=2 remove 2 stones
a. if remaining stone < 0 generate an error message and add 2 stones that were
removed.
b. else repeat 4.1.1
4.1.2. print number of stones left.
4.1.2.1. if stones==0 print “computer wins” message
4.1.3. ask the user whether he wants to play again or not
a. if yes go to step 3
b. exit the system
(B) 4.1.1. Calculate remainder by dividing number of stones by 3
a. if remain ==0 remove 2 stones and print a message that shows “The computer removes 2
stones”
b. else removes 1 stones and print a message that shows “The computer removes 1 stones”
4.1.2. Print number of stones left.
a. if stones==0 print computer wins message
Ask user whether he wants to play again or not if yes go to step 3 else exit the system.
Step 5: END the program
8
Document Page
Coding screenshots:
Figure 10 source code screenshots
9
Document Page
10

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
11
Document Page
NIM game output:
Figure 11 NIM game output
12
Document Page
Output after Adding input validation to your Nim program
Figure 12 Output after Adding input validation to your NIM program
13

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
References
[1] J. Friesen, "Java 101: Datastructures and algorithms in Java, Part 1", JavaWorld, 2017. [Online].
Available: https://www.javaworld.com/article/3215112/learn-java/java-101-datastructures-and-
algorithms-in-java-part-1.html. [Accessed: 27- Jan- 2018].
[2] "Methods in Java - GeeksforGeeks", GeeksforGeeks, 2018. [Online]. Available:
https://www.geeksforgeeks.org/methods-in-java/. [Accessed: 27- Jan- 2018].
[3] "JAVA: code for menu selection using Scanner class", DaniWeb, 2018. [Online]. Available:
https://www.daniweb.com/programming/software-development/threads/13786/java-code-for-menu-
selection-using-scanner-class. [Accessed: 27- Jan- 2018].
14
1 out of 14
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]