patterncsharpMajor
Sales Tax Problem, rejected for not being up to their standards
Viewed 0 times
problembeingtaxforstandardsrejectedsalesnottheir
Problem
I applied for a Junior .NET Developer Position recently, and I was asked to solve a problem (Sales Tax Program) and I was rejected for some reason. The question goes like this:
Basic sales tax is applicable at a rate of 10% on all goods, except food, medicines and books. For all imported goods, a tax rate of additional 5% is applied irrespective of their type. Generate a receipt which shows names of all the items purchased and their prices (including taxes), finishing with total cost of the items, and total amount sales tax 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 nearest 0.05) amount of sales tax. Write an application to generate receipt with all these details.
They gave me the input to take and output should come:
Input 3:
Output 3:
They gave two more sets of input, but I just didn't put that to save some time.
Please review my code and let me know what's wrong with that and what are the concepts I need to focus on to solve a problem like this.
```
namespace Products
{
class Program
{
static void Main(string[] args)
{
try
{
// calling the Generatereciept class and invoking Generate method to display all the product details, price, taxes and total after taxes
GenerateReciept generate = new GenerateReciept();
generate.Generate();
}
catch (Exception ex)
{
// writing the exception to console.. we can log it to a database or eventviewer based on the requirements
Basic sales tax is applicable at a rate of 10% on all goods, except food, medicines and books. For all imported goods, a tax rate of additional 5% is applied irrespective of their type. Generate a receipt which shows names of all the items purchased and their prices (including taxes), finishing with total cost of the items, and total amount sales tax 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 nearest 0.05) amount of sales tax. Write an application to generate receipt with all these details.
They gave me the input to take and output should come:
Input 3:
- 1 imported bottle of perfume at 27.99
- 1 bottle of perfume at 18.99
- 1 packet of headache pills at 9.75
- 1 box of imported chocolates at 11.25
Output 3:
- 1 imported bottle of perfume: 32.19
- 1 bottle of perfume: 20.89
- 1 packet of headache pills: 9.75
- 1 imported box of chocolates: 11.85
- Sales Taxes: 6.70
- Total: 74.68
They gave two more sets of input, but I just didn't put that to save some time.
Please review my code and let me know what's wrong with that and what are the concepts I need to focus on to solve a problem like this.
```
namespace Products
{
class Program
{
static void Main(string[] args)
{
try
{
// calling the Generatereciept class and invoking Generate method to display all the product details, price, taxes and total after taxes
GenerateReciept generate = new GenerateReciept();
generate.Generate();
}
catch (Exception ex)
{
// writing the exception to console.. we can log it to a database or eventviewer based on the requirements
Solution
As an interviewer, I want to see candidates demonstrate the skills I'm hiring for. In particular, I want to see unit tests, because I want you to write tests for your code if you come work for me. If you had written unit tests for your code, you probably would have caught many of the items listed in the other answers. You at least would have demonstrated an organized approach to coding your solution.
It's hard to say what the interviewer may have been looking for, because we're not him. He might have wanted to see if you recognized when to apply the strategy pattern (because of the different types of items that have different taxation rules.) He might have been looking for you to organize the items around a transaction (not just a product list), passing the transaction first to a tax calculator, and then to a receipt generator, using Dependency Injection. Maybe he looked at the monolithic function of Generate() and said "too much complexity in a single method." Maybe he was looking for overall better evidence of the SOLID principles.
We obviously can't know exactly what he wanted. You demonstrated a grasp of the language, you just need to apply object-oriented design principles to your coding. I think that's something you can teach a junior developer. So maybe he was fishing for someone skilled but only wanted to pay a junior developer's wage.
It's hard to say what the interviewer may have been looking for, because we're not him. He might have wanted to see if you recognized when to apply the strategy pattern (because of the different types of items that have different taxation rules.) He might have been looking for you to organize the items around a transaction (not just a product list), passing the transaction first to a tax calculator, and then to a receipt generator, using Dependency Injection. Maybe he looked at the monolithic function of Generate() and said "too much complexity in a single method." Maybe he was looking for overall better evidence of the SOLID principles.
We obviously can't know exactly what he wanted. You demonstrated a grasp of the language, you just need to apply object-oriented design principles to your coding. I think that's something you can teach a junior developer. So maybe he was fishing for someone skilled but only wanted to pay a junior developer's wage.
Context
StackExchange Code Review Q#91332, answer score: 26
Revisions (0)
No revisions yet.