Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
using System; using System.Collections.Generic; using System.Threading; public class Program { public static void Main() { AutoReapirShop autoReapirShop = new AutoReapirShop(); bool isWorking = true; int sleepTime = 200; while (isWorking) { isWorking = autoReapirShop.Update(); Thread.Sleep(sleepTime); } } } public class AutoReapirShop { private Random _random; private Auto _customerCar; private Dictionary<string, int> _partsStorage; private string[] _partsName; private int _turn; private Screen _screen; private bool _isWorking; private int _moneyAmount = 1000; private int _moneyForCar; private int _storageDetailsAmountMinimum = 0; private int _storageDetailsAmountMaximum = 10; private int _penalty = 200; public AutoReapirShop() { _random = new Random(); _partsStorage = new Dictionary<string, int>(); _screen = Screen.Round; _isWorking = true; _turn = 1; _moneyForCar = 0; CreateCustomerCar(); CreateStorage(); } public bool Update() { if (_isWorking) { switch (_screen) { case Screen.Round: PrintScreenRound(); break; case Screen.Shop: PrintScreenShop(); break; case Screen.Car: PrintScreenRepairCar(); break; case Screen.Detail: PrintScreenRepairDetail(); break; } if (IsBankrout()) { Console.WriteLine("You are banckroupt"); _isWorking = false; } } return _isWorking; } private bool IsBankrout() { return _moneyAmount < 0; } private void PrintScreenRound() { bool isTyping = true; string input; do { PrintState(); Console.WriteLine("\n0. Go to Shop."); Console.WriteLine("1. Go to Car."); Console.WriteLine("2. Exit."); input = Console.ReadLine(); if (input.Equals("0")) { isTyping = false; _screen = Screen.Shop; } else if (input.Equals("1")) { isTyping = false; _screen = Screen.Car; } else if (input.Equals("2")) { isTyping = false; _isWorking = false; } } while (isTyping); } private void PrintScreenShop() { bool isTyping = true; int partsIndex; do { PrintState(); PrintParts(ShowFormat.Car); PrintParts(ShowFormat.Storage); Console.WriteLine("Input index of detail to buy or q to exit"); string input = Console.ReadLine(); isTyping = !int.TryParse(input, out partsIndex); if (input.Equals("q")) { isTyping = false; _screen = Screen.Round; } else if (partsIndex <= 0 || partsIndex >= _partsName.Length) { isTyping = true; } else { if (_moneyAmount <= 0) { Console.WriteLine("You haven't enought money"); } else { ++_partsStorage[_partsName[partsIndex - 1]]; _moneyAmount -= _customerCar.GetPriceDetail(_partsName[partsIndex - 1]); } } } while (isTyping); } private void PrintScreenRepairCar() { bool isTyping = true; int chooseIndex; do { PrintState(); Console.WriteLine("\nBroken Details "); _customerCar.ShowBrokenDetails(); Console.WriteLine("\n0. Repair Detail."); Console.WriteLine("1. Next Car."); isTyping = !int.TryParse(Console.ReadLine(), out chooseIndex); if (chooseIndex == 0) { _screen = Screen.Detail; } else if (chooseIndex == 1) { if (_customerCar.DetailsBrokenAmount <= 0) { _moneyAmount += _moneyForCar; _moneyForCar = 0; } else { _moneyAmount -= _penalty; } _screen = Screen.Round; ++_turn; CreateCustomerCar(); } else { isTyping = true; } } while (isTyping); } private void PrintScreenRepairDetail() { string partName; int partNameIndex; int indexDetail; bool isTyping = true; do { PrintState(); PrintParts(ShowFormat.Parts); Console.WriteLine("\nInput index of name part or q to exit."); partName = Console.ReadLine(); isTyping = !int.TryParse(partName, out partNameIndex); if (partName.Equals("q")) { isTyping = false; _screen = Screen.Car; } else if (partNameIndex <= 0 || partNameIndex > _partsName.Length) { isTyping = true; } else { if (_partsStorage[_partsName[partNameIndex - 1]] > 0) { int amountItems = _customerCar.GetAmountItemsPart(_partsName[partNameIndex - 1]); Console.WriteLine($"\nInput a index of part from 1 to {amountItems}."); isTyping = int.TryParse(Console.ReadLine(), out indexDetail); if (indexDetail <= 0 || indexDetail > amountItems) { isTyping = false; } else { bool isRepairable = _customerCar.RepairDetail(_partsName[partNameIndex - 1], indexDetail - 1); --_partsStorage[_partsName[partNameIndex - 1]]; if (isRepairable) _moneyForCar += _customerCar.GetPriceRepair(_partsName[partNameIndex - 1]); else _moneyForCar -= _customerCar.GetPriceRepair(_partsName[partNameIndex - 1]); } } else { Console.WriteLine("You haven't details in storage."); } } } while (isTyping); } private void PrintState() { Console.Clear(); Console.WriteLine($"Turn : {_turn}"); Console.WriteLine($"Your money : {_moneyAmount}"); } private void PrintParts(ShowFormat showFormat) { string result = "\n" + showFormat.ToString() + ": \n"; for (int i = 0; i < _partsName.Length; ++i) { if (showFormat == ShowFormat.Parts) result += String.Format($"{i + 1}. - {_partsName[i]}\n"); else if (showFormat == ShowFormat.Car) result += String.Format($"{i + 1}. {_partsName[i]} - {_customerCar.GetPriceDetail(_partsName[i])}\n"); else if (showFormat == ShowFormat.Storage) result += String.Format($"{i + 1}. {_partsName[i]} - {_partsStorage[_partsName[i]]}\n"); } Console.WriteLine(result); } private void CreateCustomerCar() { _customerCar = new Auto(_random); } private void CreateStorage() { _partsName = _customerCar.GetNamesParts(); int detailsAmount; for (int i = 0; i < _partsName.Length; ++i) { detailsAmount = _random.Next(_storageDetailsAmountMinimum, _storageDetailsAmountMaximum); _partsStorage.Add(_partsName[i], detailsAmount); } } } public enum Screen { Round, Shop, Car, Detail } public enum ShowFormat { Parts, Car, Storage } public class Auto { private Dictionary<string, Part> _parts; private Random _random; public int DetailsBrokenAmount { get; private set; } public Auto(Random random) { _random = random; CreateParts(); } public int GetPriceDetail(string partName) { return _parts[partName].GetPriceDetail(); } public int GetPriceService(string partName) { return _parts[partName].GetPriceService(); } public int GetAmountItemsPart(string partName) { return _parts[partName].GetItemsAmount(); } public string[] GetNamesParts() { string[] partNames = new string[_parts.Count]; int i = 0; foreach(KeyValuePair<string, Part> part in _parts) { partNames[i] = part.Key; ++i; } return partNames; } public int GetPriceRepair(string partName) { return _parts[partName].GetPriceService() + _parts[partName].GetPriceDetail(); } public bool RepairDetail(string partName, int detailIndex) { bool isRepaired = _parts[partName].Repair(detailIndex); if (isRepaired) --DetailsBrokenAmount; return isRepaired; } public void ShowBrokenDetails() { foreach (KeyValuePair<string, Part> part in _parts) for (int i = 0; i < part.Value.GetItemsAmount(); ++i) if (part.Value.IsBrokenDetail(i)) Console.WriteLine($"{part.Key} ({i + 1}) - " + $"{part.Value.GetPriceDetail() + part.Value.GetPriceService()}"); } private void CreateParts() { _parts = new Dictionary<string, Part> { { "Engine", new Engine(_random) }, { "Tire", new Tires(_random) }, { "Cell", new Cells(_random) }, { "Salon", new Salon(_random) }, { "Head Light", new LightsHead(_random) }, { "Back Light", new LightsBack(_random) } }; foreach (KeyValuePair<string, Part> part in _parts) DetailsBrokenAmount += part.Value.DetailsBrokenAmount; } } public class Engine : Part { public Engine(Random random) : base(random) { ItemsAmount = 1; PriceDetailMinimum = 500; PriceDetailMaximum = 1500; PriceServiceMinimum = 200; PriceServiceMaximum = 900; NamePart = "Engine"; CreateItems(); } } public class Cells : Part { public Cells (Random random) : base (random) { ItemsAmount = 4; PriceDetailMinimum = 80; PriceDetailMaximum = 200; PriceServiceMinimum = 80; PriceServiceMaximum = 120; NamePart = "Cell"; CreateItems(); } } public class Tires : Part { public Tires (Random random) : base (random) { ItemsAmount = 4; PriceDetailMinimum = 100; PriceDetailMaximum = 250; PriceServiceMinimum = 80; PriceServiceMaximum = 140; NamePart = "Tire"; CreateItems(); } } public class Salon : Part { public Salon (Random random) : base (random) { ItemsAmount = 1; PriceDetailMinimum = 600; PriceDetailMaximum = 900; PriceServiceMinimum = 400; PriceServiceMaximum = 600; NamePart = "Salon"; CreateItems(); } } public class LightsHead : Part { public LightsHead(Random random) : base (random) { ItemsAmount = 2; PriceDetailMinimum = 100; PriceDetailMaximum = 300; PriceServiceMinimum = 80; PriceServiceMaximum = 250; NamePart = "Head Light"; CreateItems(); } } public class LightsBack : Part { public LightsBack(Random random) : base(random) { ItemsAmount = 2; PriceDetailMinimum = 120; PriceDetailMaximum = 300; PriceServiceMinimum = 80; PriceServiceMaximum = 250; NamePart = "Back Light"; CreateItems(); } } public abstract class Part { protected Random Random; protected List<Item> Items; protected int ItemsAmount; protected string NamePart; protected int PriceDetailMinimum; protected int PriceDetailMaximum; protected int PriceServiceMinimum; protected int PriceServiceMaximum; protected int RangePercent; protected int BrokenPrecent; public int DetailsBrokenAmount { get; private set; } public string GetName() { return NamePart; } public int GetPriceDetail() { return Items[Items.Count - 1].PriceDetail; } public int GetPriceService() { return Items[Items.Count - 1].PriceService; } public int GetItemsAmount() { return ItemsAmount; } public bool Repair(int index) { bool isBroken = Items[index].IsBroken; if (isBroken) Items[index].Repair(); return isBroken; } public bool IsBrokenDetail(int index) { return Items[index].IsBroken; } public Part(Random random) { Random = random; DetailsBrokenAmount = 0; } protected void CreateItems() { Items = new List<Item>(); RangePercent = 100; BrokenPrecent = 50; bool isBroken; Item item; int priceDetail = Random.Next(PriceDetailMinimum, PriceDetailMaximum); int priceService = Random.Next(PriceServiceMinimum, PriceServiceMaximum); for (int i = 0; i < ItemsAmount; ++i) { isBroken = Random.Next(RangePercent) > BrokenPrecent; if (isBroken) ++DetailsBrokenAmount; item = new Item(priceService, priceDetail, isBroken); Items.Add(item); } } } public class Item { public int PriceService { get; private set; } public int PriceDetail { get; private set; } public bool IsBroken { get; private set; } public Item(int priceService, int priceDetail, bool isBroken) { PriceService = priceService; PriceDetail = priceDetail; IsBroken = isBroken; } public void Repair() { IsBroken = false; } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
SwapEngine Bug [build 1.3]
5 min ago | 0.28 KB
December smells like money
CSS | 18 min ago | 0.28 KB
✅ Changelly.com Exploit
31 min ago | 0.28 KB
Trading method
CSS | 45 min ago | 0.28 KB
Google Docs - Exploit
58 min ago | 0.28 KB
Untitled
C | 9 hours ago | 0.88 KB
acg
1 day ago | 0.05 KB
AI METHODS
2 days ago | 0.29 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!