/* related posts with thumb nails */

A program to simulate on-line shopping.:

import java.io.*;

class Shopping

{

public static void main(String as[]) throws Exception

{

int i=0,x,op,sum=0,m;

String con="";

int a[]=new int[10];

int n[]=new int[10];

String s[]={"Self Confidence -book(Rs.200)","My Experiments with truth(Rs. 100)",

"Java Apoorva book(Rs. 150)","Java Complete Reference(Rs. 300)"};

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(isr);

do

{

System.out.println("Select Items from the list:\n");

System.out.println(" 1.Self Confidence -book\tRs.200");

System.out.println(" 2.My Experiments with truth\tRs.100");

System.out.println(" 3.Java Apoorva book\tRs.150");

System.out.println(" 4.Java Complete Reference\tRs.300");

System.out.println("\nSelect the Item number:");

x=Integer.parseInt(br.readLine());

if(x<1 || x>4) continue;

a[i]=x;

System.out.println("Enter quantity:");

n[i]=Integer.parseInt(br.readLine());

i++;

System.out.println("Add more Items?(y,n):");

con=br.readLine();

} while(con.equals("y"));

m=i; // number of items

System.out.println("\n 1. Check out \n 2. Cancel the order \n");

System.out.println("Enter option:");

op=Integer.parseInt(br.readLine());

if(op==1)

{

System.out.println("==========================================");

System.out.println("\nItem\tQuantity");

System.out.println("==========================================");

for(i=0;i

{

if(a[i]==1)

sum=sum+n[i]*200;

else if(a[i]==2)

sum=sum+n[i]*100;

else if(a[i]==3)

sum=sum+n[i]*150;

else if(a[i]==4)

sum=sum+n[i]*300;

System.out.println("\n"+s[a[i]]+"\t"+n[i]);

}

System.out.println("==========================================");

System.out.println("\nTotal Bill:"+sum);

System.out.println("==========================================");

}

}

}

/* Output: */

Select Items from the list:

1.Self Confidence -book Rs.200

2.My Experiments with truth Rs.100

3.Java Apoorva book Rs.150

4.Java Complete Reference Rs.300

Select the Item number:1

Enter quantity: 2

Add more Items?(y,n):y

Select Items from the list:

1.Self Confidence -book Rs.200

2.My Experiments with truth Rs.100

3.Java Apoorva book Rs.150

4.Java Complete Reference Rs.300

Select the Item number:3

Enter quantity:2

Add more Items?(y,n):n

1. Check out

2. Cancel the order

Enter option:1

=============================================

Item Quantity

=============================================

My Experiments with truth(Rs. 200) 2

Java Apoorva book(Rs. 150) 2

=============================================

Total Bill:700

=============================================

Related Topics:

0 comments:

Post a Comment