Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
ElevatorDesign_2020Dec11
//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). } } }
run
|
edit
|
history
|
help
0
Listas JL
a1
Working with Strings
prime number experiment
Delegate, Method, List, Classes, Conditions
Create HardwareConfigs
Imp
test_hash
Intuit // C# // listing_4.10 (for..)
Math 5.85a