Compare commits

...

2 Commits

Author SHA1 Message Date
b84e021884 Prześlij pliki do '' 2020-10-27 18:03:13 +01:00
a1c957275f test 2020-10-27 17:48:36 +01:00
6 changed files with 262 additions and 0 deletions

8
Automat_prototype.csproj Normal file
View File

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,64 @@
{
"format": 1,
"restore": {
"C:\\Users\\krykr\\source\\repos\\Automat_prototype\\Automat_prototype.csproj": {}
},
"projects": {
"C:\\Users\\krykr\\source\\repos\\Automat_prototype\\Automat_prototype.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\krykr\\source\\repos\\Automat_prototype\\Automat_prototype.csproj",
"projectName": "Automat_prototype",
"projectPath": "C:\\Users\\krykr\\source\\repos\\Automat_prototype\\Automat_prototype.csproj",
"packagesPath": "C:\\Users\\krykr\\.nuget\\packages\\",
"outputPath": "C:\\Users\\krykr\\source\\repos\\Automat_prototype\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Microsoft\\Xamarin\\NuGet\\"
],
"configFilePaths": [
"C:\\Users\\krykr\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files (x86)\\dotnet\\sdk\\3.1.402\\RuntimeIdentifierGraph.json"
}
}
}
}
}

25
Automat_prototype.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30523.141
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Automat_prototype", "Automat_prototype.csproj", "{7F9A6568-4191-49F6-B9BA-DDCA3620B778}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7F9A6568-4191-49F6-B9BA-DDCA3620B778}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F9A6568-4191-49F6-B9BA-DDCA3620B778}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F9A6568-4191-49F6-B9BA-DDCA3620B778}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F9A6568-4191-49F6-B9BA-DDCA3620B778}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {651FB487-9364-429A-9E46-E94F84C0E0EB}
EndGlobalSection
EndGlobal

28
Product.cs Normal file
View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Automat_prototype
{
class Product
{
public string Name { get; set; }
public double Price { get; set; }
public string Position { get; set; }
public int Amount { get; set; }
public Product(string name, double price, string position, int amount)
{
Name = name;
Price = price;
Position = position;
Amount = amount;
}
public void ShowInfo()
{
Console.WriteLine(this.Name + " Cena = " + this.Price + " Kod = " + this.Position + " Pozostało " + this.Amount);
}
}
}

136
Program.cs Normal file
View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
namespace Automat_prototype
{
class Program
{
public static List<Product> LoadProducts()
{
List<Product> ProductList = new List<Product>();
ProductList.Add(new Product("Pepsi", 3.00, "A1", 8));
ProductList.Add(new Product("Lipton", 2.50, "A2", 5));
ProductList.Add(new Product("Snickers", 1.00, "B3", 4));
ProductList.Add(new Product("Bounty", 2.00, "C5", 7));
return ProductList;
}
static void WorkLoop(List<Product> ProductList)
{
while (true) {
Console.WriteLine("Dostępne produkty:");
for (int i = 0; i < ProductList.Count; i++)
{
ProductList[i].ShowInfo();
}
Console.WriteLine("Wybierz produkt:");
string selected = Console.ReadLine();
for (int i = 0; i < ProductList.Count; i++)
{
if (String.Compare(selected, ProductList[i].Position) == 0)
{
if (ProductList[i].Amount == 0)
{
Console.WriteLine("Brak wybranego produktu");
break;
}
else
{
Console.WriteLine("Wrzuć pieniądze");
double money = 0;
try
{
money = double.Parse(Console.ReadLine());
}
catch (FormatException f) {
Console.WriteLine(f.Message);
}
if (money < ProductList[i].Price)
{
Console.WriteLine("Wrzuciłeś za mało, następuje zwrot pieniędzy");
break;
}
else
{
double rest = money - ProductList[i].Price;
rest = Math.Round(rest, 2);
Console.WriteLine("Wrzucono " + money + "zł, reszta wynosi " + rest);
if(rest > 0)
{
RestCounter(rest);
}
}
Console.WriteLine("Już podaję");
ProductList[i].Amount = ProductList[i].Amount - 1;
break;
}
}
if (i == ProductList.Count - 1)
{
Console.WriteLine("Brak wybranego produktu");
break;
}
}
}
}
static int RestCounter(double rest)
{
int[] coins = new int[6] {0, 0, 0, 0, 0, 0};
while (rest != 0)
{
if(rest >= 5)
{
rest = Math.Round(rest - 5, 2);
coins[0] = coins[0] + 1;
}
else if (rest >= 2)
{
rest = Math.Round(rest - 2, 2);
coins[1] = coins[1] + 1;
}
else if (rest >= 1)
{
rest = Math.Round(rest - 1, 2);
coins[2] = coins[2] + 1;
}
else if (rest >= 0.5)
{
rest = Math.Round(rest - 0.5, 2);
coins[3] = coins[3] + 1;
}
else if (rest >= 0.2)
{
rest = Math.Round(rest - 0.2, 2);
coins[4] = coins[4] + 1;
}
else if (rest >= 0.1)
{
rest = Math.Round(rest - 0.1, 2);
coins[5] = coins[5] + 1;
}
else
{
Console.WriteLine("Nastąpił błąd przy wydawaniu reszty, proszę skontaktować się z pomocą techniczną");
return -1;
}
}
Console.WriteLine("Wydano " + coins[0] + " monet 5zł, " + coins[1] + " monet 2zł, " + coins[2] + " monet 1zł, " + coins[3] + " monet 50gr, " + coins[4] + " monet 20gr, " + coins[5] + " monet 10gr");
return 0;
}
static void Main(string[] args)
{
List<Product> ProductList = new List<Product>();
ProductList = LoadProducts();
WorkLoop(ProductList);
}
}
}

View File

@ -0,0 +1 @@
prototyp