SHOPPING COUNTER

SHOPPING COUNTER

i need to do the system about the item from the small shop.

how can i calculate the item with price. if user choose more quantity from it. 1. ikan masin (price = 1.50) 2. garam (price = 1.00) 3. buttercup (price = 1.00) 4. mentega (price = 2.00) 5. honey (price = 3.00)

if customer pay more from the buying value, it will give the change. example : 3.00+2.00 = 5.00 customer pay 10.00 - 5.00 = 5.00

how can i do this coding with swtich case from the java.

thanks for helps.

View Answers

October 21, 2010 at 12:20 PM

Hi Friend,

Try the following code:

import java.util.*;

class Product{
public String item;
public int quantity;
public double price;
public double total;

public Product(){}
public Product(String item,int quantity, double price,double total) {
super();
this.item=item;
this.quantity= quantity;
this.price = price;
this.total=total;
}
public String getItem() {
return item;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
public double getTotal() {
return total;
}
}
public class BuyProducts {

public static void main(String[] args) throws Exception {
double sum=0.0;
List<Product> list = new ArrayList<Product>();
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("School Registration System Main Menu");
System.out.println();
System.out.println("1. Ikan masin");
System.out.println("2. Garam Masala");
System.out.println("3. Buttercup");
System.out.println("4. Mentega ");
System.out.println("5. Honey");
System.out.println("6. Customer Bill");
System.out.println("7. Exit");

boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();

switch(menu) {
case 1:
System.out.print("Quantity: ");
int q1 = scan.nextInt();
System.out.print("Price: ");
double p1 = scan.nextDouble();
double t1=p1*q1;
list.add(new Product("Ikan masin",q1,p1,t1));
break;
case 2:
System.out.print("Quantity: ");
int q2 = scan.nextInt();
System.out.print("Price: ");
double p2 = scan.nextDouble();
double t2=p2*q2;
list.add(new Product("Garam Masala",q2,p2,t2));
break;
case 3:
System.out.print("Quantity: ");
int q3 = scan.nextInt();
System.out.print("Price: ");
double p3 = scan.nextDouble();
double t3=p3*q3;
list.add(new Product("Buttercup",q3,p3,t3));
break;
case 4:
    System.out.print("Quantity: ");
int q4 = scan.nextInt();
System.out.print("Price: ");
double p4 = scan.nextDouble();
double t4=p4*q4;
list.add(new Product("Mentega",q4,p4,t4));break;
case 5:
System.out.print("Quantity: ");
int q5 = scan.nextInt();
System.out.print("Price: ");
double p5 = scan.nextDouble();
double t5=p5*q5;
list.add(new Product("Honey",q5,p5,t5));break;
case 6:
quit = true;
System.out.println("Items   Quantity   Price   Total");
for (Product s : list){
System.out.println(s.getItem()+"        " +s.getQuantity()+"        "+s.getPrice()+"        " +s.getTotal());
 sum+=s.getTotal();
}
System.out.print("Customer pays: ");
double pay=scan.nextDouble();
if(pay>sum){
    double amt=pay-sum;
    System.out.println("Give Change to Customer: "+amt);
}
else{
    System.out.println("You have to pay "+sum);
    System.out.print("Enter amount to pay:");
     pay=scan.nextDouble();
}
break;
case 7:
    quit=true;
break;
default:
System.out.println("Invalid Entry!");
 }
}
while(!quit);
}
}

Thanks


October 23, 2010 at 1:08 AM

thanks!!! you really helpful!!!









