CDK Global Interview Question
Backend DevelopersCountry: India
Interview Type: Written Test
public class ShoppingCartDiscount {
public static void main(String args[]) {
System.out.println("Price for the premium customer: " + calculatePrice("Premium", 23000));
System.out.println("Price for the regular customer: " + calculatePrice("Regular", 2000));
}
static int calculatePrice(String customerType, int purchaseAmount) {
int result = purchaseAmount;
if (customerType.equalsIgnoreCase("premium")) {
if (purchaseAmount >= 5000 && purchaseAmount <= 10000) {
result = purchaseAmount - (int) (purchaseAmount * 0.1);
}
else if (purchaseAmount >= 10000) {
result = purchaseAmount - (int) (purchaseAmount * 0.2);
}
}
else if (customerType.equalsIgnoreCase("regular")) {
if (purchaseAmount >= 4000 && purchaseAmount <= 8000) {
result = purchaseAmount - (int) (purchaseAmount * 0.1);
}
if (purchaseAmount >= 8000 && purchaseAmount <= 12000) {
result = purchaseAmount - (int) (purchaseAmount * 0.2);
}
if (purchaseAmount >= 12000) {
result = purchaseAmount - (int) (purchaseAmount * 0.25);
}
}
return result;
}
}
public class ShoppingCartDiscount {
public static void main(String args[]) {
System.out.println("Price for the premium customer: " + calculatePrice("Premium", 23000));
System.out.println("Price for the regular customer: " + calculatePrice("Regular", 2000));
}
static int calculatePrice(String customerType, int purchaseAmount) {
int result = purchaseAmount;
if (customerType.equalsIgnoreCase("premium")) {
if (purchaseAmount >= 5000 && purchaseAmount <= 10000) {
result = purchaseAmount - (int) (purchaseAmount * 0.1);
}
else if (purchaseAmount >= 10000) {
result = purchaseAmount - (int) (purchaseAmount * 0.2);
}
}
else if (customerType.equalsIgnoreCase("regular")) {
if (purchaseAmount >= 4000 && purchaseAmount <= 8000) {
result = purchaseAmount - (int) (purchaseAmount * 0.1);
}
if (purchaseAmount >= 8000 && purchaseAmount <= 12000) {
result = purchaseAmount - (int) (purchaseAmount * 0.2);
}
if (purchaseAmount >= 12000) {
result = purchaseAmount - (int) (purchaseAmount * 0.25);
}
}
return result;
}
}
I was also given same assignment by cdk global Pune. However I couldn't clear this , though I attempted successfully. Did you clear this ?
- prashant January 06, 2020