How to make a Billing console application for vegetable shop



 Case study:A vegetable shop owner sells Potatoes and Tomatoes at the rate of Rs16 and Rs 20 respectively. Every new customer comes and ask him and he feels annoyed. That is why he want to give an option to the user where user can input the quantity of potatoes and tomatoes, which processes the information using Java console application and displays the net payable amount after discount. He gives 5% discount to every customer.

  • First of all open notepad++ and save the file as vegetableshop.java
  • Having done this paste the following code and save the file by pressing ctrl+s


import java.util.*;

import java.util.Scanner;

class vegetableshop

{

                public static void main(String args[])

                {

                                double tomatoquantity,potatoquantity;

                double discount,netpayableamount,potatocost,tomatocost,Totalcost;

                double potatorate=16.00;

                double tomatorate=20.00;

                Scanner sc=new Scanner(System.in);

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

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

    System.out.println("|    Welcome to Vegetable shop             |");

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

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

               

                System.out.println("How many kilograms of Potatoes do you want to purchase: ");        

    potatoquantity=sc.nextDouble();

                System.out.println("How many kilograms of Tomato do you want to purchase: ");           

                tomatoquantity=sc.nextDouble();

                potatocost=potatorate*potatoquantity;

                tomatocost=tomatorate*tomatoquantity;

                Totalcost=potatocost+tomatocost;

                discount=(Totalcost*5)/100;

                netpayableamount=Totalcost-discount;

                System.out.println("Cost of potatoes: "+potatocost);

                System.out.println("Cost of potatoes: "+tomatocost);

                System.out.println("Total cost: "+Totalcost);

    System.out.println("Discount: "+discount);    

                System.out.println("Amount to pay: "+netpayableamount);      

                }

}

  • Open command prompt and compile the code by using following code

javac vegetableshop.java

 

  • Execute the code using the command

java vegetableshop

  • The output screen would look like this


As a Java developer or Java programmer we need to know how to break the complex formulas for simplicity of coding. The correct data types plays important role. Not every one will be satisfied in purchasing 5,10 or 15 kgs. They might want decimal value as well. Hence declaring it as double we can make our console application more robust and accurate.

Benefits of using Java console application in Vegetable shop

·   ðŸ‘‰  No need to reply the same question every time.
👉 Saves time in making calculation for total cost and discount.
👉 Manage the business transaction quickly by demanding the net payable amount.

Some vegetable shop owners also want to develop e commerce website hence they choose Java web development services from Java web development company.

In case you want to hire offshores Java developers for Java web development, or customized Java software development then you can contact our sales representatives right now. We provide excellent design, fully responsive professional & dynamic websites for business. Not only this we have dedicated team of expert full stack developers who can build fully customized software for your enterprise as well.

 

 

Post a Comment

0 Comments