Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave

This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements in them.

a.Apply principles of abstraction and problem solving in an object-oriented programming language

b.Apply knowledge of programming constructs in developing computer programs

c.Create programs based on incremental development processes of designing, coding, testing and debugging. 0% of the total assessments

Algorithm

START

  • Declare function main().
  • Display menu and take user input for choice.
  • Convert character input into uppercase.
  • In Case user choses ‘S’ goto next step else goto step 7.
  • Call function SelectFloor().
  • If function returns 1 call function Movement(), else goto step 2.
  • In Case user enters ‘F’, call function FireAlarm() and then goto step 2.
  • In Case user enters ‘Q’, display Exit message and goto step 10.
  • If user enters wrong choice, display error message and goto step 2.
  • End of function main().
  • Take user input of floors he wishes to travel in variable temp.
  • If tempInput <1 or tempInput>100, display error message. goto step 1.
  • If tempInput = currentFloor value, display “same floor error” message and return 0 to calling function, else next step.
  • Set floors to tempInput and return 1 to calling function.
  • End of function SelectFloor().
  • If currentFloor value > floors value, goto step 2 else goto step 7.
  • Display message “going down”
  • While currentFloor value is > or currentFloor= floors value then goto next step, else goto step 6.
  • Display currentFloor value.
  • Decrease currentFloor by 1, goto step 3.
  • Increase currentFloor value by 1, once. Goto step 12
  • Display message “going up”
  • While currentFloor value < or = floors value goto next step, else goto step 11.
  • Display currentFloor value.
  • Increase currentFloor by 1, goto step 8.
  • Decrease currentFloor value by 1, once. Goto step 12
  • End of function Movement().
  • Declare function FireAlarm().
  • Display danger message.
  • If currentFloor value is not 1 goto next step, else goto step 8.
  • Print “going down message”
  • While currentFloor > or = 1, goto next step else step 7.
  • Display currentFloor value and decrease currentFloor value by 1, goto step 5.
  • Increase currentFloor value by 1, once.
  • End of function FireAlarm().

package elevatorsim;

import java.io.*;

import java.util.Scanner;

