GUL MD ERSHAD
BAN USERResearch Engineer
- 0of 0 votes
AnswersBasic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions.
- GUL MD ERSHAD in India
When I purchase items I receive a receipt which lists the name of all the items and their price (including tax), finishing with the total cost of the items, and the total amounts of sales taxes paid. The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.
Write an application that prints out the receipt details for these shopping baskets.
Input:
1) 1 book at 12.49
2) 1 music CD at 14.99
3) 1 chocolate bar at 0.85| Report Duplicate | Flag | PURGE
ThoughtWorks Senior Software Development Engineer Object Oriented Design
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Semaphore.PrintNumbers();
Console.ReadKey();
}
}
public class Semaphore
{
static SemaphoreSlim sema = new SemaphoreSlim(1, 1);
static LinkedList<int> Numbers = new LinkedList<int>();
private static Thread th1;
private static Thread th2;
private static Thread th3;
private static void PrintOne()
{
while (Numbers.Count >0) {
sema.Wait();
var a = Numbers.FirstOrDefault();
if (a == 1) {
Console.WriteLine(1);
Numbers.RemoveFirst();
}
sema.Release();
}
}
private static void PrintSecond() {
while (Numbers.Count > 0) {
sema.Wait();
var a = Numbers.FirstOrDefault();
if (a == 2) {
Console.WriteLine(a);
Numbers.RemoveFirst();
}
sema.Release();
}
}
private static void PrintThird()
{
while (Numbers.Count > 0) {
sema.Wait();
var a = Numbers.FirstOrDefault();
if (a == 3)
{
Console.WriteLine(a);
Numbers.RemoveFirst();
}
sema.Release();
}
}
public static void PrintNumbers() {
Numbers.AddLast(1);
Numbers.AddLast(2);
Numbers.AddLast(3);
Numbers.AddLast(1);
Numbers.AddLast(2);
Numbers.AddLast(3);
Numbers.AddLast(1);
Numbers.AddLast(2);
Numbers.AddLast(3);
th1 = new Thread(PrintOne);
th2 = new Thread(PrintSecond);
th3 = new Thread(PrintThird);
th1.Name = "first";
th2.Name = "second";
th3.Name = "third";
th1.Start();
th2.Start();
th3.Start();
th1.Join();
th2.Join();
th3.Join();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
OddEven.PrintOddEven();
Console.ReadKey();
}
}
public class OddEven
{
static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);
static Thread Odd;
static Thread Even;
static Thread Zero;
static LinkedList<int> Numbers = new LinkedList<int>();
private static void PrintOdd()
{
while (Numbers.Count > 0)
{
semaphoreSlim.Wait();
var a = Numbers.FirstOrDefault();
if (a % 2 != 0)
{
Console.WriteLine(a);
Numbers.RemoveFirst();
}
semaphoreSlim.Release();
}
}
private static void PrintEven()
{
while (Numbers.Count > 0)
{
semaphoreSlim.Wait();
var a = Numbers.FirstOrDefault();
if (a % 2 == 0)
{
Console.WriteLine(a);
Numbers.RemoveFirst();
}
semaphoreSlim.Release();
}
}
private static void PrintZero()
{
while (Numbers.Count > 1)
{
semaphoreSlim.Wait();
var a = Numbers.FirstOrDefault();
if (a == 0)
{
Console.WriteLine(a);
Numbers.RemoveFirst();
}
semaphoreSlim.Release();
}
}
public static void PrintOddEven()
{
for (int i = 1; i <= 10; i++)
{
Numbers.AddLast(0);
Numbers.AddLast(i);
}
Zero = new Thread(PrintZero);
Odd = new Thread(PrintOdd);
Even = new Thread(PrintEven);
Zero.Name = "Zero";
Odd.Name = "Odd";
Even.Name = "Even";
Zero.Start();
Odd.Start();
Even.Start();
Odd.Join();
Even.Join();
}
}
}
This problem statement can be solved using with Abstract Factory and Strategy Design Pattern.
Find full code in github : gmershad
Sales-Tax
https://github.com/gmershad/Sales-Tax.git
Try to implement with k-d tree algorithm with Nearest neighbor search.
- GUL MD ERSHAD December 30, 2016I will use different design patterns for the design of this application.
Design Patterns involved:
1) Builder Design Pattern (For adding food item and ordering)
2) Interpreter Design Pattern (User can Search Different restaurant)
3) Iterator Pattern (User Sees Menu)
4) Observer Pattern(Track an order in Real Time)
5) Command Pattern(Order or Cancellation of Food)
Please refer to below Code Repository for more details:
https://github.com/gmershad/FoodDeliveryApp
Strategy Pattern.
- GUL MD ERSHAD August 18, 2016
It can be developed with the help of Command Design Pattern and some scheduler algorithm. Please find the implementation:
- GUL MD ERSHAD January 20, 2018github.com/gmershad/CabScheduling