Related Tutorials/Questions & Answers:
SHOPPING COUNTER
SHOPPING COUNTER  i need to do the system about the item from the small shop. how can i calculate the item with price. if user choose more quantity from it. 1. ikan masin (price = 1.50) 2. garam (price = 1.00) 3. buttercup
Servlet Counter
{ int counter = 0; public void doGet(HttpServletRequest request...(); counter++; pw.println("At present the value of the counter is " + counter); } } In the above example, which keeps track how many times the servlet
Advertisements
Counter
shopping cart
shopping cart  hi i want the sample project for shopping cart in struts with mysql ,if any one knows means please help me
Shopping Cart
Shopping Cart  Give some same code for shopping cart.. once click "Add to cart button" add item into cart and also moved into next step
Shopping Cart,Shopping Cart software
counter.  Software Shopping cart is used around the world in e-commerce... Shopping Cart       Overview A web based shopping cart is something like the original
Free Java Shopping Cart,Shopping cart Application
at the checkout counter.     Shopping Cart Version 1.1... Free Java Shopping Cart       Shopping Cart allows the web site owner to setup online store so that visitors can
Shopping in Delhi
Shopping in Delhi  I heard about Connaught Place and Karol Bagh are best markets for shopping in Delhi. But is there any other market.. from where i can buy something traditional that can be related to Delhi as well as Indian
online shopping
online shopping   Hai sir/madam, i'm working on online shopping project.requirements is oracle10g,servlets/jsp... what is the difference b/w storing and saving image into database.how to store and how
online shopping
online shopping  hi, i am doing online shopping project i want to do online payment. How it can be possible
ModuleNotFoundError: No module named 'Counter'
ModuleNotFoundError: No module named 'Counter'  Hi, My Python... 'Counter' How to remove the ModuleNotFoundError: No module named 'Counter... to install padas library. You can install Counter python with following command
ModuleNotFoundError: No module named 'Counter'
ModuleNotFoundError: No module named 'Counter'  Hi, My Python... 'Counter' How to remove the ModuleNotFoundError: No module named 'Counter... to install padas library. You can install Counter python with following command
ModuleNotFoundError: No module named 'Counter'
ModuleNotFoundError: No module named 'Counter'  Hi, My Python... 'Counter' How to remove the ModuleNotFoundError: No module named 'Counter... to install padas library. You can install Counter python with following command
Shopping_Beauty
Shopping_Beauty  **Deleted by Admin** - BH Cosmetics, BHCosmetics is the best place on the web for 120 eyeshadow palette, 88 eyeshadow palette, eye shadow cosmetics and professional make up palettes
Shopping Cart
Shopping Cart Shopping cart is also know as trolley, carriage, buggy or wagon is a cart mostly used while shopping in shopping mall. These cart is provided at the time of shopping for collecting the goods while shopping. In case
Counter program for java
Counter program for java  The problem is to count from 000 to 444 with recursion. The maximum digit is 4 so that the program will count from 000,001,002,003,004,010, 011 and so on. How can I solve
complete coding for shopping card
complete coding for shopping card  complete coding for shopping card   Please visit the following link: Shopping Cart Application
Shopping cart
information at the checkout counter. Software Shopping cart is used around the world... Shopping cart Overview A web based shopping cart is something like the original grocery shop shopping cart that is used by the customer
online shopping project
online shopping project  Hi, i want online shopping project modules description and screens
online shopping project
online shopping project  Hi, i want online shopping project modules description and screens
jsp code for shopping cart
jsp code for shopping cart  please provide me the jsp code for online shopping cart
character counter - Java Beginners
of the entered(by user) name?  hy katy, import java.io.*; class counter { public counter() { System.out.print("Enter ur name:"); try... void main(String args[]) { new counter(); } } this code
Shopping Cart
Shopping Cart In this section we will discuss about shopping cart and how you can use different open source shopping cart for hosting your shopping... online shopping portal and sale products online. Online portal is one
counter - JSP-Interview Questions
********///////// A page with a counter This page has been visited: times. This counter never increases its value
ModuleNotFoundError: No module named 'counter-caller'
ModuleNotFoundError: No module named 'counter-caller'  Hi, My... named 'counter-caller' How to remove the ModuleNotFoundError: No module named 'counter-caller' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'counter-robots'
ModuleNotFoundError: No module named 'counter-robots'  Hi, My... named 'counter-robots' How to remove the ModuleNotFoundError: No module named 'counter-robots' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'error-counter'
ModuleNotFoundError: No module named 'error-counter'  Hi, My... 'error-counter' How to remove the ModuleNotFoundError: No module named 'error-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'incremental-counter'
ModuleNotFoundError: No module named 'incremental-counter'  Hi, My... named 'incremental-counter' How to remove the ModuleNotFoundError: No module named 'incremental-counter' error? Thanks   Hi
ModuleNotFoundError: No module named 'line-counter'
ModuleNotFoundError: No module named 'line-counter'  Hi, My Python... 'line-counter' How to remove the ModuleNotFoundError: No module named 'line-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'moca-counter'
ModuleNotFoundError: No module named 'moca-counter'  Hi, My Python... 'moca-counter' How to remove the ModuleNotFoundError: No module named 'moca-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'moca-counter'
ModuleNotFoundError: No module named 'moca-counter'  Hi, My Python... 'moca-counter' How to remove the ModuleNotFoundError: No module named 'moca-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'moca-counter'
ModuleNotFoundError: No module named 'moca-counter'  Hi, My Python... 'moca-counter' How to remove the ModuleNotFoundError: No module named 'moca-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'morris-counter'
ModuleNotFoundError: No module named 'morris-counter'  Hi, My... named 'morris-counter' How to remove the ModuleNotFoundError: No module named 'morris-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'page-counter'
ModuleNotFoundError: No module named 'page-counter'  Hi, My Python... 'page-counter' How to remove the ModuleNotFoundError: No module named 'page-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pdf-counter'
ModuleNotFoundError: No module named 'pdf-counter'  Hi, My Python... 'pdf-counter' How to remove the ModuleNotFoundError: No module named 'pdf-counter' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'pdf-counter'
ModuleNotFoundError: No module named 'pdf-counter'  Hi, My Python... 'pdf-counter' How to remove the ModuleNotFoundError: No module named 'pdf-counter' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'reference_counter'
ModuleNotFoundError: No module named 'reference_counter'  Hi, My... named 'reference_counter' How to remove the ModuleNotFoundError: No module named 'reference_counter' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'rip-counter'
ModuleNotFoundError: No module named 'rip-counter'  Hi, My Python... 'rip-counter' How to remove the ModuleNotFoundError: No module named 'rip-counter' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'tag_counter'
ModuleNotFoundError: No module named 'tag_counter'  Hi, My Python... 'tag_counter' How to remove the ModuleNotFoundError: No module named 'tag_counter' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'tipfy.ext.sharded_counter'
ModuleNotFoundError: No module named 'tipfy.ext.sharded_counter'  Hi...: No module named 'tipfy.ext.sharded_counter' How to remove the ModuleNotFoundError: No module named 'tipfy.ext.sharded_counter' error? Thanks  
ModuleNotFoundError: No module named 'verb_counter'
ModuleNotFoundError: No module named 'verb_counter'  Hi, My Python... 'verb_counter' How to remove the ModuleNotFoundError: No module named 'verb_counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'word-counter'
ModuleNotFoundError: No module named 'word-counter'  Hi, My Python... 'word-counter' How to remove the ModuleNotFoundError: No module named 'word-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'words_counter'
ModuleNotFoundError: No module named 'words_counter'  Hi, My... 'words_counter' How to remove the ModuleNotFoundError: No module named 'words_counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'words_counter'
ModuleNotFoundError: No module named 'words_counter'  Hi, My... 'words_counter' How to remove the ModuleNotFoundError: No module named 'words_counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'words_counter'
ModuleNotFoundError: No module named 'words_counter'  Hi, My... 'words_counter' How to remove the ModuleNotFoundError: No module named 'words_counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'words_counter'
ModuleNotFoundError: No module named 'words_counter'  Hi, My... 'words_counter' How to remove the ModuleNotFoundError: No module named 'words_counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'words_counter'
ModuleNotFoundError: No module named 'words_counter'  Hi, My... 'words_counter' How to remove the ModuleNotFoundError: No module named 'words_counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'calorie-counter'
ModuleNotFoundError: No module named 'calorie-counter'  Hi, My... named 'calorie-counter' How to remove the ModuleNotFoundError: No module named 'calorie-counter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'counter-caller'
ModuleNotFoundError: No module named 'counter-caller'  Hi, My... named 'counter-caller' How to remove the ModuleNotFoundError: No module named 'counter-caller' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'counter-robots'
ModuleNotFoundError: No module named 'counter-robots'  Hi, My... named 'counter-robots' How to remove the ModuleNotFoundError: No module named 'counter-robots' error? Thanks   Hi, In your python

Ads