static void Main(string[] args) { Shop <Product> shop = new Shop <Product>(); Tshirt shirt = TshirtBuilder.BuildTshirt(); shirt.Name = "adidas"; shirt.Size = "xl"; shirt.Collection = "last"; Jeans jeans = JeansBuilder.BuildJeans(); jeans.Name = "colins"; jeans.Collection = "last"; jeans.Size = "L"; Cap cap = CapBuilder.BuildCap(); cap.Name = "Ny"; cap.Size = "s"; cap.Collection = "last"; shop.Add(shirt); shop.Add(jeans); shop.Add(cap); shop.Show(); }
// Partitioning static int partitionColorDesc(Tshirt[] tshirts, int low, int high) { Tshirt shirt = tshirts[high]; // index of smaller element int i = (low - 1); for (int j = low; j < high; j++) { // If current element is smaller // than the pivot if (tshirts[j].Color > shirt.Color) { i++; // swap tshirts[i] and tshirts[j] Tshirt temp = tshirts[i]; tshirts[i] = tshirts[j]; tshirts[j] = temp; } } // swap tshirts[i+1] and tshirts[high] (or pivot) Tshirt temp1 = tshirts[i + 1]; tshirts[i + 1] = tshirts[high]; tshirts[high] = temp1; return(i + 1); }
public static void BuyShirt() { List <IVariationStrategy> variationStrategies = new List <IVariationStrategy>() { new ColorVariation(), new FabricVariation(), new SizeVariation() }; Color color = ChooseVariation <Color>(); Size size = ChooseVariation <Size>(); Fabric fabric = ChooseVariation <Fabric>(); Tshirt shirt = new Tshirt(color, size, fabric); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"Your order is a {color}, {fabric}, {size} t-shirt"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); EshopContext eshop = new EshopContext(); eshop.SetVariationStrategy(variationStrategies); // Payment Method PaymentMethod paymentMethod = ChoosePaymentMethod(); eshop.SelectPaymentMethod(paymentMethod); eshop.TotalCostShirt(shirt); tshirts.Add(shirt); }
public void SortBySizeThenColorThenFabricDescending(List <Tshirt> tshirts) { bool didAtLeastOneSwap = false; for (int i = 0; i < tshirts.Count; i++) { for (int j = 0; j < tshirts.Count - 1 - i; j++) { didAtLeastOneSwap = false; bool comparisonCondition = (tshirts[j].Size < tshirts[j + 1].Size) || (tshirts[j].Size == tshirts[j + 1].Size && tshirts[j].Color < tshirts[j + 1].Color) || (tshirts[j].Size == tshirts[j + 1].Size && tshirts[j].Color == tshirts[j + 1].Color && tshirts[j].Fabric < tshirts[j + 1].Fabric); if (comparisonCondition) { Tshirt temp = tshirts[j]; tshirts[j] = tshirts[j + 1]; tshirts[j + 1] = temp; didAtLeastOneSwap = true; } } if (didAtLeastOneSwap) { break; } } }
static int QuickSortBySizeThenColorThenFabricPartitionDescending(List <Tshirt> tshirts, int low, int high) { Tshirt pivot = tshirts[high]; int i = low - 1; for (int j = low; j < high; j++) { bool condition = (tshirts[j].Size > pivot.Size) || ((tshirts[j].Size == pivot.Size) && (tshirts[j].Color > pivot.Color)) || ((tshirts[j].Size == pivot.Size) && (tshirts[j].Color == pivot.Color) && (tshirts[j].Fabric > pivot.Fabric)); if (condition) //here we change to descending { i++; //swap Tshirt temp = tshirts[i]; tshirts[i] = tshirts[j]; tshirts[j] = temp; } } Tshirt temp1 = tshirts[i + 1]; tshirts[i + 1] = tshirts[high]; tshirts[high] = temp1; return(i + 1); }
static void Main(string[] args) { Tshirt ob = new Tshirt(); ob.Discount(); Console.ReadLine(); }
// --------> Break until 10:13 public static void Run() { var t = new Tshirt(); t.Price = 400; t.Discount = 0.3M; t.Discount = 123456; // <----- Nothing will change Console.WriteLine($"Price of the tshirt with discount: {t.PriceWithDiscount}"); }
public void DoPayment(Tshirt tshirt) { decimal basePrice = 0.0m; switch (tshirt.Fabric) { case Fabric.WOOL: case Fabric.COTTON: basePrice = 30.0m; break; case Fabric.POLYESTER: case Fabric.RAYON: basePrice = 25.0m; break; case Fabric.LINEN: case Fabric.CASHMERE: case Fabric.SILK: basePrice = 40.0m; break; } switch (tshirt.Size) { case Size.M: basePrice += basePrice * 0.05m; break; case Size.L: case Size.XL: case Size.XXL: case Size.XXXL: basePrice += basePrice * 0.1m; break; } switch (tshirt.Color) { case Color.RED: case Color.BLUE: case Color.GREEN: case Color.YELLOW: basePrice += basePrice * 0.03m; break; case Color.ORANGE: case Color.INDIGO: case Color.VIOLET: basePrice += basePrice * 0.07m; break; } Console.WriteLine($"The price of your TShirt is: {basePrice:0.##}\u0024"); }
public ActionResult <Tshirt> GetById(int id) { Tshirt found = Inventory.Find(t => t.Id == id); if (found != null) { return(found); } return(BadRequest("error")); // return BadRequest("{\"error\": \"not found\"}"); }
public void Run() { var t = new Tshirt(); t.Price = 400; t.Discount = 0.3M; var priceWithDiscount = t.Price * (1 - t.Discount); Console.WriteLine("Priset för tshirten med rabatt är :" + priceWithDiscount); }
public ActionResult Delete(int id) { Tshirt oldData = Inventory.Find(t => t.Id == id); if (oldData == null) { return(BadRequest()); } Inventory.Remove(oldData); return(Ok()); }
public static List <Tshirt> CloneList(List <Tshirt> original) { List <Tshirt> newList = new List <Tshirt>(); foreach (var item in original) { Tshirt temp = item.DeepCopy(); newList.Add(temp); } return(newList); }
public void Run() { var t = new Tshirt(); t.Price = 400; t.SetDiscount(0.3M); t.SetDiscount(123M); // här kommer inget ske var priceWithDiscount = t.Price * (1 - t.GetDiscount()); Console.WriteLine("Priset för tshirten med rabatt är :" + priceWithDiscount); }
// (Until 9:41) public static void Run() { var t = new Tshirt(); t.Price = 400; t.SetDiscount(0.3M); // Exercise: create "priceWithDiscount" var priceWithDicount = t.Price * (1 - t.GetDiscount()); Console.WriteLine($"Price of the tshirt with discount: {priceWithDicount}"); }
public static void Main(string[] args) { Tshirt ats = new Tshirt(); ats.Name = "Awesome"; Tshirt nts = new Tshirt(); nts.Name = "Not Awesome"; TshirtSpecification criteria = new TshirtSpecification(); Console.WriteLine("Is the shirt awesome? " + criteria.Satisfies(ats)); Console.WriteLine("Is the shirt awesome? " + criteria.Satisfies(nts)); }
public ActionResult <Tshirt> Put(int id, [FromBody] Tshirt newData) { // add newData in place of old data Tshirt oldData = Inventory.Find(t => t.Id == id); if (oldData == null) { return(BadRequest()); } Inventory.Remove(oldData); Inventory.Add(newData); return(newData); }
static void Main(string[] args) { CreationPricing(); Random rand = new Random(); List <Tshirt> tshirts = new List <Tshirt>(); for (int i = 0; i < 40; i++) { Tshirt newTshirt = new Tshirt("Tshirt" + i, (Color)rand.Next(1, 7), (Size)rand.Next(1, 7), (Fabric)rand.Next(1, 7)); tshirts.Add(newTshirt); } }
public IActionResult Create([FromForm]TshirtViewModel tshirtModel) { if(ModelState.IsValid) { Tshirt tshirt = ConvertToTshirt(tshirtModel); tshirtRepository.SaveTshirt(tshirt); TempData["SuccessMessage"] = $"{tshirt.Name} " +$"tshirt ({tshirt.Id}) " +"was successfully created"; return RedirectToAction(nameof(Create)); }else{ return View(tshirtModel); } } // End of method Create.
public void addItem() { //Assign var T = new Tshirt(); int expected = 20; T.Size = "m"; //Act int actual = T.GetTotal(); //Assert Assert.AreEqual(expected, actual); }
} // End of ctor // Methods public void SaveTshirt(Tshirt tshirt) { if(tshirt != null) { if( tshirt.Id == guid) { dbContext.Tshirts.Add(tshirt); }else { dbContext.Tshirts.Update(tshirt); } dbContext.SaveChanges(); }else{ throw new ArgumentNullException(nameof(tshirt), "Unable to save an empty tshirt"); } } // End of method SaveTshirt.
} // End of method SaveTshirt. public Tshirt DeleteTshirt(Guid tshirtGuid) { if(tshirtGuid != null) { Tshirt tshirtToRemove = dbContext.Tshirts.FirstOrDefault(t => t.Id == tshirtGuid); if(tshirtToRemove != null) { dbContext.Tshirts.Remove(tshirtToRemove); dbContext.SaveChanges(); return tshirtToRemove; }else{ throw new ArgumentNullException(nameof(tshirtToRemove), "Unable to find tshirt to delete"); } } else{ throw new ArgumentNullException(nameof(tshirtGuid), "Unable to find an empty Id"); } } // End of method DeleteTshirt.S
public void TotalCostShirt(Tshirt tshirt) // An eixa polla edw 8a eixa IProduct { decimal sum = 0; foreach (var variation in _variations) { variation.Cost(tshirt); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(variation.GetType().Name + " " + tshirt.Price); Console.ForegroundColor = ConsoleColor.White; sum += tshirt.Price; Console.WriteLine(); //Tora prepei kapoiow Client(Front end ot Action method(contrtoller)) na aporrofisei tin katastash, afou 8a to zitisei } Console.WriteLine("The total cost is {0:c}", sum); }
public void TestTshirt() { // Given IProduct tshirt = new Tshirt(); PurchaseController controller = new PurchaseController(); ICommand order = new OrderCommand(tshirt); controller.InsertCommand(order); ICommand buy = new BuyCommand(tshirt); controller.InsertCommand(buy); // When var order_t = order.Execute(); var buy_t = buy.Execute(); // Then Assert.AreEqual("T-shirt", order_t); Assert.AreEqual("19.99", buy_t); }
public void Cost(Tshirt tshirt) { switch (tshirt.Size) { case Enums.Size.XS: tshirt.Price += 1.29m; break; case Enums.Size.S: tshirt.Price += 1.35m; break; case Enums.Size.M: tshirt.Price += 1.43m; break; case Enums.Size.L: tshirt.Price += 2.25m; break; case Enums.Size.XL: tshirt.Price += 1.85m; break; case Enums.Size.XXL: tshirt.Price += 1.05m; break; case Enums.Size.XXXL: tshirt.Price += 1.00m; break; default: tshirt.Price += 1.25m; break; } }
public void Cost(Tshirt tshirt) { switch (tshirt.Color) // You can choose to use dictionary. Enums help to find them easier. { case Enums.Color.Blue: tshirt.Price += 1.25m; break; case Enums.Color.Green: tshirt.Price += 1.35m; break; case Enums.Color.Indigo: tshirt.Price += 0.25m; break; case Enums.Color.Orange: tshirt.Price += 2.25m; break; case Enums.Color.Red: tshirt.Price += 3.25m; break; case Enums.Color.Violet: tshirt.Price += 1.35m; break; case Enums.Color.Yellow: tshirt.Price += 1.09m; break; default: tshirt.Price += 0m; break; } }
public void Cost(Tshirt tshirt) { switch (tshirt.Fabric) { case Enums.Fabric.Casmere: tshirt.Price += 1.75m; break; case Enums.Fabric.Cotton: tshirt.Price += 1.28m; break; case Enums.Fabric.Liner: tshirt.Price += 1.45m; break; case Enums.Fabric.Polyester: tshirt.Price += 0.25m; break; case Enums.Fabric.Rayon: tshirt.Price += 1.65m; break; case Enums.Fabric.Silk: tshirt.Price += 2.25m; break; case Enums.Fabric.Wool: tshirt.Price += 1.08m; break; default: tshirt.Price += 1.25m; break; } }
static int QuickSortBySizePartitionDescending(List <Tshirt> tshirts, int low, int high) { Tshirt pivot = tshirts[high]; int i = low - 1; for (int j = low; j < high; j++) { if (tshirts[j].Size > pivot.Size) //Here we change to descending { i++; //swap Tshirt temp = tshirts[i]; tshirts[i] = tshirts[j]; tshirts[j] = temp; } } Tshirt temp1 = tshirts[i + 1]; tshirts[i + 1] = tshirts[high]; tshirts[high] = temp1; return(i + 1); }
static int QuickSortByFabricPartitionAscending(List <Tshirt> tshirts, int low, int high) { Tshirt pivot = tshirts[high]; int i = low - 1; for (int j = low; j < high; j++) { if (tshirts[j].Fabric < pivot.Fabric) { i++; //swap Tshirt temp = tshirts[i]; tshirts[i] = tshirts[j]; tshirts[j] = temp; } } Tshirt temp1 = tshirts[i + 1]; tshirts[i + 1] = tshirts[high]; tshirts[high] = temp1; return(i + 1); }
public void DoPayment(Tshirt tshirt) { decimal basePrice = 0.0m; switch (tshirt.Fabric) { case Fabric.WOOL: case Fabric.COTTON: basePrice = 20.0m; break; case Fabric.POLYESTER: case Fabric.RAYON: basePrice = 15.0m; break; case Fabric.LINEN: case Fabric.CASHMERE: case Fabric.SILK: basePrice = 30.0m; break; } switch (tshirt.Size) { //Price change only for L+ case Size.L: case Size.XL: case Size.XXL: case Size.XXXL: basePrice += basePrice * 0.05m; break; } //Price is the same for all colors Console.WriteLine($"The price of your TShirt is: {basePrice:0.##}\u0024"); }
public void SortByFabricDescending(List <Tshirt> tshirts) { bool didAtLeastOneSwap = false; for (int i = 0; i < tshirts.Count; i++) { for (int j = 0; j < tshirts.Count - 1 - i; j++) { didAtLeastOneSwap = false; if (tshirts[j].Fabric < tshirts[j + 1].Fabric) { Tshirt temp = tshirts[j]; tshirts[j] = tshirts[j + 1]; tshirts[j + 1] = temp; didAtLeastOneSwap = true; } } if (didAtLeastOneSwap) { break; } } }
public Skin(Beard beard, Hair hair, Hat hat, Body body, Tshirt tshirt, Pant pant, Gloves gloves, Eyes eyes) { this.beard = beard; this.hair = hair; this.hat = hat; this.body = body; this.tshirt = tshirt; this.pant = pant; this.gloves = gloves; this.eyes = eyes; }
// Method public void Randomize() { List<Eyes> eyes = new List<Eyes>(); foreach (Eyes e in Clothing.Eyes) eyes.Add(e); this.eyes = eyes[Random.Range(0, eyes.Count - 1)]; List<Gloves> gloves = new List<Gloves>(); foreach (Gloves g in Clothing.Gloves) gloves.Add(g); this.gloves = gloves[Random.Range(0, gloves.Count - 1)]; List<Pant> pant = new List<Pant>(); foreach (Pant p in Clothing.Pants) pant.Add(p); this.pant = pant[Random.Range(0, pant.Count - 1)]; List<Tshirt> tshirt = new List<Tshirt>(); foreach (Tshirt t in Clothing.Tshirts) tshirt.Add(t); this.tshirt = tshirt[Random.Range(0, tshirt.Count - 1)]; List<Body> body = new List<Body>(); foreach (Body b in Clothing.Bodies) body.Add(b); this.body = body[Random.Range(0, body.Count - 1)]; List<Hair> hair = new List<Hair>(); foreach (Hair h in Clothing.Hairs) hair.Add(h); this.hair = hair[Random.Range(0, hair.Count - 1)]; if (this.hair.GetTypeHair == Hair.TypeHair.Crete) this.hat = Hat.NoneHat; else { List<Hat> hat = new List<Hat>(); foreach (Hat h in Clothing.Hats) hat.Add(h); this.hat = hat[Random.Range(0, hat.Count - 1)]; } List<Beard> beard = new List<Beard>(); foreach (Beard b in Clothing.Beards) beard.Add(b); this.beard = beard[Random.Range(0, beard.Count - 1)]; }
// Constructeur public Skin() { this.beard = new Beard(); this.hair = new Hair(); this.hat = new Hat(); this.body = new Body(); this.tshirt = new Tshirt(); this.pant = new Pant(); this.gloves = new Gloves(); this.eyes = new Eyes(); }
public Tshirt(Tshirt tshirt) : base(tshirt) { this.color = tshirt.color; this.type = tshirt.type; }