/*@author: Asdur Rehman Gara

 *@authorID: MIT172984

 *Class purpose: The purpose of this class is to simulate an Elevator system. The system takes in user input for Floor numbers they wish to travel,

 *checks for validity of inputs and travels accordingly. It also allows users to raise Fire Alarms and quit the system.

    static int floors=1;

    static int currentFloor=1;

    public static int SelectFloor()

        Scanner sc = new Scanner(System.in);

        System.out.println("Which floor you would like to go to: ");

        int tempInput=sc.nextInt();

        if(tempInput<1 || tempInput>100)

            System.out.println("Floor value cannot be out of range 1-100. ERROR!");

            return 0;

        else if(tempInput==currentFloor)

            System.out.println("Same floor. Please try again!");

            return 0;

        else

            floors=tempInput;

            return 1;

    public static void Movement()

        if(currentFloor<floors)

            System.out.println("Going up...");

            while(currentFloor<=floors)

                System.out.print(currentFloor+"...");

                currentFloor++;

            currentFloor--;

         System.out.println("Going down...");

            while(currentFloor>=floors)

                System.out.print(currentFloor+"...");

                currentFloor--;

            currentFloor++;       

        System.out.print("Ding!n");

    public static void FireAlarm()

System.out.println("Danger!! You must exit the building now.");

        if(currentFloor!=1)

            System.out.println("Going down..");

            while(currentFloor>=1)

                System.out.print(currentFloor+"...");

                currentFloor--;

            currentFloor++;

            System.out.print("Ding!n");

Public static void main(String []args)

        Scanner sc = new Scanner(System.in);

        char ch='S';

        System.out.println("Welcome to MIT172984: Asdur Rehman Gara's elevator simulator!n");

        while(ch!='Q')

            System.out.print("nEnter S: Select floor to travelnEnter F: Raise the fire-alarmnEnter Q: Exit the elevatornEnter option now: ");

            ch=sc.next(".").charAt(0);

            ch=Character.toUpperCase(ch);

            switch(ch)

                case 'S': if(SelectFloor()==1)

                                Movement();

                          break;

                case 'F': FireAlarm();

                          break;          

                case 'Q': System.out.println("Exiting...");

                          break;

                default:  System.out.println("Invalid Entry."); 

START

  • Define function main().
  • Display welcome message.
  • User enters number of stones.
  • If number of stones LESS or EQUALS TO 0, goto step 3, else step 5.
  • Set value of remains to number of stones, i.e., n.
  • User enters first going choice in ch.
  • If choice is ‘Y’ or ‘YES’, set turn to 1 and Call player() function and goto step 8 else step 9.
  • Display remaining stones.
  • If user enters neither Y, YES, N or NO, goto step 6.
  • Until remainsvalue reaches 0, goto step 11.
  • Set turn to 2 and call function comp().
  • Display remaining stones.
  • If remaining stones is 0, goto step 17.
  • Set turn to 1.
  • Call player()
  • Display remaining stones.
  • If turn is 2, display “Player Won” message, else display “Computer Won”.
  • Take user choice for continuation.
  • If user enters Y or YES goto step 3. Else step 20.
  • If user enters N or NO, display goodbye message and goto step 22.
  • Otherwise, goto step 18.
  • End of main()

Function player()

  • Declare function player().
  • User enters number of stones to remove.
  • If remaining stones is 1 and also user enters 2, goto step 2, else step 4.
  • If user enters 1 or 2 set value of remaining stones by decreasing removed stones from it and goto step
  • Else it user enters other values, display error message and goto step 2.
  • End of function player().

Function comp()

  • Declare function comp().
  • If remaining stone is divisible by 3, set remove to 2 else set remove to 1.
  • Decrease remaining stones by remove.
  • End of function comp().

package nim.game;

import java.io.*;

import java.util.Scanner;

 *@author: Asdur Rehman Gara #MIT172984

 *This class simulates the game of NIM.

 *It allows the players to select how many stones to start with and remove 1 or 2 stones from that pile. This continues until no stones are left.

 *The computer uses the (OPS)Optimal Playing Strategy for the gaming.

    public static void player()

        Scanner sc = new Scanner(System.in);

        while(true)

            int remove;

            while(true)

                System.out.println("Enter the number of stones to remove (1 or 2): ");

                remove=sc.nextInt();

                if(remains==1)

                    if(remove==2)

            if(remove==1 || remove==2)

                remains=remains-remove;

                System.out.println("Player removes "+remove+" stones.");

                break;

                System.out.println("You can remove either 1 or 2 stones only. Enter again!");

public static void comp()

        int remove;

        if(remains%3==0)

            remove=2;          

        else

            remove=1;

        remains=remains-remove;

    public static void main(String[] args)

        Scanner sc = new Scanner(System.in);

        int n=2;

        String ch="YES";

        int turn=1;

        int flag=1;

        System.out.println("THE GAME OF NIM");

        while(flag==1)

                System.out.print("nEnter the number of starting stones: ");

                n=sc.nextInt();

                if(n<=0)

System.out.println("Invalid entry. Number of stones must be greater than 0.");

                    remains=n;

                    break;

            System.out.print("Would you like to go first? (YES/NO): ");

            ch=sc.next();

            if(ch.equalsIgnoreCase("Y") || ch.equalsIgnoreCase("YES"))

                turn=1;

                player();

                System.out.println("Number of stones left is "+remains);

            else if(!ch.equalsIgnoreCase("y") && !ch.equalsIgnoreCase("yes") && !ch.equalsIgnoreCase("n") && !ch.equalsIgnoreCase("no") )

                System.out.println("Invalid entry.");

                continue;

            while(remains>0)

                turn=2;

                comp();

                System.out.println("Number of stones left is "+remains);

                if(remains==0)

                    break;

                turn=1;

                player();

                System.out.println("Number of stones left is "+remains);

            if(turn==2)

                System.out.println("nYOU WON NIM !! CONGRATULATIONS !!");

                System.out.println("nAlas !! YOU LOST !! COMPUTER WON NIM!!");

            while(true)

                System.out.print("Would you like to go continue? (Y/N):");

                ch=sc.next();

                ch=ch.toUpperCase();

                if(ch.equalsIgnoreCase("Y") || ch.equalsIgnoreCase("YES"))

                    flag=1;

                    break;

                else if(ch.equalsIgnoreCase("NO") || ch.equals("N"))

                    System.out.println("Goodbye!!");

                    flag=0;

                    break;

                    System.out.println("Invalid Entry.");

Cite This Work

To export a reference to this article please select a referencing stye below:

My Assignment Help. (2020). The Essay On Elevator System And NIM Game Simulation Was Insightful.. Retrieved from https://myassignmenthelp.com/free-samples/mn404-fundamentals-of-operating-systems-and-java-programming.

"The Essay On Elevator System And NIM Game Simulation Was Insightful.." My Assignment Help, 2020, https://myassignmenthelp.com/free-samples/mn404-fundamentals-of-operating-systems-and-java-programming.

My Assignment Help (2020) The Essay On Elevator System And NIM Game Simulation Was Insightful. [Online]. Available from: https://myassignmenthelp.com/free-samples/mn404-fundamentals-of-operating-systems-and-java-programming
[Accessed 18 December 2024].

My Assignment Help. 'The Essay On Elevator System And NIM Game Simulation Was Insightful.' (My Assignment Help, 2020) <https://myassignmenthelp.com/free-samples/mn404-fundamentals-of-operating-systems-and-java-programming> accessed 18 December 2024.

My Assignment Help. The Essay On Elevator System And NIM Game Simulation Was Insightful. [Internet]. My Assignment Help. 2020 [cited 18 December 2024]. Available from: https://myassignmenthelp.com/free-samples/mn404-fundamentals-of-operating-systems-and-java-programming.

Get instant help from 5000+ experts for
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing: Proofread your work by experts and improve grade at Lowest cost

loader
250 words
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Plagiarism checker
Verify originality of an essay
essay
Generate unique essays in a jiffy
Plagiarism checker
Cite sources with ease
support
close