Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Mashinki
- {
- abstract class Item
- {
- protected string name;
- protected double price;//с точностью до двух знаков
- public double Price
- {
- get {
- if (price >= 0)
- {
- return price;
- }
- else throw new ArgumentException();
- }
- }
- public Item(string name1, double price1)
- {
- name = name1;
- price = price1;
- }
- public Item()
- {
- }
- }
- class Food:Item
- {
- protected int weight;
- protected int Weight{ get { return weight; } }
- public Food(string name1, double price1, int weight1)
- {
- name = name1;
- price = price1;
- weight = weight1;
- }
- public override string ToString()
- {
- return name + " " + Price + " " + weight;
- }
- }
- class Drink:Item
- {
- int volume;
- protected int Volume { get { return volume; } }
- public Drink(string name1, double price1, int volume1)
- {
- name = name1;
- price = price1;
- volume = volume1;
- }
- public override string ToString()
- {
- return name + " " + Price + " " + Volume;
- }
- }
- class FoodBasket
- {
- Item[] foodBasket;
- int size;
- public FoodBasket(int n, Item[] arr)
- {
- foodBasket = new Item[n];
- for (int i = 0; i < n; i++)
- {
- foodBasket[i] = arr[i];
- }
- }
- public double BasketCost()
- {
- double m = 0;
- for (int i = 0; i < foodBasket.Length; i++)
- {
- m += foodBasket[i].Price;
- }
- return m;
- }
- public Item[] Basket{ get { return foodBasket; } }
- }
- class Program
- {
- public static Random rnd = new Random();
- static string RandomString()
- {
- string r="";
- string n = "qwertyuiopasdfghjklzxcvbnm";
- for (int i = 0; i < rnd.Next(n.Length); i++)
- {
- r += n[rnd.Next(n.Length)];
- }
- return r;
- }
- static void Main(string[] args)
- {
- double maxuser = 0;
- FoodBasket[] user = new FoodBasket[rnd.Next(10, 15)];
- double[] maxarr = new double[user.Length];
- for (int i = 0; i <user.Length ; i++)
- {
- Item[] arr = new Item[7];
- for (int m = 0; m < arr.Length; m++)
- {
- int r = rnd.Next(9);
- if (r <= 3) arr[m] = new Food(RandomString(), rnd.Next(30, 3000), rnd.Next());
- else arr[m] = new Drink(RandomString(), rnd.Next(30, 3000), rnd.Next());
- if (arr[m].Price > maxarr[i]) maxarr[i] = arr[m].Price;
- }
- user[i] = new FoodBasket(7, arr);
- if (user[i].BasketCost() > maxuser) maxuser = user[i].BasketCost();
- }
- for (int i = 0; i < user.Length; i++)
- {
- Console.WriteLine("Корзина #{0}", i);
- for (int m = 0; m < 7; m++)
- {
- Console.WriteLine(user[i].Basket[m].ToString());
- }
- Console.WriteLine("Самый дорогой в козине:{0}", maxarr[i]);
- Console.WriteLine();
- }
- Console.WriteLine("Самая дорогая корзина:{0}",maxuser);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement