Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ElevatorDesign_2020Dec11
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { static int floorA; //declaring variable Floor A static int floorB; //declaring variable Floor B static int currentFloor; // xxxxxx //Conditional Statments to call elevators A or B based on number of floors inbetween passenger and elevator. // Also built into the logic below, Elevator A services basement(-1) and elevator B services penthouse(10) public void elevatorB_Logic() { if (floorB == currentFloor ) { Console.WriteLine("Enter elevator B: "); } else { MoveElevator_B(currentFloor); } Console.WriteLine("Door Open "); Console.WriteLine("Which floor do you want to go (1 to 10),where 10 = Penthouse?"); int target_floor = 6; Console.WriteLine("Door closed"); //restricts the range of floors for elevator B between floors(0 to 10) if (target_floor>10||target_floor<0) { Stop(); } else { MoveElevator_B_to_target(target_floor);} } public void elevatorA_Logic()//run elevator A { if(floorA == currentFloor ) { Console.WriteLine("Enter elevator A"); //open the elevator } else { MoveElevator_A(currentFloor); } Console.WriteLine("Door Open "); Console.WriteLine("Which floor do you want to go (-1 to 9) where -1 = Basement?"); int target_floor = 7; Console.WriteLine("Door closed"); //restricts the range of floors for elevator A between (-1 to 9) if (target_floor>=10||target_floor<-1) { Stop(); } else { MoveElevator_A_to_target(target_floor); } } //xxxxxxx public static void MoveElevator_A(int currentFloor) { int direction ; if (currentFloor > floorA) { Console.WriteLine("Elevator A moving to floor:"+currentFloor); direction =+1; } else if (currentFloor < floorA) { Console.WriteLine("Elevator A moving to floor:"+currentFloor); direction =-1; } else { Console.WriteLine("Elevator A is here..."); direction =0; } while (currentFloor != floorA) { floorA += direction; // wait(500); //System.out.println(floorA); } Console.WriteLine("Elevator A has arrived"); } public static void MoveElevator_B(int currentFloor) { int direction ; if (currentFloor > floorB) { Console.WriteLine("Elevator B moving to floor:"+currentFloor); direction =+1; } else if (currentFloor < floorB) { Console.WriteLine("Elevator B moving to floor:"+currentFloor); direction =-1; } else { Console.WriteLine("Elevator B is here..."); direction =0; } while (currentFloor != floorB) { floorA += direction; // wait(500); //System.out.println(floorA); } Console.WriteLine("Elevator B has arrived"); } public static void MoveElevator_B_to_target(int target_floor) { int direction ; if (target_floor > floorB) { Console.WriteLine("Elevator B moving up..."); direction =+1; } else { Console.WriteLine("Elevator B moving down..."); direction = -1; } while (target_floor != floorB) { floorB += direction; // wait(1000); Console.WriteLine(floorB); } Console.WriteLine("Elevator B has arrived at destination."); Console.WriteLine("Door Open."); //wait(3000); Console.WriteLine("Door Close."); } public static void MoveElevator_A_to_target(int target_floor) { int direction ; if (target_floor > floorA) { Console.WriteLine("Elevator A moving up..."); direction =+1; } else { Console.WriteLine("Elevator A moving down..."); direction = -1; } while (target_floor != floorA) { floorA += direction; // wait(1000); Console.WriteLine(floorA); } Console.WriteLine("Elevator A has arrived at destination."); Console.WriteLine("Door Open."); //wait(3000); Console.WriteLine("Door Close."); } // Stop method to restrict the elevators to their respective floor ranges. private static void Stop() { //DualElevators run =new DualElevators(); Console.WriteLine("Please enter a valid input."); //return; } public static void Main(string[] args) { Program run=new Program(); Random rand = new Random(); int ElevatorA = rand.Next(-1,9); //Elevator A is positioned randomly between floors:-1 to 9. int ElevatorB = rand.Next(1,10); // Elevator B is positioned randomly between floors :1 to 10. int floorA=ElevatorA; int floorB=ElevatorB; Console.WriteLine("Elevator A :" +floorA + " floor"); //print the current floor for elevator A Console.WriteLine("Elevator B :" +floorB + " floor"); //print the current floor for elevator B int passengerFloor=rand.Next(-1,10); //Random Integer between -1 and 10 to denote the floor passenger is on. Console.WriteLine("Passenger on floor:"+passengerFloor+" has called the elevator."); currentFloor=passengerFloor; int relA = Math.Abs(currentFloor - floorA); int relB = Math.Abs(currentFloor - floorB); //Method to move elevator A from its current floor assigned randomly to floor on which Passenger is waiting(if summoned by controller). } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,44 sec, absolute running time: 0,09 sec, cpu time: 0,11 sec, average memory usage: 18 Mb, average nr of threads: 3, absolute service time: 0,56 sec
edit mode
|
history
|
discussion
Elevator A :0 floor Elevator B :4 floor Passenger on floor:8 has called the elevator.