96 lines
2.1 KiB
C#
96 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
class Termek
|
|
{
|
|
public int ar, keszlet;
|
|
public string nev;
|
|
|
|
public int Ar
|
|
{
|
|
get { return this.ar; }
|
|
set { this.ar = value;}
|
|
}
|
|
|
|
public int Keszlet
|
|
{
|
|
get { return this.keszlet; }
|
|
set { this.keszlet = value; }
|
|
}
|
|
public string Nev
|
|
{
|
|
get { return this.nev; }
|
|
set { this.nev = value; }
|
|
}
|
|
|
|
public Termek(string name, int price, int db)
|
|
{
|
|
Nev = name;
|
|
Ar = price;
|
|
Keszlet = db;
|
|
}
|
|
|
|
}
|
|
|
|
class Kosar
|
|
{
|
|
public int osszeg = 0;
|
|
|
|
public int Osszeg
|
|
{
|
|
get { return this.osszeg; }
|
|
set { this.osszeg = value;}
|
|
}
|
|
|
|
public void AddItem(Termek t, int darab)
|
|
{
|
|
if (darab <= t.keszlet)
|
|
{
|
|
Osszeg += t.Ar * darab;
|
|
t.Keszlet -= darab;
|
|
} else
|
|
{
|
|
Console.WriteLine("A vásárlás ennyi termékre nem valósítható meg.");
|
|
}
|
|
|
|
}
|
|
|
|
public void Price()
|
|
{
|
|
Console.WriteLine(Osszeg);
|
|
}
|
|
|
|
public void Stock(Termek t)
|
|
{
|
|
Console.WriteLine(t.Keszlet);
|
|
}
|
|
|
|
}
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
Termek alma = new Termek("alma", 250, 20);
|
|
Termek korte = new Termek("korte", 300, 10);
|
|
Termek szolo = new Termek("szolo", 500, 5);
|
|
|
|
Kosar mykosar = new Kosar();
|
|
mykosar.AddItem(alma, 5);
|
|
mykosar.AddItem(korte, 1000);
|
|
mykosar.AddItem(szolo, 5);
|
|
|
|
mykosar.Price();
|
|
|
|
mykosar.Stock(alma);
|
|
Console.WriteLine(alma.Keszlet);
|
|
|
|
|
|
}
|
|
}
|
|
}
|