Zazada is Singapore\'s latest online shopping website As a new entry to the comp
ID: 3910198 • Letter: Z
Question
Zazada is Singapore's latest online shopping website As a new entry to the competitive e-commerce scene, Zazada is very aggressive in its sales promotions In order to further promote itself and gain popularity with online shoppers, Zazada works with a number of banks to provide discounts when shoppers pay with credit cards from different banks. The credit card promotion would work as below: After a shopper has selected a number of items in his cart and check-out for payment, he could key in a promotional code If the promotion code entered is valid, the relevant discount scheme would be applied and the final payment amount after discount would be shown. In the month of July, Zazada is working with CitibankA bank for its sales promotion. There are 2 promotional codes marketed to attract more online shoppers, especially those with CitibankA credit cards. Zazada Promotional Code Discount Scheme Valid only for new customers. CITI10OFF Zazada offers 10% off total check-out value with Citibank card. Valid for existing customers. CITI5OFF Zazada offers 5% off total check-out value with Citibank card Table 1: Promotional Code Below shows a sample calculation for promotion code "CITI10OFF Purchased 4 quantities of Brand A Fragrant Rice Total check-out value 4 30.80 $123.20 Calculated savings 0.10 123.20 S$12.32 Final payment value123.20-12.32 -S$110.88Explanation / Answer
import java.util.Scanner;
class Main
{
void display() //display function
{
System.out.println("=======================================================");
System.out.println(" "+"Welcome to Zazada Online Shopping Mall");
System.out.println("=======================================================");
System.out.println("Item Description"+" "+"Price(S$)");
System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
System.out.println("1. Brand A Fragnant Rice"+" "+"30.80");
System.out.println("2. Brand B FBody Wash"+" "+"9.70");
System.out.println("3. Brand C Cooking Oil"+" "+"12.90");
System.out.println("4. Brand D Detergent"+" "+"10.95");
System.out.println("5. Brand E Seasoning sauce"+" "+"3.40");
System.out.println("Select item to add to cart (1 to 5)");
System.out.print("Enter 0 to checkout order : ");
}
int checkpromo(int a,String s) //to validate promo code
{
//for new user
if(a==0 && s.equalsIgnoreCase("CITI10OFF"))
return 1;
//for old user
else if(a==1 && s.equalsIgnoreCase("CITI5OFF"))
return 2;
else
//for invalid code
return 0;
}
double calc(int x,double y) //to calculate savings
{
double temp=0;
temp=(double)(y-(double)(x/100*y));
return temp; //returning the value
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
//variable decalration
int ch,qty,n,cp,pr,res;
n=0;
pr=0;
double tp=0,sav=0,total=0;
String c1;
String str;
String nc;
do{
Main obj=new Main();
do
{
//acepting value from user
obj.display();
ch=sc.nextInt();
if(ch>5)
{
System.out.println("Invalid Entry!");
continue;
}
if(ch==0)
{
System.out.println("Total cart value of "+n+" items : $"+tp);
break;
}
else
{
System.out.print("Enter quantity : ");
qty=sc.nextInt();
System.out.println();
//calculating total price and total quantity in cart
if(ch==1)
{
tp+=qty*30.80;
n=n+qty;
}
if(ch==2)
{
tp+=qty*9.70;
n=n+qty;
}
if(ch==3)
{
tp+=qty*12.90;
n=n+qty;
}
if(ch==4)
{
tp+=qty*10.95;
n=n+qty;
}
if(ch==5)
{
tp+=qty*3.40;
n=n+qty;
}
System.out.println("Total cart value of "+n+" items : $"+tp);
}
}while(ch!=0);
//checking for new or old customer
System.out.println("Enter 0 for new customer");
System.out.println("Enter 1 for old customer");
System.out.print("Enter status : ");
cp=sc.nextInt();
if(cp==0)
System.out.println("You are a new customer. Welcome to Zazada Online Shopping Mall");
if(cp==1)
System.out.println("You are an existing customer. Welcome back!");
System.out.print("Do you have an promotional code (Y/N) ? ");
c1=sc.next();
System.out.println();
if(c1.equals("y") || c1.equals("Y"))
{
//checking for promotional code
System.out.print("Enter promotional code : ");
str=sc.next();
res=obj.checkpromo(cp,str);
if(res==1)
{
pr=10;
System.out.println("Promotional Code "+str.toUpperCase()+" applied!");
}
if(res==2)
{
pr=5;
System.out.println("Promotional Code "+str.toUpperCase()+" applied!");
}
//displaying the result if promotional code applied
System.out.println();
sav=obj.calc(pr,tp);
total=tp-sav;
System.out.println("Total check-out value : $"+tp);
System.out.println("Total Savings : $"+sav);
System.out.println("Final payment amount : "+total);
System.out.println("Promotional code applied : "+str.toUpperCase());
}
else
{
//displaying the result if no promotional code applied
System.out.println();
System.out.println("Total check-out value : $"+tp);
System.out.println("Total Savings : $0.00");
System.out.println("Final payment amount : "+tp);
System.out.println("Promotional code applied : NONE");
}
//asking if the user want o continue anothere order
System.out.print("Do you want to create a new order (Y/N) ? ");
nc=sc.next();
}while(!nc.equals("N"));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.